<?php
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */

// @codingStandardsIgnoreFile

?>
<?php
$_option = $block->getOption();
$class = ($_option->getIsRequire()) ? ' required' : '';
?>

<div class="field<?php if ($_option->getType() == \Magento\Catalog\Api\Data\ProductCustomOptionInterface::OPTION_TYPE_AREA) {
    echo ' textarea';
} ?><?= /* @escapeNotVerified */ $class ?>">
    <label class="label" for="options_<?= /* @escapeNotVerified */ $_option->getId() ?>_text">
        <span><?= $block->escapeHtml($_option->getTitle()) ?></span>
        <?= /* @escapeNotVerified */ $block->getFormatedPrice() ?>
    </label>

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