<?php $__template->layout('Layout.main'); ?>
<?php $__template->section('title'); ?>طلبات نقل المجموعات<?php $__template->endSection(); ?>
<?php $__template->section('page_actions'); ?>
<a href="/training-groups" class="btn btn-outline">المجموعات</a>
<a href="/transfer-requests/create" class="btn btn-primary">طلب نقل جديد</a>
<?php $__template->endSection(); ?>
<?php $__template->section('content'); ?>

<!-- Filter Tabs -->
<div class="card" style="margin-bottom:20px;padding:0;">
    <div style="display:flex;gap:0;border-bottom:2px solid #E5E7EB;">
        <?php foreach (['pending' => 'معلقة', 'approved' => 'مقبولة', 'rejected' => 'مرفوضة', 'waitlisted' => 'قائمة انتظار', 'all' => 'الكل'] as $key => $label): ?>
        <a href="/transfer-requests?status=<?= $key ?>" style="padding:12px 20px;font-size:14px;font-weight:600;text-decoration:none;border-bottom:3px solid <?= $status === $key ? '#0D7377' : 'transparent' ?>;color:<?= $status === $key ? '#0D7377' : '#6B7280' ?>;">
            <?= $label ?>
        </a>
        <?php endforeach; ?>
    </div>
</div>

<div class="card" style="padding:20px;">
    <?php if (empty($requests)): ?>
    <p style="color:#6B7280;text-align:center;padding:30px;">لا توجد طلبات</p>
    <?php else: ?>
    <?php foreach ($requests as $req): ?>
    <div style="padding:15px;border:1px solid #E5E7EB;border-radius:8px;margin-bottom:12px;">
        <div style="display:flex;justify-content:space-between;align-items:start;">
            <div>
                <span style="font-weight:700;"><?= e($req['player_name'] ?? '') ?></span>
                <div style="font-size:13px;color:#6B7280;margin-top:4px;">
                    من: <strong><?= e($req['from_group_name'] ?? '') ?></strong>
                    <?php if ($req['to_group_name']): ?>→ إلى: <strong><?= e($req['to_group_name']) ?></strong><?php else: ?>→ <span style="color:#DC2626;">مغادرة</span><?php endif; ?>
                </div>
            </div>
            <div>
                <?php if ($req['status'] === 'pending'): ?>
                <span style="background:#FEF3C7;color:#D97706;padding:3px 10px;border-radius:12px;font-size:11px;">معلق</span>
                <?php elseif ($req['status'] === 'approved'): ?>
                <span style="background:#D1FAE5;color:#059669;padding:3px 10px;border-radius:12px;font-size:11px;">مقبول</span>
                <?php elseif ($req['status'] === 'waitlisted'): ?>
                <span style="background:#DBEAFE;color:#1D4ED8;padding:3px 10px;border-radius:12px;font-size:11px;">قائمة انتظار</span>
                <?php else: ?>
                <span style="background:#FEE2E2;color:#DC2626;padding:3px 10px;border-radius:12px;font-size:11px;">مرفوض</span>
                <?php endif; ?>
            </div>
        </div>
        <?php if (!empty($req['reason_ar'])): ?>
        <div style="font-size:13px;color:#4B5563;margin-top:8px;">السبب: <?= e($req['reason_ar']) ?></div>
        <?php endif; ?>
        <?php if ($req['status'] === 'pending'): ?>
        <div style="margin-top:10px;display:flex;gap:8px;">
            <form method="POST" action="/transfer-requests/<?= (int) $req['id'] ?>/approve" style="display:inline;"><?= csrf_field() ?><button type="submit" class="btn btn-sm btn-primary">قبول</button></form>
            <form method="POST" action="/transfer-requests/<?= (int) $req['id'] ?>/reject" style="display:inline-flex;gap:5px;">
                <?= csrf_field() ?>
                <input type="text" name="notes" placeholder="سبب الرفض..." style="font-size:12px;padding:4px 8px;border:1px solid #D1D5DB;border-radius:4px;width:150px;">
                <button type="submit" class="btn btn-sm btn-outline" style="color:#DC2626;">رفض</button>
            </form>
        </div>
        <?php endif; ?>
        <?php if (!empty($req['review_notes'])): ?>
        <div style="font-size:12px;color:#6B7280;margin-top:6px;font-style:italic;">ملاحظة: <?= e($req['review_notes']) ?></div>
        <?php endif; ?>
    </div>
    <?php endforeach; ?>
    <?php endif; ?>
</div>
<?php $__template->endSection(); ?>
