<section class="page-hero page-hero-compact">
    <div class="container">
        <span class="eyebrow">Almost yours</span>
        <h1>Your Order</h1>
    </div>
</section>

<div class="container checkout-layout section">
    <section class="checkout-main">
        <?php if (empty($cart['items'])): ?>
            <div class="empty-state">
                <h2>Your order is wide open.</h2>
                <p>Start with a burger, a burrito, or whatever sounds good right now.</p>
                <a class="button" href="<?= e(url('/menu')) ?>">Browse the Menu</a>
            </div>
        <?php else: ?>
            <form action="<?= e(url('/cart/update')) ?>" method="post">
                <?= csrf_field() ?>
                <div class="cart-list">
                    <?php foreach ($cart['items'] as $item): ?>
                        <article class="cart-item">
                            <div class="cart-item-mark"><?= e(strtoupper(substr((string) $item['name'], 0, 2))) ?></div>
                            <div class="cart-item-copy">
                                <h2><?= e($item['name']) ?></h2>
                                <?php if ($item['notes']): ?><p>Note: <?= e($item['notes']) ?></p><?php endif; ?>
                                <span><?= money($item['unit_price_cents']) ?> each</span>
                            </div>
                            <label class="quantity-field">
                                <span>Qty</span>
                                <input type="number" min="0" max="20" name="quantity[<?= (int) $item['id'] ?>]" value="<?= (int) $item['quantity'] ?>">
                            </label>
                            <strong class="cart-line-total"><?= money((int) $item['quantity'] * (int) $item['unit_price_cents']) ?></strong>
                            <button class="icon-button remove-cart-item" type="submit" formaction="<?= e(url('/cart/remove')) ?>" name="cart_item_id" value="<?= (int) $item['id'] ?>" aria-label="Remove <?= e($item['name']) ?>">&times;</button>
                        </article>
                    <?php endforeach; ?>
                </div>
                <div class="cart-actions">
                    <a class="text-link" href="<?= e(url('/menu')) ?>">Add More Items</a>
                    <button class="button button-outline" type="submit">Update Order</button>
                </div>
            </form>
        <?php endif; ?>
    </section>
    <?php if (!empty($cart['items'])): ?>
        <aside class="order-summary">
            <span class="eyebrow">Pickup summary</span>
            <h2><?= (int) $cart['item_count'] ?> <?= (int) $cart['item_count'] === 1 ? 'item' : 'items' ?></h2>
            <dl>
                <div><dt>Subtotal</dt><dd><?= money($totals['subtotal_cents']) ?></dd></div>
                <div><dt>Estimated tax</dt><dd><?= money($totals['tax_cents']) ?></dd></div>
                <div class="summary-total"><dt>Total</dt><dd><?= money($totals['total_cents']) ?></dd></div>
            </dl>
            <a class="button button-block button-large" href="<?= e(url('/checkout')) ?>">Continue to Checkout</a>
            <p class="summary-note">Pickup at 410 W Piedmont St, Keyser.</p>
        </aside>
    <?php endif; ?>
</div>
