<?php
/**
 * Copyright © Amazon.com, Inc. or its affiliates. All Rights Reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License").
 * You may not use this file except in compliance with the License.
 * A copy of the License is located at
 *
 *  http://aws.amazon.com/apache2.0
 *
 * or in the "license" file accompanying this file. This file is distributed
 * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
 * express or implied. See the License for the specific language governing
 * permissions and limitations under the License.
 */

use Amazon\Pay\Block\Adminhtml\System\Config\AutoKeyExchangeAdmin;
use Magento\Framework\Escaper;

/**
 * @var AutoKeyExchangeAdmin $block
 * @var Escaper $escaper
 */

$currency = $block->getCurrency();
?>

<?php if ($block->canUpgrade()): ?>
    <div data-mage-init='{"Amazon_Pay/js/keyupgrade": <?= $escaper->escapeHtml($block->getKeyUpgradeConfig()) ?>}'
            id="amazon_keyupgrade">
        <div id="keyupgrade-hint">
            <?= $escaper->escapeHtml(
                __(
                    "Amazon Pay will not be functional until the legacy keys associated with your configuration " .
                    "are updated. Click the button below to upgrade your credentials."
                )
            ); ?>
        </div>

        <span class="apkeys-getstarted">
            <button id="amazon_keyupgrade_start" type="button">
                <span><?= /* @noEscape */__('Upgrade your legacy Amazon Pay credentials'); ?></span>
            </button>
        </span>
        <br />
        <span id="keyupgrade_message">
            <?= /* @noEscape */ __('Updating your config with new keys, please wait...'); ?>
        </span>

    </div>
<?php else: ?>
    <div data-mage-init='{
            "Amazon_Pay/js/autokeyexchange": <?= $escaper->escapeHtml($block->getJsonConfig()) ?> }'
        id="amazon_autokeyexchange">
        <?php if (!$currency): // Auto Key Exchange not supported ?>
            <div id="autokeyexchange_unsupported">
                <?= $escaper->escapeHtml(__('An unsupported currency is currently selected. ' .
                    'Please review our configuration guide.')); ?>
                <span class="note">
                    <a href="https://amzn.github.io/amazon-payments-magento-2-plugin/configuration.html"
                        target="_blank">
                    (<?= $escaper->escapeHtml(__('More Information')); ?>)
                    </a>
                </span>
            </div>
        <?php elseif ($currency == 'JPY'): // JPY (JA) AKE not supported ?>
            <div></div>
        <?php else: ?>
            <div id="autokeyexchange-hint">
                <div id="keypair-hint">
                    <p class="message message-info">
                        <?= $escaper->escapeHtml(
                            __("If you are trying to automatically register/configure your account and it is not " .
                            "working, try clicking the Reset configuration button to reset the internal " .
                            "public/private key, and then retry the transfer process.")
                        ); ?>
                    </p>
                </div>
                <?= $escaper->escapeHtml(
                    __(
                        "You'll be connecting/registering a %1 account based on your display currency of your store " .
                        "scope. For more information, see Amazon Pay for Magento 2.",
                        $block->getRegion()
                    )
                ); ?>
                <span class="note">
                    <a href="https://amzn.github.io/amazon-payments-magento-2-plugin/overview.html" target="_blank">
                        (<?= $escaper->escapeHtml(__('More Information')); ?>)
                    </a>
                </span>
            </div>

            <span class="apkeys-getstarted">
            <button>
                <span><?= $escaper->escapeHtml(__('Start account connection/registration')); ?></span>
            </button>
            </span>
            <span class="apkeys-or">
            &nbsp; <?= $escaper->escapeHtml(__('or')); ?> &nbsp;
            <a href="#" id="autokeyexchange-skip">
                <?= $escaper->escapeHtml(__("I've already set up Amazon Pay with Magento and I want to edit " .
                "my configuration.")); ?>
            </a>
            </span>
            <p id="amazon_https_required">
                <?=
                $escaper->escapeHtml(__("In order to enable automatic account configuration using Amazon's secure " .
                'key exchange, please turn on secure admin pages in General > Web > Use secure URLs in Admin.'));
                ?>
            </p>
            <p id="amazon_reload">
                <?= $escaper->escapeHtml(__('Updating your config with new keys, please wait...')); ?>
            </p>
            <div class="reset-auto-key-exchange">
                <button id="reset-auto-key-exchange-button" type="button">
                    <?= /* @noEscape */ __('Reset configuration') ?>
                </button>
                <br />
                <span id="reset-auto-key-exchange-message">
                    <?= /* @noEscape */ __('Resetting the Amazon Pay configuration. After the page reloaded, ' .
                    'click Start configuration/registration.'); ?>
                </span>
            </div>
        <?php endif; ?>
    </div>

    <div id="amazon_autokeyexchange_back">
        <a href="#">&laquo; <?= $escaper->escapeHtml(__('Back to account connection/registration')); ?></a>
    </div>
<?php endif; ?>
