<?php
/**
 *
 * Adyen Payment module (https://www.adyen.com/)
 *
 * Copyright (c) 2015 Adyen BV (https://www.adyen.com/)
 * See LICENSE.txt for license details.
 *
 * Author: Adyen <magento@adyen.com>
 */

/**
 * @see \Magento\Payment\Block\Info
 * @var PaymentMethodInfo $block
 */

use Adyen\Payment\Block\Info\PaymentMethodInfo;

$_info = $block->getInfo();
$_isDemoMode = $block->isDemoMode();

?>

<?= $block->escapeHtml($block->getMethod()->getTitle()); ?>

<?php if ($_pspReference = $_info->getAdditionalInformation('pspReference')): ?>
    <div>
        <?php if ($_isDemoMode): ?>
            <?= $block->escapeHtml(__('Adyen PSP Reference: ')); ?>
            <a href="https://ca-test.adyen.com/ca/ca/accounts/showTx.shtml?pspReference=<?= $block->escapeHtml(
                $_pspReference
            ); ?>&txType=Payment" target="_blank"><?= $block->escapeHtml($_pspReference); ?></a>
        <?php else: ?>
            <?= $block->escapeHtml(__('Adyen PSP Reference: ')); ?>
            <a href="https://ca-live.adyen.com/ca/ca/accounts/showTx.shtml?pspReference=<?= $block->escapeHtml(
                $_pspReference
            ); ?>&txType=Payment" target="_blank"><?= $block->escapeHtml($_pspReference); ?></a>
        <?php endif; ?>
    </div>
<?php endif; ?>

<?php if (!empty($block->getBankTransferData())): ?>

    <?php
    $banktranferData = $block->getBankTransferData();
    $order = $block->getOrder();
    $orderAmountCurrency = $block->getOrderAmountCurrency();
    ?>

    <div>
        <table class="edit-order-table" style="text-align:left; margin-top:5px; margin-bottom:0;" aria-describedby="Payment Details">
            <tbody>
            <?php if (!empty($orderAmountCurrency->getAmount())): ?>
                <tr>
                    <th scope="row"><?= $block->escapeHtml(__('Amount')); ?></th>
                    <td><?= /* @noEscape */ $order->formatPrice($orderAmountCurrency->getAmount()); ?></td>
                </tr>
            <?php endif; ?>

            <?php if (!empty($banktranferData['bankTransfer.reference'])): ?>
                <tr>
                    <th scope="row"><?= $block->escapeHtml(__('With reference')); ?></th>
                    <td><?= $block->escapeHtml($banktranferData['bankTransfer.reference']); ?></td>
                </tr>
            <?php endif; ?>

            <?php if (!empty($banktranferData['bankTransfer.owner'])): ?>
                <tr>
                    <th scope="row"><?= $block->escapeHtml(__('Beneficiary Name')); ?></th>
                    <td><?= $block->escapeHtml($banktranferData['bankTransfer.owner']); ?></td>
                </tr>
            <?php endif; ?>

            <?php if (!empty($banktranferData['bankTransfer.bankName'])): ?>
                <tr>
                    <th scope="row"><?= $block->escapeHtml(__('Bank')); ?></th>
                    <td><?= $block->escapeHtml($banktranferData['bankTransfer.bankName']); ?></td>
                </tr>
            <?php endif; ?>

            <?php if (!empty($banktranferData['bankTransfer.iban'])): ?>
                <tr>
                    <th scope="row"><?= $block->escapeHtml(__('IBAN')); ?></th>
                    <td><?= $block->escapeHtml($banktranferData['bankTransfer.iban']); ?></td>
                </tr>
            <?php endif; ?>

            <?php if (!empty($banktranferData['bankTransfer.accountCode'])): ?>
                <tr>
                    <th scope="row"><?= $block->escapeHtml(__('Bankaccount')); ?></th>
                    <td><?= $block->escapeHtml($banktranferData['bankTransfer.accountCode']); ?></td>
                </tr>
            <?php endif; ?>
            </tbody>
        </table>
    </div>
<?php elseif (!empty($block->getMultibancoData())): ?>
    <?php
    $multibancoData = $block->getMultibancoData();
    ?>

    <div>
        <table class="edit-order-table" style="text-align:left; margin-top:5px; margin-bottom:0;" aria-describedby="Multibanco Details">
            <tbody>
            <?php if (!empty($multibancoData['entity'])): ?>
                <tr>
                    <th scope="row"><?= $block->escapeHtml(__('Entity')); ?></th>
                    <td><?= $block->escapeHtml($multibancoData['entity']); ?></td>
                </tr>
            <?php endif; ?>

            <?php if (!empty($multibancoData['reference'])): ?>
                <tr>
                    <th scope="row"><?= $block->escapeHtml(__('Reference')); ?></th>
                    <td><?= $block->escapeHtml($multibancoData['reference']); ?></td>
                </tr>
            <?php endif; ?>

            <?php if (!empty($multibancoData['expiresAt'])): ?>
                <tr>
                    <th scope="row"><?= $block->escapeHtml(__('Expires at')); ?></th>
                    <td><?= $block->escapeHtml($multibancoData['expiresAt']); ?></td>
                </tr>
            <?php endif; ?>
            </tbody>
        </table>
    </div>
<?php endif; ?>

<?php if ($_info->getAdditionalInformation('adyen_total_fraud_score') != ""): ?>
    <?= $block->escapeHtml(__('Total fraud score: ')); ?>
    <?= $block->escapeHtml($_info->getAdditionalInformation('adyen_total_fraud_score')); ?>
    <br/>
<?php endif; ?>

<?php
    if ($block->getPartialPayments()->getSize() > 1) {
        echo $block->renderPartialPaymentsHtml();
    }
?>

<?php if ($_specificInfo = $block->getSpecificInformation()): ?>
    <table class="data-table admin__table-secondary" aria-describedby="Specific Information">
        <?php foreach ($_specificInfo as $_label => $_value): ?>
            <tr>
                <th scope="row"><?= $block->escapeHtml($_label) ?>:</th>
                <td><?= $block->escapeHtml(nl2br(implode("\n", $block->getValueAsArray($_value, true)))); ?></td>
            </tr>
        <?php endforeach; ?>
    </table>
<?php endif; ?>

<?php if ($ratepayDescriptor = $_info->getAdditionalInformation('adyen_ratepay_descriptor')): ?>
    <div><?= $block->escapeHtml(__('Invoice Descriptor: %1', $ratepayDescriptor)); ?>
    </div>
<?php endif; ?>

<?= $block->escapeHtml($block->getChildHtml()); ?>
