<?php
/**
 * Webkul Software.
 *
 * @category  Webkul
 * @package   Webkul_MpPayPal
 * @author    Webkul
 * @copyright Copyright (c) Webkul Software Private Limited (https://webkul.com)
 * @license   https://store.webkul.com/license.html
 */
$transactions = $block->getOrderTransactions();
$sessionData = $block->getCoreSessionObj();
if ($sessionData->getErrorMessage() != '') {
    ?>
    <div id="messages">
        <div class="messages">
            <div class="message message-error error">
                <div data-ui-id="messages-message-error">
                    <?= $block->escapeHtml($sessionData->getErrorMessage()) ?>
                </div>
            </div>
        </div>
    </div>
    <?php
}
if ($sessionData->getSuccessMessage() != '') {
    ?>
    <div id="messages">
        <div class="messages">
            <div class="message message-success success">
                <div data-ui-id="messages-message-success">
                    <?= $block->escapeHtml($sessionData->getSuccessMessage()) ?>
                </div>
            </div>
        </div>
    </div>
    <?php
}
if ($transactions->getSize() > 0) {
    ?>
    <table class="data-table admin__table-primary">
        <tr class="headings">
            <th><?= /*@noEscape*/ __('Seller Name') ?></th>
            <th><?= /*@noEscape*/ __('Transaction Id') ?></th>
            <th><?= /*@noEscape*/ __('Action') ?></th>
        </tr>
    <?php
    foreach ($transactions as $transaction) {
        ?>
        <tr>
        <td><?= $block->escapeHtml($block->getSellerName($transaction->getSellerId())) ?></td>
        <?php
        if ($transaction->getDelayedPayment() && !$transaction->getPaymentStatus()) {
            $url = $block->getReleaseUrl($transaction->getCaptureId());
            ?>
            <td><b><?=  $block->escapeHtml($transaction->getCaptureId()); ?></b></td>
            <td>
                <div class="mppaypal-transactions">
                    <button style=""
                        onclick="submitAndReloadArea(
                            $('sales_order_view_tabs_delayed_payment_content'), '<?= $block->escapeUrl($url); ?>'
                        )"
                        class="scalable save"
                        type="button" title="Release Vendor Payment" id="vendor_payment">
                        <span><span><span><?= /* @noEscape */ __('Release Vendor Payment')?></span></span></span>
                    </button>
                </div>
            </td>
            <?php
        } elseif ($transaction->getDelayedPayment() && $transaction->getPaymentStatus()) {
            ?>
            <td><b><?=  $block->escapeHtml($transaction->getCaptureId()); ?></b></td>
            <td>
                <div class="mppaypal-transactions">
                    <span>
                        <?=  $block->escapeHtml(__("Delayed Payment released")); ?>
                    </span>
                </div>
            </td>
            <?php
        }
        ?>
        </tr>
        <?php
    }
    ?>
    </table>
    <?php
} else {
    ?>
    <note><b><?=  $block->escapeHtml(__("No transactions found in this order")); ?></b></note>
    <?php
}
?>
</div>