<?php

use Lab\Helpers;

require dirname(__DIR__) . '/partials/head.php';
$storeName = $stores[$order['store_id'] ?? '']['name'] ?? '—';
$lines = [];
foreach ($items as $item) {
    foreach ($item['lines'] as $line) {
        $key = (string) ($line['name'] ?? $line['sku']);
        $lines[$key] = ($lines[$key] ?? 0) + (int) $line['qty'];
    }
}
?>
<main class="ticket">
    <header>
        <strong>Πανόραμα</strong>
        <span>Panorama Lab</span>
    </header>
    <h1><?= Helpers::e($order['code']) ?></h1>
    <p><?= Helpers::e($order['customer_name']) ?><br><?= Helpers::e($order['customer_phone']) ?></p>
    <p>Παραλαβή: <?= Helpers::e($storeName) ?><br>
        <?= ($order['delivery'] ?? '') === 'acs' ? 'ACS' : 'Κατάστημα' ?><br>
        <?= Helpers::e(Helpers::paperLabel((string) ($order['paper'] ?? 'glossy'))) ?>
        · <?= Helpers::e(Helpers::borderLabel((string) ($order['border'] ?? 'none'))) ?>
        · <?= Helpers::e(Helpers::paymentLabel((string) ($order['payment'] ?? 'counter'))) ?>
        <?= ! empty($order['rush']) ? '<br><strong>ΕΠΕΙΓΟΝ</strong>' : '' ?>
    </p>
    <ul>
        <?php foreach ($lines as $name => $qty): ?>
            <li><?= Helpers::e($name) ?> ×<?= (int) $qty ?></li>
        <?php endforeach; ?>
    </ul>
    <p class="total">Σύνολο <?= Helpers::e(Helpers::euro((int) $order['total_cents'])) ?></p>
    <?php if (! empty($order['notes'])): ?>
        <p>Σημ.: <?= Helpers::e($order['notes']) ?></p>
    <?php endif; ?>
    <p class="when"><?= Helpers::e($order['created_at']) ?></p>
</main>
<script>window.print();</script>
</body>
</html>
