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

<?php /* @var $block \Magento\Bundle\Block\Catalog\Product\View\Type\Bundle\Option\Checkbox */ ?>
<?php $_option = $block->getOption() ?>
<?php $_selections = $_option->getSelections() ?>
<?php $inputClass = 'checkbox product bundle option bundle-option-' . $block->escapeHtmlAttr($_option->getId()) ?>
<?php $inputId = 'bundle-option-' . $block->escapeHtmlAttr($_option->getId()) ?>
<?php $inputName = 'bundle_option[' . $block->escapeHtmlAttr($_option->getId()) . ']' ?>
<?php $dataValidation = 'data-validate="{\'validate-one-required-by-name\':\'input[name^=&quot;bundle_option[' .
    $block->escapeHtmlAttr($_option->getId()) . ']&quot;]:checked\'}"' ?>

<div class="field option <?= ($_option->getRequired()) ? ' required': '' ?>">
    <label class="label">
        <span><?= $block->escapeHtml($_option->getTitle()) ?></span>
    </label>
    <div class="control">
        <div class="nested options-list">
            <?php if ($block->showSingle()): ?>
                <?= /* @noEscape */ $block->getSelectionQtyTitlePrice($_selections[0]) ?>
                <?= /* @noEscape */ $block->getTierPriceRenderer()->renderTierPrice($_selections[0]) ?>
                <input type="hidden"
                       class="bundle-option-<?= $block->escapeHtmlAttr($_option->getId()) ?>  product bundle option"
                       name="bundle_option[<?= $block->escapeHtml($_option->getId()) ?>]"
                       value="<?= $block->escapeHtmlAttr($_selections[0]->getSelectionId()) ?>"/>
            <?php else:?>
                <?php foreach ($_selections as $selection): ?>
                    <?php $sectionId = $selection->getSelectionId() ?>
                    <div class="field choice">
                        <input class="<?= /* @noEscape */ $inputClass ?> change-container-classname"
                               id="<?= /* @noEscape */ $inputId . '-' . $block->escapeHtmlAttr($sectionId) ?>"
                               type="checkbox"
                               <?php if ($_option->getRequired()): ?>
                                    <?= /* @noEscape */ $dataValidation ?>
                                <?php endif; ?>
                               name="<?= /* @noEscape */ $inputName . '[' . $block->escapeHtmlAttr($sectionId) ?>]"
                               data-selector="<?= /* @noEscape */ $inputName.'['.$block->escapeHtmlAttr($sectionId)?>]"
                               <?php if ($block->isSelected($selection)) { echo ' checked="checked"'; } ?>
                               <?php if (!$selection->isSaleable()) { echo ' disabled="disabled"'; } ?>
                               value="<?= $block->escapeHtmlAttr($selection->getSelectionId()) ?>"
                               data-errors-message-box="#validation-message-box"/>
                        <label class="label"
                               for="<?=/* @noEscape */ $inputId . '-' . $block->escapeHtmlAttr($sectionId) ?>">
                            <span><?= /* @noEscape */ $block->getSelectionQtyTitlePrice($selection) ?></span>
                            <br/>
                            <?= /* @noEscape */ $block->getTierPriceRenderer()->renderTierPrice($selection) ?>
                        </label>
                    </div>
                <?php endforeach; ?>
                <div id="bundle-option-<?= $block->escapeHtmlAttr($_option->getId()) ?>-container"></div>
                <div id="validation-message-box"></div>
            <?php endif; ?>
        </div>
    </div>
</div>
