<section class="page-hero page-hero-compact">
    <div class="container">
        <span class="eyebrow">Good to see you</span>
        <h1>My Account</h1>
    </div>
</section>

<div class="container account-grid section">
    <section class="panel">
        <div class="panel-heading">
            <div>
                <span class="eyebrow">Your details</span>
                <h2>Pickup Profile</h2>
            </div>
            <span class="account-email"><?= e($currentUser['email']) ?></span>
        </div>
        <form class="form-stack" action="<?= e(url('/account')) ?>" method="post">
            <?= csrf_field() ?>
            <div class="form-grid">
                <label>Full name
                    <input type="text" name="full_name" required value="<?= e($currentUser['full_name']) ?>">
                </label>
                <label>Phone
                    <input type="tel" name="phone" required value="<?= e($currentUser['phone']) ?>">
                </label>
                <label class="field-wide">Street address
                    <input type="text" name="street_address" value="<?= e($currentUser['street_address']) ?>">
                </label>
                <label>City
                    <input type="text" name="city" value="<?= e($currentUser['city']) ?>">
                </label>
                <label>State
                    <input type="text" name="state" maxlength="2" value="<?= e($currentUser['state']) ?>">
                </label>
                <label>ZIP code
                    <input type="text" name="postal_code" value="<?= e($currentUser['postal_code']) ?>">
                </label>
            </div>
            <label class="check-control">
                <input type="checkbox" name="newsletter_opt_in" value="1" <?= checked($currentUser['newsletter_opt_in']) ?>>
                <span>
                    <strong>Send me restaurant news and specials</strong>
                    <small>You can change this any time.</small>
                </span>
            </label>
            <label class="check-control">
                <input type="checkbox" name="two_factor_enabled" value="1" <?= checked($currentUser['two_factor_enabled'] ?? 0) ?>>
                <span>
                    <strong>Use email two-factor authentication</strong>
                    <small>Optional. When enabled, each sign-in requires a six-digit code sent to <?= e($currentUser['email']) ?>.</small>
                </span>
            </label>
            <details class="account-password">
                <summary>Change password</summary>
                <div class="form-stack">
                    <label>Current password
                        <input type="password" name="current_password" autocomplete="current-password">
                    </label>
                    <div class="form-grid">
                        <label>New password
                            <input type="password" name="new_password" minlength="10" autocomplete="new-password">
                        </label>
                        <label>Confirm new password
                            <input type="password" name="new_password_confirmation" minlength="10" autocomplete="new-password">
                        </label>
                    </div>
                </div>
            </details>
            <button class="button" type="submit">Save Account</button>
        </form>
    </section>
    <section class="panel">
        <div class="panel-heading">
            <div>
                <span class="eyebrow">Past pickups</span>
                <h2>Order History</h2>
            </div>
            <a class="button button-small" href="<?= e(url('/menu')) ?>">Order Again</a>
        </div>
        <?php if (!$orders): ?>
            <div class="empty-state compact">
                <p>Your first online order will appear here.</p>
            </div>
        <?php else: ?>
            <div class="order-history">
                <?php foreach ($orders as $order): ?>
                    <article>
                        <div>
                            <a href="<?= e(url('/order/track')) ?>?order=<?= e(rawurlencode((string) $order['order_number'])) ?>"><strong><?= e($order['order_number']) ?></strong></a>
                            <span><?= e(store_datetime((string) $order['placed_at'])) ?></span>
                        </div>
                        <span class="status-pill status-<?= e($order['status']) ?>"><?= e(order_status_label((string) $order['status'])) ?></span>
                        <strong><?= money($order['total_cents']) ?></strong>
                    </article>
                <?php endforeach; ?>
            </div>
        <?php endif; ?>
    </section>
</div>
