<?php
/**
 * Copyright 2014 Adobe
 * All Rights Reserved.
 */
// phpcs:disable Magento2.Templates.ThisInTemplate.FoundThis
?>
<?php /* @var $block \Magento\Bundle\Block\Adminhtml\Catalog\Product\Composite\Fieldset\Options\Type\Multi */ ?>
<?php $_option = $block->getOption(); ?>
<?php $_selections = $_option->getSelections(); ?>
<?php $_skipSaleableCheck = $this->helper(Magento\Catalog\Helper\Product::class)->getSkipSaleableCheck(); ?>
<div class="field admin__field <?php if ($_option->getRequired()) { echo ' _required'; } ?><?php if ($_option->getDecoratedIsLast()) :?> last<?php endif; ?>">
    <label class="label admin__field-label"><span><?= $block->escapeHtml($_option->getTitle()) ?></span></label>
    <div class="control admin__field-control">
        <?php if (count($_selections) == 1 && $_option->getRequired()) : ?>
            <?= /* @noEscape */ $block->getSelectionQtyTitlePrice($_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 multiple="multiple" size="5" id="bundle-option-<?= $block->escapeHtmlAttr($_option->getId()) ?>"
                    name="bundle_option[<?= $block->escapeHtmlAttr($_option->getId()) ?>][]"
                    class="admin__control-multiselect bundle-option-<?= $block->escapeHtmlAttr($_option->getId()) ?><?php if ($_option->getRequired()) { echo ' required-entry'; } ?> multiselect change-container-classname"
                    onchange="ProductConfigure.bundleControl.changeSelection(this)">
            <?php if (!$_option->getRequired()) : ?>
                <option value=""><?= $block->escapeHtml(__('None')) ?></option>
            <?php endif; ?>
            <?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)) ?>">
                    <?= /* @noEscape */ $block->getSelectionQtyTitlePrice($_selection, false) ?></option>
            <?php endforeach; ?>
            </select>
        <?php endif; ?>
    </div>
</div>
