<?php
$__template->layout('Layout.main');
?>
<?php $__template->section('title'); ?>بيانات اللاعب: <?= e($player['full_name_ar'] ?? '') ?><?php $__template->endSection(); ?>

<?php $__template->section('page_actions'); ?>
<a href="/sa/players/<?= (int) $player['id'] ?>/edit" class="btn btn-primary"><i data-lucide="edit-3" style="width:16px;height:16px;vertical-align:middle;margin-left:4px;"></i> تعديل</a>
<a href="/sa/players/<?= (int) $player['id'] ?>/documents" class="btn btn-outline"><i data-lucide="file-text" style="width:16px;height:16px;vertical-align:middle;margin-left:4px;"></i> المستندات</a>
<a href="/sa/players" class="btn btn-outline"><i data-lucide="arrow-right" style="width:16px;height:16px;vertical-align:middle;margin-left:4px;"></i> رجوع</a>
<?php $__template->endSection(); ?>

<?php $__template->section('content'); ?>

<?php
$typeLabels = ['member' => 'عضو', 'non_member' => 'غير عضو'];
$medLabels = ['fit' => 'لائق', 'unfit' => 'غير لائق', 'pending' => 'في الانتظار', 'expired' => 'منتهي', 'conditional' => 'مشروط'];
$medColors = ['fit' => '#059669', 'unfit' => '#DC2626', 'pending' => '#D97706', 'expired' => '#6B7280', 'conditional' => '#F59E0B'];
$cardLabels = ['inactive' => 'غير مفعلة', 'active' => 'فعالة', 'suspended' => 'موقوفة', 'revoked' => 'ملغاة'];
$genderLabels = ['male' => 'ذكر', 'female' => 'أنثى'];
$relationLabels = ['father' => 'أب', 'mother' => 'أم', 'brother' => 'أخ', 'sister' => 'أخت', 'uncle' => 'عم / خال', 'other' => 'أخرى'];
?>

<!-- Player Info Card -->
<div class="card" style="margin-bottom:20px;">
    <div style="padding:20px;display:flex;align-items:center;gap:20px;border-bottom:1px solid #E5E7EB;">
        <div style="width:64px;height:64px;border-radius:50%;background:linear-gradient(135deg, #0D737715, #0D737730);display:flex;align-items:center;justify-content:center;">
            <i data-lucide="user" style="width:32px;height:32px;color:#0D7377;"></i>
        </div>
        <div>
            <h2 style="margin:0 0 4px;font-size:20px;font-weight:700;"><?= e($player['full_name_ar'] ?? '') ?></h2>
            <?php if (!empty($player['full_name_en'])): ?>
            <div style="font-size:13px;color:#6B7280;margin-bottom:4px;" dir="ltr"><?= e($player['full_name_en']) ?></div>
            <?php endif; ?>
            <div style="display:flex;gap:8px;flex-wrap:wrap;">
                <code style="font-size:11px;background:#F3F4F6;padding:2px 8px;border-radius:4px;"><?= e($player['registration_serial'] ?? '') ?></code>
                <?php $mStatus = $player['medical_status'] ?? 'pending'; $mColor = $medColors[$mStatus] ?? '#6B7280'; ?>
                <span style="padding:2px 10px;border-radius:10px;font-size:11px;font-weight:600;background:<?= $mColor ?>15;color:<?= $mColor ?>;"><?= e($medLabels[$mStatus] ?? $mStatus) ?></span>
            </div>
        </div>
    </div>

    <div style="padding:20px;display:grid;grid-template-columns:repeat(auto-fit, minmax(220px, 1fr));gap:20px;">
        <div>
            <div style="font-size:12px;color:#9CA3AF;margin-bottom:4px;">نوع اللاعب</div>
            <div style="font-size:14px;font-weight:600;"><?= e($typeLabels[$player['player_type'] ?? ''] ?? '-') ?></div>
        </div>
        <div>
            <div style="font-size:12px;color:#9CA3AF;margin-bottom:4px;">الرقم القومي</div>
            <div style="font-size:14px;font-weight:600;" dir="ltr"><?= e($player['national_id'] ?? '-') ?></div>
        </div>
        <div>
            <div style="font-size:12px;color:#9CA3AF;margin-bottom:4px;">تاريخ الميلاد</div>
            <div style="font-size:14px;font-weight:600;"><?= e($player['date_of_birth'] ?? '-') ?></div>
        </div>
        <div>
            <div style="font-size:12px;color:#9CA3AF;margin-bottom:4px;">النوع</div>
            <div style="font-size:14px;font-weight:600;"><?= e($genderLabels[$player['gender'] ?? ''] ?? '-') ?></div>
        </div>
        <div>
            <div style="font-size:12px;color:#9CA3AF;margin-bottom:4px;">الهاتف</div>
            <div style="font-size:14px;font-weight:600;" dir="ltr"><?= e($player['phone'] ?? '-') ?></div>
        </div>
        <div>
            <div style="font-size:12px;color:#9CA3AF;margin-bottom:4px;">البريد الإلكتروني</div>
            <div style="font-size:14px;font-weight:600;" dir="ltr"><?= e($player['email'] ?? '-') ?></div>
        </div>
        <div>
            <div style="font-size:12px;color:#9CA3AF;margin-bottom:4px;">حالة البطاقة</div>
            <div style="font-size:14px;font-weight:600;"><?= e($cardLabels[$player['card_status'] ?? ''] ?? '-') ?></div>
        </div>
        <div>
            <div style="font-size:12px;color:#9CA3AF;margin-bottom:4px;">انتهاء الكشف الطبي</div>
            <div style="font-size:14px;font-weight:600;"><?= e($player['medical_expiry_date'] ?? '-') ?></div>
        </div>
        <?php if (!empty($player['member_id'])): ?>
        <div>
            <div style="font-size:12px;color:#9CA3AF;margin-bottom:4px;">رقم العضوية</div>
            <div style="font-size:14px;font-weight:600;"><?= (int) $player['member_id'] ?></div>
        </div>
        <?php endif; ?>
    </div>
