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

use Magento\CheckoutAgreements\Model\AgreementModeOptions;
?>
<?php
/**
 * @var $block \Magento\CheckoutAgreements\Block\Agreements
 * @var \Magento\Framework\View\Helper\SecureHtmlRenderer $secureRenderer
 */
?>
<?php if (!$block->getAgreements()) {
    return;
} ?>
<ol id="checkout-agreements" class="agreements checkout items">
    <?php /** @var \Magento\CheckoutAgreements\Api\Data\AgreementInterface $agreement */ ?>
    <?php foreach ($block->getAgreements() as $agreement):?>
        <li class="item">
            <div class="checkout-agreement-item-content" id="<?= /* @noEscape */ $agreement->getAgreementId() ?>"
                <?php if ($agreement->getIsHtml()):?>
                    <?= /* @noEscape */ $agreement->getContent() ?>
                <?php else:?>
                    <?= $block->escapeHtml(nl2br($agreement->getContent())) ?>
                <?php endif; ?>
            </div>
                <?php if ($agreement->getContentHeight()): ?>
                    <?= /* @noEscape */ $secureRenderer->renderStyleAsTag(
                        'height:' . $agreement->getContentHeight(),
                        '#' . $agreement->getAgreementId()
                    ) ?>
                <?php endif; ?>
            <?php if ($agreement->getMode() == AgreementModeOptions::MODE_MANUAL):?>
            <div id="checkout-agreements-form-<?= (int) $agreement->getAgreementId() ?>"
                 class="field choice agree required">
                <input type="checkbox"
                       id="agreement-<?= (int) $agreement->getAgreementId() ?>"
                       name="agreement[<?= (int) $agreement->getAgreementId() ?>]"
                       value="1"
                       title="<?= $block->escapeHtml($agreement->getCheckboxText()) ?>"
                       class="checkbox"
                       data-validate="{required:true}"/>
                <label class="label" for="agreement-<?= (int) $agreement->getAgreementId() ?>">
                    <span>
                        <?php if ($agreement->getIsHtml()):?>
                            <?= /* @noEscape */ $agreement->getCheckboxText() ?>
                        <?php else:?>
                            <?= $block->escapeHtml($agreement->getCheckboxText()) ?>
                        <?php endif; ?>
                    </span>
                </label>
            </div>
            <?php elseif ($agreement->getMode() == AgreementModeOptions::MODE_AUTO):?>
            <div id="checkout-agreements-form-<?= (int) $agreement->getAgreementId() ?>" class="field choice agree">
                <span>
                    <?php if ($agreement->getIsHtml()):?>
                        <?= /* @noEscape */ $agreement->getCheckboxText() ?>
                    <?php else:?>
                        <?= $block->escapeHtml($agreement->getCheckboxText()) ?>
                    <?php endif; ?>
                </span>
            </div>
            <?php endif; ?>
        </li>
    <?php endforeach ?>
</ol>
