<?php
/**
 * Copyright 2014 Adobe
 * All Rights Reserved.
 */
?>

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

<div class="field option <?= ($_option->getRequired()) ? ' required': '' ?>">
    <label class="label">
        <span><?= $escaper->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-<?= $escaper->escapeHtmlAttr($_option->getId()) ?>  product bundle option"
                       name="bundle_option[<?= $escaper->escapeHtml($_option->getId()) ?>]"
                       value="<?= $escaper->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 . '-' . $escaper->escapeHtmlAttr($sectionId)?>"
                           type="checkbox"
                           <?php if ($_option->getRequired()): ?>
                                <?= /* @noEscape */ $dataValidation ?>
                           <?php endif;?>
                           name="<?=/* @noEscape */ $inputName .'['. $escaper->escapeHtmlAttr($sectionId)?>]"
                           data-selector="<?= /* @noEscape */ $inputName.'['.$escaper->escapeHtmlAttr($sectionId)?>]"
                            <?php if ($block->isSelected($selection)): ?>
                                <?= ' checked="checked"' ?>
                            <?php endif; ?>
                            <?php if (!$selection->isSaleable()): ?>
                                <?= ' disabled="disabled"' ?>
                            <?php endif; ?>
                           value="<?= $escaper->escapeHtmlAttr($sectionId) ?>"
                        data-errors-msg-box="#validation-message-box-<?=$escaper->escapeHtmlAttr($_option->getId())?>"/>
                        <label class="label"
                               for="<?= /* @noEscape */ $inputId . '-' . $escaper->escapeHtmlAttr($sectionId) ?>">
                            <span><?= /* @noEscape */ $block->getSelectionQtyTitlePrice($selection) ?></span>
                            <br/>
                            <?= /* @noEscape */ $block->getTierPriceRenderer()->renderTierPrice($selection) ?>
                        </label>
                    </div>

                <?php endforeach; ?>
            <?php endif; ?>
        </div>
        <div id="bundle-option-<?= $escaper->escapeHtmlAttr($_option->getId()) ?>-container"></div>
        <div id="validation-message-box-<?= $escaper->escapeHtmlAttr($_option->getId()) ?>"></div>
    </div>
</div>