</div>

<!-- Guardian Info -->
<?php if (!empty($player['guardian_name'])): ?>
<div class="card" style="margin-bottom:20px;">
    <div style="padding:15px 20px;border-bottom:1px solid #E5E7EB;">
        <h3 style="margin:0;font-size:16px;font-weight:600;">بيانات ولي الأمر</h3>
    </div>
    <div style="padding:20px;display:grid;grid-template-columns:repeat(auto-fit, minmax(220px, 1fr));gap:20px;">
        <div>
            <div style="font-size:12px;color:#9CA3AF;margin-bottom:4px;">الاسم</div>
            <div style="font-size:14px;font-weight:600;"><?= e($player['guardian_name'] ?? '-') ?></div>
        </div>
        <div>
            <div style="font-size:12px;color:#9CA3AF;margin-bottom:4px;">الهاتف</div>
            <div style="font-size:14px;font-weight:600;" dir="ltr"><?= e($player['guardian_phone'] ?? '-') ?></div>
        </div>
        <div>
            <div style="font-size:12px;color:#9CA3AF;margin-bottom:4px;">الرقم القومي</div>
            <div style="font-size:14px;font-weight:600;" dir="ltr"><?= e($player['guardian_national_id'] ?? '-') ?></div>
        </div>
        <div>
            <div style="font-size:12px;color:#9CA3AF;margin-bottom:4px;">صلة القرابة</div>
            <div style="font-size:14px;font-weight:600;"><?= e($relationLabels[$player['guardian_relationship'] ?? ''] ?? '-') ?></div>
        </div>
    </div>
</div>
<?php endif; ?>

<!-- Notes -->
<?php if (!empty($player['notes'])): ?>
<div class="card" style="margin-bottom:20px;">
    <div style="padding:15px 20px;border-bottom:1px solid #E5E7EB;">
        <h3 style="margin:0;font-size:16px;font-weight:600;">ملاحظات</h3>
    </div>
    <div style="padding:20px;font-size:14px;line-height:1.8;color:#374151;">
        <?= nl2br(e($player['notes'])) ?>
    </div>
</div>
<?php endif; ?>

<!-- Documents Section -->
<div class="card">
    <div style="padding:15px 20px;border-bottom:1px solid #E5E7EB;display:flex;justify-content:space-between;align-items:center;">
        <h3 style="margin:0;font-size:16px;font-weight:600;">المستندات</h3>
        <a href="/sa/players/<?= (int) $player['id'] ?>/documents" class="btn btn-sm btn-primary">
            <i data-lucide="upload" style="width:14px;height:14px;vertical-align:middle;margin-left:4px;"></i> إدارة المستندات
        </a>
    </div>
    <?php if (!empty($documents)): ?>
    <div class="table-responsive">
        <table class="data-table">
            <thead>
                <tr>
                    <th>العنوان</th>
                    <th>النوع</th>
                    <th>الحالة</th>
                    <th>تاريخ الرفع</th>
                </tr>
            </thead>
            <tbody>
                <?php foreach ($documents as $doc): ?>
                <tr>
                    <td><?= e($doc['file_name'] ?? '') ?></td>
                    <td>
                        <?php
                        $docTypes = ['medical_cert' => 'شهادة طبية', 'national_id' => 'صورة بطاقة', 'photo' => 'صورة شخصية', 'birth_cert' => 'شهادة ميلاد'];
                        ?>
                        <?= e($docTypes[$doc['document_type'] ?? ''] ?? $doc['document_type'] ?? '') ?>
                    </td>
                    <td>
                        <?php
                        $approvalLabels = ['pending' => 'في الانتظار', 'approved' => 'معتمد', 'rejected' => 'مرفوض'];
                        $approvalColors = ['pending' => '#D97706', 'approved' => '#059669', 'rejected' => '#DC2626'];
                        $aStatus = $doc['approval_status'] ?? 'pending';
                        $aColor = $approvalColors[$aStatus] ?? '#6B7280';
                        ?>
                        <span style="padding:2px 8px;border-radius:8px;font-size:11px;font-weight:600;background:<?= $aColor ?>15;color:<?= $aColor ?>;">
                            <?= e($approvalLabels[$aStatus] ?? $aStatus) ?>
                        </span>
                    </td>
                    <td style="font-size:13px;"><?= e($doc['created_at'] ?? '') ?></td>
                </tr>
                <?php endforeach; ?>
            </tbody>
        </table>
    </div>
    <?php else: ?>
    <div style="padding:40px 20px;text-align:center;color:#9CA3AF;">
        لا توجد مستندات مرفوعة بعد.
    </div>
    <?php endif; ?>
</div>

<script>
document.addEventListener('DOMContentLoaded', function() {
    if (typeof lucide !== 'undefined') lucide.createIcons();
});
</script>
<?php $__template->endSection(); ?>
