<?php
/**
 * Mageplaza
 *
 * NOTICE OF LICENSE
 *
 * This source file is subject to the Mageplaza.com license that is
 * available through the world-wide-web at this URL:
 * https://www.mageplaza.com/LICENSE.txt
 *
 * DISCLAIMER
 *
 * Do not edit or add to this file if you wish to upgrade this extension to newer
 * version in the future.
 *
 * @category    Mageplaza
 * @package     Mageplaza_Faqs
 * @copyright   Copyright (c) Mageplaza (https://www.mageplaza.com/)
 * @license     https://www.mageplaza.com/LICENSE.txt
 */

use Mageplaza\Faqs\Block\Article\Form;
use Mageplaza\Faqs\Model\Config\Source\System\AddTerm;

/** @var Form $block */
?>
<?php if ($block->helperData->isShowForm()) : ?>
    <div class="mpfaqs-form mpfaqs">
        <div class="section card-panel hoverable row">
            <div class="mpfaqs-form-title left-align">
                <span><i
                            class="far fa-question-circle"></i>&nbsp&nbsp <?= $block->escapeHtml(__("Ask a question")) ?></span>
            </div>
            <form id="mpfaqs-question-form" class="col s12" data-mage-init='{"validation":{}}' novalidate="novalidate">
                <div class="mpfaqs-form-fieldset row">
                    <?php if ($block->isShowNameField()) : ?>
                        <div class="input-field col s6">
                            <input id="mpfaqs-form-fieldset__name-input"
                                   type="text"
                                   name="mpfaqs-form-fieldset__name-input"
                                   value="<?= $block->getLoggedCustomerName() ? $block->escapeHtmlAttr($block->getLoggedCustomerName()) : '' ?>"
                                <?php if ($block->isRequiredNameField()) : ?>
                                    data-validate="{required:true}"
                                <?php endif; ?>
                            >
                            <label for="mpfaqs-form-fieldset__name-input"><?= $block->escapeHtml(__("Name")) ?>
                                <?php if ($block->isRequiredNameField()) : ?>
                                    <span class="red-text">*</span>
                                <?php endif; ?>
                            </label>
                        </div>
                    <?php endif; ?>
                    <?php if ($block->isShowEmailField()) : ?>
                        <div class="input-field col s6">
                            <input id="mpfaqs-form-fieldset__email-input"
                                   type="text"
                                   name="mpfaqs-form-fieldset__email-input"
                                   value="<?= $block->getLoggedCustomerEmail() ? $block->escapeHtmlAttr($block->getLoggedCustomerEmail()) : '' ?>"
                                <?php if ($block->isRequiredEmailField()) : ?>
                                    data-validate="{required:true, 'validate-email':true}"
                                <?php else : ?>
                                    data-validate="{'validate-email':true}"
                                <?php endif; ?>
                            >
                            <label for="mpfaqs-form-fieldset__email-input"><?= $block->escapeHtml(__("Email")) ?>
                                <?php if ($block->isRequiredEmailField()) : ?>
                                    <span class="red-text">*</span>
                                <?php endif; ?>
                            </label>
                        </div>
                    <?php endif; ?>
                </div>
                <div class="mpfaqs-form-fieldset row">
                    <div class="input-field col s12">
                        <textarea id="mpfaqs-form-fieldset__question-content"
                                  maxlength="<?= $block->escapeHtmlAttr($block->getQuestionMaxChar()) ?>"
                                  class="materialize-textarea"
                                  data-validate="{required:true}"
                        ></textarea>
                        <label
                                for="mpfaqs-form-fieldset__question-content"><?= $block->escapeHtml(__("What is your question?")) ?>
                            <span class="red-text">*</span>
                        </label>
                    </div>
                </div>
                <?php if ($block->isShowEmailNotify()) : ?>
                    <div class="mpfaqs-form-fieldset row">
                        <div class="input-field col s12">
                            <label id="mpfaqs-form-fieldset__email-notify">
                                <input type="checkbox" value="0"/>
                                <span><?= $block->escapeHtml(__("Receive email notification if the question is answered.")) ?></span>
                            </label>
                        </div>
                    </div>
                <?php endif; ?>
                <?php if ($block->helperData->getTermConfig('enabled')) : ?>
                    <div class="mpfaqs-form-fieldset row">
                        <div class="input-field control col s12">
                            <?php if ((int) $block->helperData->getTermConfig('enabled') == AddTerm::CHECKBOX) : ?>
                                <label id="mpfaqs-form-fieldset__term-conditions">
                                    <input type="checkbox" value="0"/>
                                    <span><?= $block->escapeHtml(__("I agree with the")) ?>
                                        <a id="mpfaqs-term"
                                           href="#term-popup"><?= $block->helperData->getTermConfig('popup_label') ? $block->escapeHtml($block->helperData->getTermConfig('popup_label')) : $block->escapeHtml(__('Terms & Conditions')) ?>
                                        </a>
                                    </span>
                                </label>
                            <?php else : ?>
                                <label id="mpfaqs-form-fieldset__term-conditions">
                                    <input type="checkbox" value="1" checked="checked" disabled="disabled"/>
                                    <span><?= $block->escapeHtml(__("I agree with the")) ?>
                                        <a id="mpfaqs-term"
                                           href="#term-popup"><?= $block->helperData->getTermConfig('popup_label') ? $block->escapeHtml($block->helperData->getTermConfig('popup_label')) : $block->escapeHtml(__('Terms & Conditions')) ?>
                                        </a>
                                    </span>
                                </label>
                            <?php endif; ?>
                        </div>
                    </div>
                <?php endif; ?>
                <div id="mpfaqs-form-actions" class="mpfaqs-form-fieldset row">
                    <div class="input-field col s12">
                        <a class="waves-effect waves-light btn mpfaqs-form-fieldset__submit-form"><?= $block->escapeHtml(__("Submit the question")) ?></a>
                    </div>
                </div>
            </form>
            <div id="term-popup" class="white-popup mfp-hide mpfaqs">
                <div class="term-popup__term-title">
                    <h2><?= $block->helperData->getTermConfig('title') ? $block->escapeHtml($block->helperData->getTermConfig('title')) : $block->escapeHtml(__('Terms & Conditions')) ?></h2>
                </div>
                <div class="term-popup__term-content">
                    <span><?= $block->helperData->getTermConfig('content') ? $block->escapeHtml($block->helperData->getTermConfig('content')) : $block->escapeHtml(__('There is no content for Term & Conditions.')) ?></span>
                </div>
                <a class="waves-effect waves-light btn"><?= $block->escapeHtml(__("I Agree with the Terms")) ?></a>
            </div>
        </div>
    </div>
    <script type="text/javascript">
        require(['jquery', 'form_submit'], function ($, form_submit) {
            var config = {
                formMessengerBox: {
                    submitSuccess: '<?= $block->getMessagesHtml('addsuccess',
                        __('Your question has been sent successfully. Please wait admin approve!'))?>'
                },
                productId: '<?= /** noEscape */ $block->getCurrentProductId() ?>',
                ajaxUrl: '<?= /** noEscape */ $block->getSubmitAjaxUrl() ?>',
                isGoogleCapcha: '<?= /** noEscape */ $block->helperData->checkModuleEnabled('Mageplaza_GoogleRecaptcha') ?>',
                imgLoader: '<?= $block->escapeUrl($block->getLoadingImage()) ?>'
            };
            form_submit(config);
        });
    </script>
<?php endif; ?>
