<?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\Checkbox */ ?>
<?php $_option = $block->getOption(); ?>
<?php $_selections = $_option->getSelections(); ?>
<?php $_skipSaleableCheck = $this->helper(Magento\Catalog\Helper\Product::class)->getSkipSaleableCheck(); ?>

<div class="field admin__field options<?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">
        <div class="nested <?php if ($_option->getDecoratedIsLast()) :?> last<?php endif;?>">

            <?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 :?>

                <?php foreach ($_selections as $_selection) : ?>
                    <div class="field choice admin__field admin__field-option">
                        <input
                            class="change-container-classname admin__control-checkbox checkbox bundle-option-<?= $block->escapeHtmlAttr($_option->getId()) ?> <?php if ($_option->getRequired()) { echo 'validate-one-required-by-name'; } ?>"
                            id="bundle-option-<?= $block->escapeHtmlAttr($_option->getId()) ?>-<?= $block->escapeHtmlAttr($_selection->getSelectionId()) ?>"
                            type="checkbox"
                            name="bundle_option[<?= $block->escapeHtmlAttr($_option->getId()) ?>][<?= $block->escapeHtmlAttr($_selection->getId()) ?>]"
                            <?php if ($block->isSelected($_selection)) :?>
                                <?= ' checked="checked"' ?>
                            <?php endif;?>
                            <?php if (!$_selection->isSaleable() && !$_skipSaleableCheck) :?>
                                <?= ' disabled="disabled"' ?>
                            <?php endif;?>
                            value="<?= $block->escapeHtmlAttr($_selection->getSelectionId()) ?>"
                            onclick="ProductConfigure.bundleControl.changeSelection(this)"
                            price="<?= $block->escapeHtmlAttr($block->getSelectionPrice($_selection)) ?>" />

                        <label class="admin__field-label"
                               for="bundle-option-<?= $block->escapeHtmlAttr($_option->getId()) ?>-<?= $block->escapeHtmlAttr($_selection->getSelectionId()) ?>">
                            <span><?= /* @noEscape */ $block->getSelectionQtyTitlePrice($_selection) ?></span>
                        </label>

                        <?php if ($_option->getRequired()) : ?>
                            <?=  /* @noEscape */ $block->setValidationContainer('bundle-option-' . $_option->getId() . '-' . $_selection->getSelectionId(), 'bundle-option-' . $_option->getId() . '-container') ?>
                        <?php endif;?>
                    </div>
                <?php endforeach; ?>

                <div id="bundle-option-<?= $block->escapeHtmlAttr($_option->getId()) ?>-container"></div>
            <?php endif; ?>
        </div>
    </div>
</div>
