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

/**
 * @var \Magento\Payment\Block\Transparent\Iframe $block
 * @var \Magento\Framework\View\Helper\SecureHtmlRenderer $secureRenderer
 */
$params = $block->getParams();

/** @var \Magento\Framework\Json\Helper\Data $jsonHelper */
$jsonHelper = $block->getData('jsonHelper');
?>
<html>
<head>
    <?php $scriptString = '' ?>
<?php if (isset($params['redirect'])): ?>
    <?php $scriptString .= <<<script
    window.location="{$block->escapeJs($params['redirect'])}";
script;
    ?>
<?php elseif (isset($params['redirect_parent'])): ?>
    <?php $scriptString .= <<<script
    window.top.location="{$block->escapeJs($params['redirect_parent'])}";
script;
    ?>
<?php elseif (isset($params['error_msg'])): ?>
    <?php $encodedErrorMsg = /* @noEscape */ $jsonHelper->jsonEncode($params['error_msg']);
    $scriptString .= <<<script
    window.top.alert({$encodedErrorMsg});
script;
    ?>
<?php elseif (isset($params['order_success'])): ?>
    <?php $scriptString .= <<<script
    window.top.location = "{$block->escapeJs($params['order_success'])}";
script;
    ?>
<?php else: ?>
    <?php $scriptString .= <<<script
    var require = window.top.require;
    require(['jquery'], function($) {
        $('#edit_form').trigger('processStop');

        $("input[name='payment[cc_number]']").prop('disabled', true);
        $("select[name='payment[cc_type]']").prop('disabled', true);
        $("select[name='payment[cc_exp_month]']").prop('disabled', true);
        $("select[name='payment[cc_exp_year]']").prop('disabled', true);
        $("input[name='payment[cc_cid]']").prop('disabled', true);

        $('#edit_form').trigger('realOrder');
    });
script;
    ?>
<?php endif; ?>
    <?= /* @noEscape */ $secureRenderer->renderTag('script', [], $scriptString, false) ?>
</head>
<body>
</body>
</html>
