<?php
/**
 *
 * Adyen Payment Module
 *
 * Copyright (c) 2023 Adyen N.V.
 * This file is open source and available under the MIT license.
 * See the LICENSE file for more info.
 *
 * Author: Adyen <magento@adyen.com>
 */

use Magento\Payment\Block\Form;

/**
 * @var Form $block
 */
$code = $block->getMethod()->getCode();

/** @var \Magento\Framework\View\Helper\SecureHtmlRenderer $secureRenderer */


$script = <<<SCRIPT
    require([
        'uiLayout',
        'jquery'
    ], function (layout, \$) {
        \$(function () {
            const paymentMethodCode = "{$block->escapeJs($code)}";
            const customMethodRenderers = window.checkoutConfig.payment.adyen.customMethodRenderers;
            const paymentMethodData = {
                method: paymentMethodCode
            };

            let multishippingFrontendComponent;

            if (typeof customMethodRenderers[paymentMethodCode] !== 'undefined') {
                let frontendComponent = customMethodRenderers[paymentMethodCode];
                multishippingFrontendComponent = frontendComponent.replace('/method-renderer/', '/method-renderer/multishipping/');
            } else {
                multishippingFrontendComponent = 'Adyen_Payment/js/view/payment/method-renderer/multishipping/adyen-pm-method';
            }

            layout([
                {
                    component: multishippingFrontendComponent,
                    name: 'payment_method_' + "{$block->escapeJs($code)}",
                    method: paymentMethodData.method,
                    item: paymentMethodData
                }
            ]);

            \$('body').trigger('contentUpdated');
        });
    });
SCRIPT;

/* @noEscape */
echo $secureRenderer->renderTag('script', [], $script, false);
?>

<!-- ko template: getTemplate() --><!-- /ko -->

