<?php
/**
 * Copyright © MageMe. All rights reserved.
 * See LICENSE for license terms, or https://mageme.com/license.
 */
/**
 * Hyva theme override of the Step 1b order rows (shared by the page and the
 * load-more AJAX endpoint).
 *
 * @var \MageMe\EUWithdrawal\Block\Withdraw\OrderSelector $block
 * @var \Magento\Framework\Escaper $escaper
 */
?>
<?php foreach ($block->getOrders() as $order): ?>
    <?php $tns = $block->getItemThumbnails($order); $extra = $block->getExtraItemCount($order); ?>
    <li class="grid grid-cols-1 gap-4 py-5 sm:grid-cols-[auto_1fr_auto_auto] sm:items-center">
        <div class="flex gap-1.5">
            <?php foreach ($tns as $idx => $tn): ?>
                <div class="relative h-20 w-20 shrink-0 overflow-hidden rounded-lg border border-gray-200 bg-gray-50 max-sm:h-14 max-sm:w-14">
                    <?php if ($tn['url'] !== ''): ?>
                        <img src="<?= $escaper->escapeUrl($tn['url']) ?>" alt="<?= $escaper->escapeHtmlAttr($tn['alt']) ?>" class="h-full w-full object-cover">
                    <?php else: ?>
                        <div class="flex h-full w-full items-center justify-center text-gray-400"><svg viewBox="0 0 24 24" width="32" height="32" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M3 9l9-4 9 4v10l-9 4-9-4z"/><polyline points="3 9 12 13 21 9"/><line x1="12" y1="13" x2="12" y2="22"/></svg></div>
                    <?php endif; ?>
                    <?php if ($idx === count($tns) - 1 && $extra > 0): ?>
                        <span class="absolute inset-0 flex items-center justify-center bg-black/55 text-xs font-semibold leading-tight text-white text-center px-1">+<?= (int) $extra ?> <?= $escaper->escapeHtml(__('items')) ?></span>
                    <?php endif; ?>
                </div>
            <?php endforeach; ?>
        </div>
        <div class="min-w-0">
            <div class="text-[17px] font-semibold text-gray-900 leading-tight whitespace-nowrap max-sm:text-[16px] max-sm:whitespace-normal">
                <?= $escaper->escapeHtml(__('Order #%1', $block->getOrderIncrementId($order))) ?>
            </div>
            <div class="mt-1 text-[15px] text-gray-500">
                <?= $escaper->escapeHtml(__('Placed on %1', $block->formatOrderDate($order))) ?>
                <?php $delivered = $block->formatDeliveryDate($order); ?>
                <?php if ($delivered !== ''): ?>
                    · <?= $escaper->escapeHtml(__('Delivered on %1', $delivered)) ?>
                <?php else: ?>
                    · <?= $escaper->escapeHtml(__('Awaiting delivery')) ?>
                <?php endif; ?>
            </div>
        </div>
        <div class="text-right whitespace-nowrap max-sm:text-left">
            <div class="text-[18px] font-semibold text-gray-900 max-sm:text-[17px]"><?= $escaper->escapeHtml($block->formatOrderTotal($order)) ?></div>
            <div class="text-sm text-gray-500"><?= $escaper->escapeHtml($block->getShippingMethodLabel($order)) ?></div>
        </div>
        <div class="justify-self-end max-sm:justify-self-stretch">
            <a class="inline-flex items-center justify-center gap-2 whitespace-nowrap min-w-[140px] rounded-lg border border-primary px-5 py-2.5 text-[15px] font-semibold text-primary hover:bg-primary hover:text-white transition-colors group max-sm:w-full max-sm:py-3 max-sm:text-[16px]" href="<?= $escaper->escapeUrl($block->getStep2Url($order)) ?>">
                <span><?= $escaper->escapeHtml(__('Select order')) ?></span>
                <svg viewBox="0 0 16 16" width="16" height="16" aria-hidden="true" focusable="false" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="transition-transform group-hover:translate-x-0.5"><line x1="3" y1="8" x2="13" y2="8"/><polyline points="8,3 13,8 8,13"/></svg>
            </a>
        </div>
    </li>
<?php endforeach; ?>
