<?php
/**
 * Copyright © 2016 Magento. 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\Model\Product\Option::OPTION_TYPE_AREA) {
    echo ' textarea';
} ?><?php /* @escapeNotVerified */ echo $class ?>">
    <label class="label" for="options_<?php /* @escapeNotVerified */ echo $_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 $_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 $_option->getId() ?>]"
                   data-selector="options[<?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 $_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 $_option->getId() ?>]"
                      data-selector="options[<?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>
