<?php
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */
?>
<?php /* @var $block \Magento\Catalog\Block\Product\View\Options\Type\File */ ?>
<?php $_option = $block->getOption(); ?>
<?php $_fileInfo = $block->getFileInfo(); ?>
<?php $_fileExists = $_fileInfo->hasData(); ?>
<?php $_fileName = 'options_' . $block->escapeHtmlAttr($_option->getId()) . '_file'; ?>
<?php $_fieldNameAction = $_fileName . '_action'; ?>
<?php $_fieldValueAction = $_fileExists ? 'save_old' : 'save_new'; ?>
<?php $_fileNamed = $_fileName . '_name'; ?>
<?php $class = ($_option->getIsRequire()) ? ' required' : ''; ?>

<div class="field file<?= /* @noEscape */ $class ?>">
    <label class="label" for="<?= /* @noEscape */ $_fileName ?>" id="<?= /* @noEscape */ $_fileName ?>-label">
        <span><?= $block->escapeHtml($_option->getTitle()) ?></span>
        <?= /* @noEscape */ $block->getFormattedPrice() ?>
    </label>
    <?php if ($_fileExists) :?>
    <div class="control">
        <span class="<?= /* @noEscape */ $_fileNamed ?>"><?= $block->escapeHtml($_fileInfo->getTitle()) ?></span>
        <a href="javascript:void(0)" class="label" id="change-<?= /* @noEscape */ $_fileName ?>" >
            <?= $block->escapeHtml(__('Change')) ?>
        </a>
        <?php if (!$_option->getIsRequire()) :?>
            <input type="checkbox" id="delete-<?= /* @noEscape */ $_fileName ?>" />
            <span class="label"><?= $block->escapeHtml(__('Delete')) ?></span>
        <?php endif; ?>
    </div>
    <?php endif; ?>
    <div class="control" id="input-box-<?= /* @noEscape */ $_fileName ?>"
             data-mage-init='{"priceOptionFile":{
                "fileName":"<?= /* @noEscape */ $_fileName ?>",
                "fileNamed":"<?= /* @noEscape */ $_fileNamed ?>",
                "fieldNameAction":"<?= /* @noEscape */ $_fieldNameAction ?>",
                "changeFileSelector":"#change-<?= /* @noEscape */ $_fileName ?>",
                "deleteFileSelector":"#delete-<?= /* @noEscape */ $_fileName ?>"}
             }'
            <?= $_fileExists ? 'style="display:none"' : '' ?>>
        <input type="file"
               name="<?= /* @noEscape */ $_fileName ?>"
               id="<?= /* @noEscape */ $_fileName ?>"
               class="product-custom-option<?= $_option->getIsRequire() ? ' required' : '' ?>"
            <?= $_fileExists ? 'disabled="disabled"' : '' ?> />
        <input type="hidden" name="<?= /* @noEscape */ $_fieldNameAction ?>" value="<?= /* @noEscape */ $_fieldValueAction ?>" />
        <?php if ($_option->getFileExtension()) :?>
            <p class="note">
                <?= $block->escapeHtml(__('Compatible file extensions to upload')) ?>: <strong><?= $block->escapeHtml($_option->getFileExtension()) ?></strong>
            </p>
        <?php endif; ?>
        <?php if ($_option->getImageSizeX() > 0) :?>
            <p class="note">
                <?= $block->escapeHtml(__('Maximum image width')) ?>: <strong><?= (int)$_option->getImageSizeX() ?> <?= $block->escapeHtml(__('px.')) ?></strong>
            </p>
        <?php endif; ?>
        <?php if ($_option->getImageSizeY() > 0) :?>
            <p class="note">
                <?= $block->escapeHtml(__('Maximum image height')) ?>: <strong><?= (int)$_option->getImageSizeY() ?> <?= $block->escapeHtml(__('px.')) ?></strong>
            </p>
        <?php endif; ?>
    </div>
</div>
