<?php
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */
// phpcs:disable Magento2.Templates.ThisInTemplate.FoundThis
?>
<?php /* @var $block \Magento\Bundle\Block\Adminhtml\Catalog\Product\Composite\Fieldset\Options\Type\Select */ ?>
<?php $_option      = $block->getOption(); ?>
<?php $_selections  = $_option->getSelections(); ?>
<?php $_default     = $_option->getDefaultSelection(); ?>
<?php $_skipSaleableCheck = $this->helper(Magento\Catalog\Helper\Product::class)->getSkipSaleableCheck(); ?>
<?php list($_defaultQty, $_canChangeQty) = $block->getDefaultValues(); ?>

<div class="field admin__field option<?php if ($_option->getDecoratedIsLast()) :?> last<?php endif; ?><?php if ($_option->getRequired()) { echo ' _required'; } ?>">
    <label class="label admin__field-label"><span><?= $block->escapeHtml($_option->getTitle()) ?></span></label>
    <div class="control admin__field-control">
        <?php if ($block->showSingle()) : ?>
            <?= /* @noEscape */ $block->getSelectionTitlePrice($_selections[0]) ?>
            <input type="hidden"
                   name="bundle_option[<?= $block->escapeHtmlAttr($_option->getId()) ?>]"
                   value="<?= $block->escapeHtmlAttr($_selections[0]->getSelectionId()) ?>"
                   price="<?= $block->escapeHtmlAttr($block->getSelectionPrice($_selections[0])) ?>" />
        <?php else :?>
            <select id="bundle-option-<?= $block->escapeHtmlAttr($_option->getId()) ?>"
                    name="bundle_option[<?= $block->escapeHtmlAttr($_option->getId()) ?>]"
                    class="bundle-option-<?= $block->escapeHtmlAttr($_option->getId()) ?><?php if ($_option->getRequired()) { echo ' required-entry'; } ?> select admin__control-select change-container-classname"
                    onchange="ProductConfigure.bundleControl.changeSelection(this)">
                <option value=""><?= $block->escapeHtml(__('Choose a selection...')) ?></option>
                <?php foreach ($_selections as $_selection) : ?>
                    <option
                        value="<?= $block->escapeHtmlAttr($_selection->getSelectionId()) ?>"
                        <?php if ($block->isSelected($_selection)) { echo ' selected="selected"'; } ?>
                        <?php if (!$_selection->isSaleable() && !$_skipSaleableCheck) { echo ' disabled="disabled"'; } ?>
                        price="<?= $block->escapeHtmlAttr($block->getSelectionPrice($_selection)) ?>"
                        qtyId="bundle-option-<?= $block->escapeHtmlAttr($_option->getId()) ?>-qty-input">
                        <?= /* @noEscape */ $block->getSelectionTitlePrice($_selection, false) ?>
                    </option>
                <?php endforeach; ?>
            </select>
        <?php endif; ?>

        <div class="nested">
            <div class="field admin__field qty">
                <label class="label admin__field-label"
                       for="bundle-option-<?= $block->escapeHtmlAttr($_option->getId()) ?>-qty-input">
                    <span><?= $block->escapeHtml(__('Quantity:')) ?></span>
                </label>
                <div class="control admin__field-control">
                    <input <?php if (!$_canChangeQty) { echo ' disabled="disabled"'; } ?>
                        id="bundle-option-<?= $block->escapeHtmlAttr($_option->getId()) ?>-qty-input"
                        class="input-text admin__control-text qty validate-greater-than-zero<?php if (!$_canChangeQty) { echo ' qty-disabled'; } ?>"
                        type="text"
                        name="bundle_option_qty[<?= $block->escapeHtmlAttr($_option->getId()) ?>]"
                        value="<?= $block->escapeHtmlAttr($_defaultQty) ?>" />
                </div>
            </div>
        </div>
    </div>
</div>
