<?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>
        <a href="/cashier/deposits/create" class="btn btn-primary" style="font-size:13px;">إيداع جديد</a>
    </div>

    <!-- Filters -->
    <div style="padding:10px 20px;border-bottom:1px solid #F3F4F6;">
        <form method="GET" action="/cashier/deposits" style="display:flex;gap:10px;align-items:center;">
            <select name="status" class="form-select" style="width:auto;">
                <option value="">الكل</option>
                <option value="deposited" <?= ($filters['status'] ?? '') === 'deposited' ? 'selected' : '' ?>>في انتظار التأكيد</option>
                <option value="confirmed" <?= ($filters['status'] ?? '') === 'confirmed' ? 'selected' : '' ?>>مؤكد</option>
                <option value="rejected" <?= ($filters['status'] ?? '') === 'rejected' ? 'selected' : '' ?>>مرفوض</option>
            </select>
            <button type="submit" class="btn btn-outline" style="font-size:12px;">تصفية</button>
        </form>
    </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>
                    <th></th>
                </tr>
            </thead>
            <tbody>
                <?php if (empty($deposits)): ?>
                    <tr><td colspan="8" style="text-align:center;padding:40px;color:#9CA3AF;">لا توجد إيداعات</td></tr>
                <?php else: ?>
                    <?php foreach ($deposits as $d):
                        $statusColor = match($d['status']) {
                            'pending_deposit' => '#9CA3AF',
                            'deposited'       => '#F59E0B',
                            'confirmed'       => '#059669',
                            'rejected'        => '#DC2626',
                            default           => '#6B7280',
                        };
                        $statusLabel = match($d['status']) {
                            'pending_deposit' => 'لم يُودع',
                            'deposited'       => 'في انتظار التأكيد',
                            'confirmed'       => 'مؤكد',
                            'rejected'        => 'مرفوض',
                            default           => $d['status'],
                        };
                    ?>
                    <tr>
                        <td>
                            <a href="/cashier/deposits/<?= (int) $d['id'] ?>" style="font-family:monospace;font-size:12px;color:#3B82F6;">
                                <?= e($d['deposit_number']) ?>
                            </a>
                        </td>
                        <td style="font-size:12px;"><?= e($d['bank_name'] ?? '—') ?></td>
                        <td style="font-weight:600;"><?= money($d['amount']) ?></td>
                        <td style="font-size:12px;"><?= e($d['deposit_date']) ?></td>
                        <td style="font-family:monospace;font-size:12px;"><?= e($d['bank_receipt_serial'] ?? '—') ?></td>
                        <td style="font-size:12px;"><?= e($d['deposited_by_name'] ?? '—') ?></td>
                        <td><span style="color:<?= $statusColor ?>;font-weight:600;font-size:12px;"><?= e($statusLabel) ?></span></td>
                        <td>
                            <?php if ($d['status'] === 'deposited'): ?>
                                <a href="/cashier/deposits/<?= (int) $d['id'] ?>" class="btn btn-outline" style="font-size:11px;padding:3px 8px;">تفاصيل</a>
                            <?php endif; ?>
                        </td>
                    </tr>
                    <?php endforeach; ?>
                <?php endif; ?>
            </tbody>
        </table>
    </div>
</div>
<?php $__template->endSection(); ?>
