<?php
/**
 * Copyright © MageMe. All rights reserved.
 * See LICENSE for license terms, or https://mageme.com/license.
 */
/** @var \MageMe\EUWithdrawal\Block\Withdraw\OrderSelector $block */
/** @var \Magento\Framework\Escaper $escaper */
$orders = $block->getOrders();

$svgInfo = '<svg class="mm-eu-w-banner-icon-svg" viewBox="0 0 24 24" width="20" height="20" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><circle cx="12" cy="12" r="9"/><path d="M12 11v5"/><circle cx="12" cy="8" r="1" fill="currentColor" stroke="none"/></svg>';
?>
<section class="mm-eu-w-step1b">
    <div class="mm-eu-w-card">
        <h2 class="mm-eu-w-card-title"><?= $escaper->escapeHtml(__('Select an order')) ?></h2>
        <p class="mm-eu-w-card-subtitle">
            <?= $escaper->escapeHtml(__('Choose an order from your history to start a return or withdrawal.')) ?>
        </p>
        <?php if (empty($orders)): ?>
            <div class="mm-eu-w-empty">
                <p>
                    <?= $escaper->escapeHtml(__(
                        "You don't have any orders eligible for withdrawal. The %1-day withdrawal window runs from the day you received your order.",
                        $block->getWithdrawalPeriodDays()
                    )) ?>
                </p>
                <a class="mm-eu-w-link" href="<?= $escaper->escapeUrl($block->getOrderHistoryUrl()) ?>">
                    <?= $escaper->escapeHtml(__('View all my orders')) ?>
                </a>
            </div>
        <?php else: ?>
            <ul id="mm-eu-w-order-list" class="mm-eu-w-order-list" data-role="order-list">
                <?= /* @noEscape */ $block->getChildHtml('order_rows') ?>
            </ul>
            <?php if ($block->canLoadMore()): ?>
                <div class="mm-eu-w-load-more" data-role="load-more-wrap">
                    <a class="mm-eu-w-btn mm-eu-w-btn--outlined"
                       data-role="load-more"
                       href="<?= $escaper->escapeUrl($block->getLoadMoreUrl()) ?>"
                       data-endpoint="<?= $escaper->escapeUrl($block->getLoadMoreEndpoint()) ?>">
                        <svg class="mm-eu-w-spinner" viewBox="0 0 24 24" width="16" height="16" fill="none" aria-hidden="true">
                            <circle cx="12" cy="12" r="9" stroke="currentColor" stroke-width="3" stroke-linecap="round" stroke-dasharray="40 60">
                                <animateTransform attributeName="transform" type="rotate" from="0 12 12" to="360 12 12" dur="0.7s" repeatCount="indefinite"/>
                            </circle>
                        </svg>
                        <span><?= $escaper->escapeHtml(__('Show more orders')) ?></span>
                    </a>
                </div>
            <?php endif; ?>
        <?php endif; ?>
    </div>
    <div class="mm-eu-w-banner mm-eu-w-banner--info">
        <span class="mm-eu-w-banner-icon" aria-hidden="true"><?= /* @noEscape */ $svgInfo ?></span>
        <span class="mm-eu-w-banner-text">
            <?= $escaper->escapeHtml(__('You have the right to withdraw from your purchase within %1 days of receiving your order, without giving any reason.', $block->getWithdrawalPeriodDays())) ?>
        </span>
    </div>
</section>
<script type="text/javascript"
        src="<?= $escaper->escapeUrl($block->getViewFileUrl('MageMe_EUWithdrawal::js/load-more-orders.js')) ?>"
        defer></script>
