<?php $__template->layout('Layout.main'); ?>

<?php $__template->section('title'); ?>الورديات — الخزنة الفرعية<?php $__template->endSection(); ?>

<?php $__template->section('content'); ?>
<div class="card">
    <div style="padding:15px 20px;border-bottom:1px solid #E5E7EB;display:flex;justify-content:space-between;align-items:center;">
        <span style="font-weight:600;">سجل الورديات</span>
    </div>
    <div class="table-responsive">
        <table class="data-table" style="width:100%;">
            <thead>
                <tr>
                    <th>رقم الوردية</th>
                    <th>الصراف</th>
                    <th>فتح</th>
                    <th>إغلاق</th>
                    <th>الإجمالي</th>
                    <th>الإيصالات</th>
                    <th>الحالة</th>
                </tr>
            </thead>
            <tbody>
                <?php if (empty($sessions)): ?>
                    <tr><td colspan="7" style="text-align:center;padding:40px;color:#9CA3AF;">لا توجد ورديات</td></tr>
                <?php else: ?>
                    <?php foreach ($sessions as $s):
                        $statusColor = match($s['status']) {
                            'open'    => '#059669',
                            'closed'  => '#F59E0B',
                            'settled' => '#3B82F6',
                            default   => '#6B7280',
                        };
                        $statusLabel = match($s['status']) {
                            'open'    => 'مفتوحة',
                            'closed'  => 'مغلقة',
                            'settled' => 'تمت التسوية',
                            default   => $s['status'],
                        };
                    ?>
                    <tr>
                        <td style="font-family:monospace;font-size:12px;"><?= e($s['session_number']) ?></td>
                        <td><?= e($s['cashier_name'] ?? '—') ?></td>
                        <td style="font-size:12px;"><?= e($s['opened_at']) ?></td>
                        <td style="font-size:12px;"><?= e($s['closed_at'] ?? '—') ?></td>
                        <td style="font-weight:600;"><?= money($s['total_collected'] ?? '0.00') ?></td>
                        <td><?= (int) $s['total_receipts'] ?></td>
                        <td><span style="color:<?= $statusColor ?>;font-weight:600;font-size:12px;"><?= e($statusLabel) ?></span></td>
                    </tr>
                    <?php endforeach; ?>
                <?php endif; ?>
            </tbody>
        </table>
    </div>
</div>
<?php $__template->endSection(); ?>
