<?php
/**
 * Popup container template.
 *
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 *
 * @var \Magento\Backend\Block\Template $block
 */

/** @var \Magento\Backend\Block\Template $block */
/** @var \Magento\Framework\View\Helper\SecureHtmlRenderer $secureRenderer */
?>

<?php $scriptString = <<<script
    require([
        "jquery",
        'Magento_Ui/js/modal/confirm',
        "jquery/ui",
        "Magento_Integration/js/integration",
        'mage/dataPost'
    ], function ($, Confirm) {

        window.integration = new Integration(
            '{$block->escapeJs(
                $block->getUrl(
                    '*/*/permissionsDialog',
                    ['id' => ':id', 'reauthorize' => ':isReauthorize', '_escape_params' => false]
                )
            )}',
            '{$block->escapeJs(
                $block->getUrl(
                    '*/*/tokensDialog',
                    ['id' => ':id', 'reauthorize' => ':isReauthorize', '_escape_params' => false]
                )
            )}',
            '{$block->escapeJs(
                $block->getUrl(
                    '*/*/tokensExchange',
                    ['id' => ':id', 'reauthorize' => ':isReauthorize', '_escape_params' => false]
                )
            )}',
            '{$block->escapeJs(
                $block->getUrl(
                    '*/*'
                )
            )}',
            '{$block->escapeJs(
                $block->getUrl(
                    '*/*/loginSuccessCallback'
                )
            )}'
        );

        /**
         * Confirm dialog for delete integration action
         */
        $(function () {
            $('div#integrationGrid').on('click', 'button#delete', function (e) {

                new Confirm({
                    title: '{$block->escapeJs(__('Are you sure?'))}',
                    content: "{$block->escapeJs(__("Are you sure you want to delete this integration? " .
                                                     "You can't undo this action."))}",
                    actions: {
                        confirm: function () {
                            $.mage.dataPost().postData({action: $(e.target).data('url'), data: {}});
                        }
                    }
                });
                e.stopPropagation();
            });
        });
    });
script;
?>
<?= /* @noEscape */ $secureRenderer->renderTag('script', [], $scriptString, false) ?>

<div id="integration-popup-container"></div>
<?= /* @noEscape */ $secureRenderer->renderStyleAsTag("display: none;", '#integration-popup-container') ?>
