<?php

use Lab\Helpers;

require dirname(__DIR__) . '/partials/head.php';
require dirname(__DIR__) . '/partials/studio-nav.php';
?>
<main class="wrap studio">
    <?php require dirname(__DIR__) . '/partials/flash.php'; ?>
    <div class="stats">
        <div class="stat"><b><?= (int) $stats['today'] ?></b><span>Σήμερα</span></div>
        <div class="stat"><b><?= (int) $stats['open'] ?></b><span>Σε εκτέλεση</span></div>
        <div class="stat"><b><?= (int) $stats['ready'] ?></b><span>Έτοιμες</span></div>
        <div class="stat"><b><?= Helpers::e(Helpers::euro((int) $stats['revenue_cents'])) ?></b><span>Τζίρος ημέρας</span></div>
    </div>
        <div class="filters">
            <form class="search" method="GET" action="<?= Helpers::url('/studio') ?>">
                <input type="hidden" name="status" value="<?= Helpers::e($status ?? 'all') ?>">
                <input type="search" name="q" value="<?= Helpers::e($q ?? '') ?>" placeholder="Όνομα, τηλέφωνο ή κωδικός">
                <button class="btn" type="submit">Αναζήτηση</button>
            </form>
            <?php foreach (['all' => 'Όλες', 'new' => 'Νέες', 'printing' => 'Εκτύπωση', 'ready' => 'Έτοιμες', 'delivered' => 'Παραδομένες'] as $key => $label): ?>
                <a class="chip <?= ($status ?? 'all') === $key ? 'on' : '' ?>" href="<?= Helpers::url('/studio?status=' . $key . (($q ?? '') !== '' ? '&q=' . rawurlencode((string) $q) : '')) ?>"><?= Helpers::e($label) ?></a>
            <?php endforeach; ?>
        </div>
    <div class="table-wrap">
        <table class="orders">
            <thead>
                <tr>
                    <th>Κωδικός</th>
                    <th>Πελάτης</th>
                    <th>Κανάλι</th>
                    <th>Κατάσταση</th>
                    <th>Χαρτί</th>
                    <th>Σύνολο</th>
                    <th>Ώρα</th>
                </tr>
            </thead>
            <tbody>
            <?php if (! $orders): ?>
                <tr><td colspan="7" class="muted">Δεν υπάρχουν παραγγελίες ακόμα. Άνοιξε το κιόσκ ή το /web.</td></tr>
            <?php endif; ?>
            <?php foreach ($orders as $order): ?>
                <tr>
                    <td><a href="<?= Helpers::url('/studio/orders/' . $order['id']) ?>"><strong><?= Helpers::e($order['code']) ?></strong></a></td>
                    <td>
                        <?= Helpers::e($order['customer_name']) ?><br>
                        <span class="muted"><?= Helpers::e($order['customer_phone']) ?></span>
                    </td>
                    <td><?= Helpers::e(Helpers::channelLabel($order['channel'])) ?></td>
                    <td><span class="badge badge-<?= Helpers::e($order['status']) ?>"><?= Helpers::e(Helpers::statusLabel($order['status'])) ?></span><?php if (! empty($order['rush'])): ?> <span class="badge badge-new">Επείγον</span><?php endif; ?></td>
                    <td><?= Helpers::e(Helpers::paperLabel((string) ($order['paper'] ?? 'glossy'))) ?></td>
                    <td><?= Helpers::e(Helpers::euro((int) $order['total_cents'])) ?></td>
                    <td><?= Helpers::e(substr((string) $order['created_at'], 0, 16)) ?></td>
                </tr>
            <?php endforeach; ?>
            </tbody>
        </table>
    </div>
</main>
</body>
</html>
