<?php $__template->layout('Layout.main'); ?>
<?php $__template->section('title'); ?>تقرير التحويلات<?php $__template->endSection(); ?>
<?php $__template->section('content'); ?>

<div class="card" style="margin-bottom:20px;padding:15px;">
    <form method="GET" action="/reports/transfers" style="display:flex;gap:10px;flex-wrap:wrap;align-items:end;">
        <div>
            <label class="form-label" style="font-size:12px;">من تاريخ</label>
            <input type="date" name="date_from" value="<?= e($dateFrom) ?>" class="form-input">
        </div>
        <div>
            <label class="form-label" style="font-size:12px;">إلى تاريخ</label>
            <input type="date" name="date_to" value="<?= e($dateTo) ?>" class="form-input">
        </div>
        <div>
            <label class="form-label" style="font-size:12px;">النوع</label>
            <select name="type" class="form-select" style="min-width:140px;">
                <option value="">الكل</option>
                <option value="separation" <?= $type === 'separation' ? 'selected' : '' ?>>انفصال</option>
                <option value="divorce" <?= $type === 'divorce' ? 'selected' : '' ?>>طلاق</option>
                <option value="death" <?= $type === 'death' ? 'selected' : '' ?>>وفاة</option>
            </select>
        </div>
        <button type="submit" class="btn btn-outline">تصفية</button>
        <a href="/reports/transfers" class="btn btn-sm btn-outline" style="color:#6B7280;">مسح</a>
    </form>
</div>

<div class="card">
    <div style="padding:15px;border-bottom:1px solid #E5E7EB;">
        <strong>النتائج:</strong> <?= count($transfers) ?> عملية تحويل مكتملة
    </div>
    <div class="table-responsive">
        <table class="data-table">
            <thead>
                <tr>
                    <th>تاريخ الإتمام</th>
                    <th>النوع</th>
                    <th>المصدر</th>
                    <th>الرقم القديم</th>
                    <th>المستفيد</th>
                    <th>الرقم الجديد</th>
                </tr>
            </thead>
            <tbody>
            <?php if (empty($transfers)): ?>
                <tr><td colspan="6" style="text-align:center;padding:30px;color:#6B7280;">لا توجد نتائج</td></tr>
            <?php else: ?>
                <?php foreach ($transfers as $t): ?>
                <tr>
                    <td><?= e($t['completed_at'] ?? '—') ?></td>
                    <td>
                        <?= match($t['transfer_type'] ?? '') {
                            'separation' => 'انفصال',
                            'divorce'    => 'طلاق',
                            'death'      => 'وفاة',
                            default      => e($t['transfer_type'] ?? '—'),
                        } ?>
                    </td>
                    <td><?= e($t['source_name'] ?? '—') ?></td>
                    <td><?= e($t['old_number'] ?? '—') ?></td>
                    <td><?= e($t['target_name'] ?? '—') ?></td>
                    <td><?= e($t['new_membership_number'] ?? '—') ?></td>
                </tr>
                <?php endforeach; ?>
            <?php endif; ?>
            </tbody>
        </table>
    </div>
</div>

<?php $__template->endSection(); ?>
