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

/**
 * @var $block \Magento\CheckoutAgreements\Block\Agreements
 */
if (!$block->getAgreements()) {
    return;
}

/** @var \Magento\CheckoutAgreements\Model\ResourceModel\Agreement\Collection $agreementsCollection */
$agreementsCollection = $block->getAgreements();
$agreementMappedArray = [];
/** @var \Magento\CheckoutAgreements\Model\Agreement $agreement */
foreach ($agreementsCollection as $agreement) {
    if ($agreement->getIsActive()) {
        $agreementMappedArray[] = [
            'mode' => $agreement->getMode(),
            'agreementId' => $agreement->getAgreementId(),
            'checkboxText' => $agreement->getCheckboxText(),
            'content' => $agreement->getContent()
        ];
    }
}
$agreementJson = json_encode($agreementMappedArray);
?>

<div data-bind="scope: 'checkout-agreements-component-scope'" class="checkout-agreements-block">
    <!-- ko template: getTemplate() --><!-- /ko -->
</div>
<script type="text/x-magento-init">
    {
        "*": {
            "Magento_Ui/js/core/app": {
                "components": {
                    "checkout-agreements-component-scope": {
                        "component": "Magento_CheckoutAgreements/js/view/checkout-agreements",
                        "agreements": <?= /* @noEscape */ $agreementJson ?>,
                        "isVisible": true
                    }
                }
            }
        }
    }
</script>
