<?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="/violations" style="display:flex;gap:10px;align-items:end;">
        <div><label class="form-label" style="font-size:12px;">بحث</label><input type="text" name="q" value="<?= e($filters['search'] ?? '') ?>" class="form-input" style="min-width:200px;"></div>
        <div><label class="form-label" style="font-size:12px;">الحالة</label><select name="status" class="form-select"><option value="">الكل</option><option value="reported" <?= ($filters['status'] ?? '') === 'reported' ? 'selected' : '' ?>>مُبلّغ</option><option value="penalty_imposed" <?= ($filters['status'] ?? '') === 'penalty_imposed' ? 'selected' : '' ?>>تم فرض عقوبة</option></select></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></tr></thead><tbody>
<?php foreach ($rows as $r): ?>
<tr>
    <td style="font-size:13px;"><?= e($r['violation_date']) ?></td>
    <td><a href="/members/<?= (int) $r['member_id'] ?>" style="color:#0D7377;font-weight:600;"><?= e($r['member_name'] ?? '') ?></a></td>
    <td style="font-size:13px;max-width:300px;overflow:hidden;text-overflow:ellipsis;"><?= e(mb_substr($r['description'], 0, 100)) ?></td>
    <td style="font-size:13px;"><?= e($r['reported_by_name'] ?? '—') ?></td>
    <td><span style="color:<?= $r['status'] === 'reported' ? '#D97706' : '#059669' ?>;font-weight:600;">● <?= $r['status'] === 'reported' ? 'مُبلّغ' : 'تم فرض عقوبة' ?></span></td>
    <td>
        <?php if ($r['status'] === 'reported'): ?>
        <form method="POST" action="/fines/impose/<?= (int) $r['id'] ?>" style="display:flex;gap:5px;align-items:center;">
            <?= csrf_field() ?>
            <select name="penalty_type" class="form-select" style="width:auto;font-size:12px;" required><option value="">عقوبة</option><option value="warning">لفت نظر</option><option value="caution">إنذار</option><option value="fine">غرامة</option><option value="suspension">إيقاف</option><option value="ban">منع دخول</option><option value="termination">إنهاء عضوية</option></select>
            <input type="number" name="amount" placeholder="المبلغ" class="form-input" style="width:80px;font-size:12px;" step="0.01">
            <button type="submit" class="btn btn-sm" style="background:#DC2626;color:#fff;border:none;padding:5px 10px;border-radius:4px;cursor:pointer;">فرض</button>
        </form>
        <?php else: ?>—<?php endif; ?>
    </td>
</tr>
<?php endforeach; ?>
<?php if (empty($rows)): ?><tr><td colspan="6" style="text-align:center;padding:40px;color:#6B7280;">لا توجد مخالفات</td></tr><?php endif; ?>
</tbody></table></div></div>
<?php $__template->endSection(); ?>