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

// @codingStandardsIgnoreFile
use Magento\Catalog\Model\Product\Option;

/**
 * @var \Magento\Catalog\Block\Product\View\Options\View\Checkable $block
 */
$option = $block->getOption();
if ($option) : ?>
    <?php
    $configValue = $block->getPreconfiguredValue($option);
    $optionType = $option->getType();
    $arraySign = $optionType === Option::OPTION_TYPE_CHECKBOX ? '[]' : '';
    $count = 1;
    ?>

<div class="options-list nested" id="options-<?php echo /* @noEscape */
$option->getId() ?>-list">
    <?php if ($optionType === Option::OPTION_TYPE_RADIO && !$option->getIsRequire()): ?>
    <div class="field choice admin__field admin__field-option">
        <input type="radio"
               id="options_<?php echo /* @noEscape */
               $option->getId() ?>"
               class="radio admin__control-radio product-custom-option"
               name="options[<?php echo /* @noEscape */
               $option->getId() ?>]"
               data-selector="options[<?php echo /* @noEscape */
               $option->getId() ?>]"
               onclick="<?php echo $block->getSkipJsReloadPrice() ? '' : 'opConfig.reloadPrice()' ?>"
               value=""
               checked="checked"
        />
        <label class="label admin__field-label" for="options_<?php echo /* @noEscape */
        $option->getId() ?>">
                        <span>
                            <?php echo /* @noEscape */
                            __('None') ?>
                        </span>
        </label>
    </div>
<?php endif; ?>

    <?php foreach ($option->getValues() as $value) : ?>
        <?php
        $checked = '';
        $count++;
        if ($arraySign) {
            $checked = is_array($configValue) && in_array($value->getOptionTypeId(), $configValue) ? 'checked' : '';
        } else {
            $checked = $configValue == $value->getOptionTypeId() ? 'checked' : '';
        }
        $dataSelector = 'options[' . $option->getId() . ']';
        if ($arraySign) {
            $dataSelector .= '[' . $value->getOptionTypeId() . ']';
        }
        ?>

        <div class="field choice admin__field admin__field-option <?php echo /* @noEscape */
        $option->getIsRequire() ? 'required': '' ?>">
            <input type="<?php echo /* @noEscape */
            $optionType ?>"
                   class="<?php /** @noinspection DisconnectedForeachInstructionInspection */
                   echo /* @noEscape */
                   $optionType === Option::OPTION_TYPE_RADIO ?
                       'radio admin__control-radio' :
                       'checkbox admin__control-checkbox' ?> <?php echo /* @noEscape */
                   $option->getIsRequire() ? 'required': '' ?>
                       product-custom-option
                        <?php echo $block->getSkipJsReloadPrice() ? '' : 'opConfig.reloadPrice()' ?>"
                   name="options[<?php echo $option->getId() ?>]<?php echo /* @noEscape */
                   $arraySign ?>"
                   id="options_<?php echo /* @noEscape */
                       $option->getId() . '_' . $count ?>"
                   value="<?php echo /* @noEscape */
                   $value->getOptionTypeId() ?>"
                <?php echo /* @noEscape */
                $checked ?>
                   data-selector="<?php echo /* @noEscape */
                   $dataSelector ?>"
                   price="<?php echo /* @noEscape */
                   $block->getCurrencyByStore($value) ?>"
            />
            <label class="label admin__field-label"
                   for="options_<?php echo /* @noEscape */
                       $option->getId() . '_' . $count ?>">
                <span>
                    <?php echo $block->escapeHtml($value->getTitle()) ?>
                </span>
                <?php echo /* @noEscape */
                $block->formatPrice($value) ?>
            </label>
        </div>
    <?php endforeach; ?>
    </div>
<?php endif; ?>