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

// @codingStandardsIgnoreFile

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

/** @var \Magento\CheckoutAgreements\Model\ResourceModel\Agreement\Collection $argeementsCollection */
$argeementsCollection = $block->getAgreements();
$agreementMappedArray = [];
/** @var \Magento\CheckoutAgreements\Model\Agreement $agreement */
foreach ($argeementsCollection 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": <?php /* @noEscape */ echo $agreementJson; ?>,
                        "isVisible": true
                    }
                }
            }
        }
    }
</script>
