<?php $__template->layout('Layout.main'); ?>
<?php $__template->section('title'); ?>المقابلات<?php $__template->endSection(); ?>
<?php $__template->section('page_actions'); ?>
<div style="padding:8px 16px;background:#EFF6FF;border:1px solid #BFDBFE;border-radius:6px;font-size:13px;color:#0284C7;">
    💡 لتحديد مقابلة جديدة، اذهب لصفحة العضو واختر "🗓️ تحديد مقابلة"
</div>
<?php $__template->endSection(); ?>
<?php $__template->section('content'); ?>
<div class="card" style="margin-bottom:20px;padding:15px;">
    <form method="GET" action="/interviews" 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>
            <select name="decision" class="form-select"><option value="">الكل</option><option value="pending" <?= ($filters['decision'] ?? '') === 'pending' ? 'selected' : '' ?>>في الانتظار</option><option value="accepted" <?= ($filters['decision'] ?? '') === 'accepted' ? 'selected' : '' ?>>مقبول</option><option value="rejected" <?= ($filters['decision'] ?? '') === 'rejected' ? 'selected' : '' ?>>مرفوض</option></select></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>
        <a href="/interviews" class="btn btn-sm btn-outline" style="color:#6B7280;">مسح</a>
    </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><th>الإجراءات</th></tr></thead><tbody>
<?php foreach ($rows as $r): ?>
<tr style="<?= $r['decision'] === 'pending' && $r['scheduled_date'] < date('Y-m-d') ? 'background:#FEF2F2;' : '' ?>">
    <td style="font-weight:600;white-space:nowrap;"><?= e($r['scheduled_date']) ?></td>
    <td style="font-size:13px;"><?= e($r['scheduled_time'] ?? '—') ?></td>
    <td><a href="/members/<?= (int) $r['member_id'] ?>" style="color:#0D7377;font-weight:600;"><?= e($r['member_name']) ?></a><br><small style="color:#9CA3AF;"><?= e($r['membership_number'] ?? 'بدون رقم') ?></small></td>
    <td style="direction:ltr;text-align:right;font-size:13px;"><?= e($r['phone_mobile'] ?? '—') ?></td>
    <td style="font-size:13px;"><?= e($r['location'] ?? '—') ?></td>
    <td style="text-align:center;"><?= (int) $r['reschedule_count'] ?></td>
    <td>
        <?php
        $decColor = match($r['decision']) { 'accepted' => '#059669', 'rejected' => '#DC2626', default => '#D97706' };
        $decLabel = \App\Modules\Interviews\Models\Interview::getDecisionLabel($r['decision']);
        ?>
        <span style="color:<?= $decColor ?>;font-weight:600;">● <?= e($decLabel) ?></span>
    </td>
    <td>
        <div style="display:flex;gap:5px;flex-wrap:wrap;">
        <?php if ($r['decision'] === 'pending'): ?>
            <a href="/interviews/<?= (int) $r['id'] ?>/decide" class="btn btn-sm btn-primary">البت</a>
            <form method="POST" action="/interviews/<?= (int) $r['id'] ?>/reschedule" style="display:flex;gap:3px;">
                <?= csrf_field() ?>
                <input type="date" name="scheduled_date" class="form-input" style="width:120px;font-size:11px;padding:3px 6px;" required min="<?= e(date('Y-m-d')) ?>">
                <input type="hidden" name="reschedule_reason" value="إعادة جدولة">
                <button type="submit" class="btn btn-sm btn-outline" style="font-size:11px;">تأجيل</button>
            </form>
        <?php else: ?>
            <a href="/interviews/<?= (int) $r['id'] ?>/decide" class="btn btn-sm btn-outline">عرض</a>
        <?php endif; ?>
        </div>
    </td>
</tr>
<?php endforeach; ?>
<?php if (empty($rows)): ?><tr><td colspan="8" style="text-align:center;padding:40px;color:#6B7280;">لا توجد مقابلات</td></tr><?php endif; ?>
</tbody></table></div></div>
<?php $__template->endSection(); ?>