<?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\File $block */
$_option           = $block->getOption();
$_fileInfo         = $block->getFileInfo();
$_fileExists       = $_fileInfo->hasData();
$_fileName         = 'options_' . $_option->getId() . '_file';
$_fieldNameAction  = $_fileName . '_action';
$_fieldValueAction = $_fileExists ? 'save_old' : 'save_new';
$_fileNamed        = $_fileName . '_name';
$class             = $_option->getIsRequire() ? ' required' : '';
$productId         = $block->getProduct()->getId();
?>
<div class="field file<?php /* @escapeNotVerified */ echo $class; ?>">
    <label class="label" for="<?php /* @noEscape */ echo $_fileName; ?>" id="<?php /* @noEscape */ echo $_fileName; ?>-label">
        <span><?php echo  $block->escapeHtml($_option->getTitle()) ?></span>
        <?php /* @escapeNotVerified */ echo $block->getFormatedPrice() ?>
    </label>
    <?php if ($_fileExists): ?>
    <div class="control">
        <span class="<?php /* @noEscape */ echo $_fileNamed ?>"><?php echo $block->escapeHtml($_fileInfo->getTitle()); ?></span>
        <a href="javascript:void(0)" class="label" id="change-<?php /* @noEscape */ echo $_fileName ?>" >
            <?php /* @escapeNotVerified */ echo __('Change') ?>
        </a>
        <?php if (!$_option->getIsRequire()): ?>
            <label for="delete-<?php /* @escapeNotVerified */ echo $_fileName ?>"></label><input type="checkbox" id="delete-<?php /* @escapeNotVerified */ echo $_fileName ?>" />
            <span class="label"><?php /* @escapeNotVerified */ echo __('Delete') ?></span>
        <?php endif; ?>
    </div>
    <?php endif; ?>
    <div class="control" id="input-box-<?php /* @escapeNotVerified */ echo $_fileName ?>"
             data-mage-init='{"priceOptionFile":{
                "fileName":"<?php /* @noEscape */ echo $_fileName ?>",
                "fileNamed":"<?php /* @noEscape */ echo $_fileNamed ?>",
                "fieldNameAction":"<?php /* @escapeNotVerified */ echo $_fieldNameAction ?>",
                "changeFileSelector":"#change-<?php /* @escapeNotVerified */ echo $_fileName ?>",
                "deleteFileSelector":"#delete-<?php /* @escapeNotVerified */ echo $_fileName ?>"}
             }'
            <?php echo $_fileExists ? 'style="display:none"' : '' ?>>
        <input type="file"
               name="mageplaza-fbt-custom-option-<?php /* @escapeNotVerified */ echo $productId;?><?php /* @escapeNotVerified */ echo $_fileName; ?>"
               id="<?php /* @escapeNotVerified */ echo $_fileName; ?>"
               class="product-custom-option<?php echo $_option->getIsRequire() ? ' required' : '' ?>"
                <?php echo $_fileExists ? 'disabled="disabled"' : '' ?> />
        <input type="hidden" name="mageplaza-fbt-custom-option-<?php /* @escapeNotVerified */ echo $productId;?><?php /* @escapeNotVerified */ echo $_fieldNameAction; ?>" value="<?php /* @escapeNotVerified */ echo $_fieldValueAction; ?>" />
        <?php if ($_option->getFileExtension()): ?>
            <p class="note">
                <?php /* @escapeNotVerified */ echo __('Compatible file extensions to upload')?>: <strong><?php /* @escapeNotVerified */ echo $_option->getFileExtension() ?></strong>
            </p>
        <?php endif; ?>
        <?php if ($_option->getImageSizeX() > 0): ?>
            <p class="note">
                <?php /* @escapeNotVerified */ echo __('Maximum image width')?>: <strong><?php /* @escapeNotVerified */ echo $_option->getImageSizeX() ?> <?php /* @escapeNotVerified */ echo __('px.')?></strong>
            </p>
        <?php endif; ?>
        <?php if ($_option->getImageSizeY() > 0): ?>
            <p class="note">
                <?php /* @escapeNotVerified */ echo __('Maximum image height')?>: <strong><?php /* @escapeNotVerified */ echo $_option->getImageSizeY() ?> <?php /* @escapeNotVerified */ echo __('px.')?></strong>
            </p>
        <?php endif; ?>
    </div>
</div>
