<?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_FrequentlyBought
 * @copyright   Copyright (c) Mageplaza (https://www.mageplaza.com/)
 * @license     https://www.mageplaza.com/LICENSE.txt
 */

/** @var Magento\Catalog\Block\Product\View\Options\Type\Text $block */
$_option   = $block->getOption();
$class     = $_option->getIsRequire() ? ' required' : '';
$productId = $block->getProduct()->getId();
?>
<div class="field<?php if ($_option->getType() == \Magento\Catalog\Model\Product\Option::OPTION_TYPE_AREA) {
    echo ' textarea';
                 } ?><?php /* @escapeNotVerified */ echo $class ?>">
    <label class="label" for="options_<?php /* @escapeNotVerified */ echo $productId . '_' . $_option->getId() ?>_text">
        <span><?php echo $block->escapeHtml($_option->getTitle()) ?></span>
        <?php /* @escapeNotVerified */ echo $block->getFormatedPrice() ?>
    </label>

    <div class="control">
        <?php if ($_option->getType() == \Magento\Catalog\Model\Product\Option::OPTION_TYPE_FIELD): ?>
            <?php $_textValidate = null;
            if ($_option->getIsRequire()) {
                $_textValidate['required'] = true;
            }
            if ($_option->getMaxCharacters()) {
                $_textValidate['maxlength'] = $_option->getMaxCharacters();
            }
            ?>
            <input type="text"
                   id="options_<?php /* @escapeNotVerified */ echo $productId . '_' . $_option->getId() ?>_text"
                   class="input-text product-custom-option"
                   <?php if (!empty($_textValidate)) {?>
                   data-validate="<?php echo  $block->escapeHtml(json_encode($_textValidate));?>"
                    <?php } ?>
                   name="options_<?php /* @escapeNotVerified */ echo $productId ?>[<?php /* @escapeNotVerified */ echo $_option->getId() ?>]"
                   data-selector="options[<?php /* @escapeNotVerified */ echo $productId ?>][<?php /* @escapeNotVerified */ echo $_option->getId() ?>]"
                   value="<?php echo $block->escapeHtml($block->getDefaultValue()) ?>"/>
        <?php elseif ($_option->getType() == \Magento\Catalog\Model\Product\Option::OPTION_TYPE_AREA): ?>
            <?php $_textAreaValidate = null;
            if ($_option->getIsRequire()) {
                $_textAreaValidate['required'] = true;
            }
            if ($_option->getMaxCharacters()) {
                $_textAreaValidate['maxlength'] = $_option->getMaxCharacters();
            }
            ?>
            <textarea id="options_<?php /* @escapeNotVerified */ echo $productId . '_' . $_option->getId() ?>_text"
                      class="product-custom-option"
                    <?php if (!empty($_textAreaValidate)) {?>
                        data-validate="<?php echo $block->escapeHtml(json_encode($_textAreaValidate));?>"
                    <?php } ?>
                      name="options_<?php /* @escapeNotVerified */ echo $productId ?>[<?php /* @escapeNotVerified */ echo $_option->getId() ?>]"
                      data-selector="options[<?php /* @escapeNotVerified */ echo $productId ?>][<?php /* @escapeNotVerified */ echo $_option->getId() ?>]"
                      rows="5"
                      cols="25"><?php echo $block->escapeHtml($block->getDefaultValue()) ?></textarea>
        <?php endif; ?>
        <?php if ($_option->getMaxCharacters()): ?>
            <p class="note"><?php /* @escapeNotVerified */ echo __('Maximum number of characters:') ?>
                <strong><?php /* @escapeNotVerified */ echo $_option->getMaxCharacters() ?></strong></p>
        <?php endif; ?>
    </div>
</div>
