<?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; ?>
            <form id="checkout-agreements-form-<?= (int) $agreement->getAgreementId() ?>"
                  class="field choice agree required">
                <?php if ($agreement->getMode() == AgreementModeOptions::MODE_MANUAL):?>
                <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>
                <?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; ?>
            </form>
        </li>
    <?php endforeach ?>
</ol>
