<?php $__template->layout('Layout.main'); ?>
<?php $__template->section('title'); ?><?= e($title ?? 'الإيصالات') ?><?php $__template->endSection(); ?>
<?php $__template->section('content'); ?>

<div class="card" style="margin-bottom:20px;padding:15px;">
    <form method="GET" action="<?= !empty($showVoided) ? '/receipts/voided' : '/receipts' ?>" style="display:flex;gap:10px;flex-wrap:wrap;align-items:end;">
        <div><label class="form-label" style="font-size:12px;">بحث</label><input type="text" name="q" value="<?= e($filters['search'] ?? '') ?>" placeholder="رقم إيصال، اسم عضو..." class="form-input" style="min-width:200px;"></div>
        <div><label class="form-label" style="font-size:12px;">من</label><input type="date" name="date_from" value="<?= e($filters['date_from'] ?? '') ?>" class="form-input"></div>
        <div><label class="form-label" style="font-size:12px;">إلى</label><input type="date" name="date_to" value="<?= e($filters['date_to'] ?? '') ?>" class="form-input"></div>
        <button type="submit" class="btn btn-outline">بحث</button>
    </form>
</div>

<div class="card">
    <div class="table-responsive">
        <table class="data-table">
            <thead><tr><th>رقم الإيصال</th><th>العضو</th><th>المبلغ</th><th>التاريخ</th><th>بواسطة</th><th>الحالة</th><th>الإجراءات</th></tr></thead>
            <tbody>
                <?php foreach ($rows as $r): ?>
                <tr style="<?= $r['is_voided'] ? 'opacity:0.6;' : '' ?>">
                    <td style="font-weight:600;direction:ltr;text-align:right;"><?= e($r['receipt_number']) ?></td>
                    <td><a href="/members/<?= (int) $r['member_id'] ?>" style="color:#0D7377;"><?= e($r['member_name']) ?></a></td>
                    <td style="font-weight:700;direction:ltr;text-align:right;"><?= money($r['amount']) ?></td>
                    <td style="font-size:12px;"><?= e(substr($r['issued_at'], 0, 10)) ?></td>
                    <td style="font-size:13px;"><?= e($r['issued_by_name'] ?? '—') ?></td>
                    <td><?php if ($r['is_voided']): ?><span style="color:#DC2626;font-weight:600;">ملغى</span><?php else: ?><span style="color:#059669;font-weight:600;">ساري</span><?php endif; ?></td>
                    <td>
                        <div style="display:flex;gap:5px;">
                            <?php if (!$r['is_voided']): ?>
                            <a href="/receipts/<?= (int) $r['id'] ?>/print" class="btn btn-sm btn-outline" target="_blank">طباعة</a>
                            <?php endif; ?>
                        </div>
                    </td>
                </tr>
                <?php endforeach; ?>
                <?php if (empty($rows)): ?><tr><td colspan="7" style="text-align:center;padding:40px;color:#6B7280;">لا توجد إيصالات</td></tr><?php endif; ?>
            </tbody>
        </table>
    </div>
</div>
<?php $__template->endSection(); ?>