<?php $__template->layout('Layout.main'); ?>
<?php $__template->section('title'); ?>لوحة اللاعب — <?= e($player['full_name_ar'] ?? '') ?><?php $__template->endSection(); ?>
<?php $__template->section('page_actions'); ?>
<a href="/parents/<?= $parentId ?>" class="btn btn-outline">العودة لولي الأمر</a>
<a href="/players/<?= (int) $player['id'] ?>" class="btn btn-outline">ملف اللاعب</a>
<?php $__template->endSection(); ?>
<?php $__template->section('content'); ?>

<!-- Player Summary -->
<div class="card" style="padding:20px;margin-bottom:20px;display:flex;align-items:center;gap:20px;">
    <div style="width:60px;height:60px;background:#0D7377;border-radius:50%;display:flex;align-items:center;justify-content:center;color:#fff;font-size:24px;font-weight:700;">
        <?= mb_substr($player['full_name_ar'] ?? '', 0, 1) ?>
    </div>
    <div style="flex:1;">
        <h3 style="margin:0;"><?= e($player['full_name_ar'] ?? '') ?></h3>
        <div style="font-size:13px;color:#6B7280;">
            <?php if (!empty($player['date_of_birth'])): ?>العمر: <?= (int) ((time() - strtotime($player['date_of_birth'])) / 31557600) ?> سنة<?php endif; ?>
            <?php if (!empty($player['card_status'])): ?> | حالة الكارت: <span style="color:<?= $player['card_status'] === 'active' ? '#059669' : '#DC2626' ?>;"><?= $player['card_status'] === 'active' ? 'نشط' : 'موقوف' ?></span><?php endif; ?>
        </div>
    </div>
</div>

<div style="display:grid;grid-template-columns:1fr 1fr;gap:20px;">
    <!-- Groups -->
    <?php if (!empty($groups)): ?>
    <div class="card" style="padding:20px;">
        <h4 style="margin-bottom:12px;">المجموعات الحالية</h4>
        <?php foreach ($groups as $g): ?>
        <div style="padding:8px;background:#F0FDF4;border-radius:6px;margin-bottom:8px;">
            <div style="font-weight:600;"><?= e($g['name_ar'] ?? '') ?></div>
            <div style="font-size:12px;color:#6B7280;"><?= e($g['level_name'] ?? '') ?> | <?= e($g['day_of_week_label'] ?? '') ?> <?= e(substr($g['start_time'] ?? '', 0, 5)) ?>-<?= e(substr($g['end_time'] ?? '', 0, 5)) ?></div>
        </div>
        <?php endforeach; ?>
    </div>
    <?php endif; ?>

    <!-- Recent Attendance -->
    <?php if (!empty($recent_attendance)): ?>
    <div class="card" style="padding:20px;">
        <h4 style="margin-bottom:12px;">آخر الحضور</h4>
        <div style="max-height:250px;overflow-y:auto;">
            <?php foreach (array_slice($recent_attendance, 0, 10) as $a): ?>
            <div style="display:flex;justify-content:space-between;padding:6px 0;border-bottom:1px solid #F3F4F6;font-size:13px;">
                <span><?= e($a['session_date'] ?? '') ?></span>
                <span style="color:<?= ($a['status'] ?? '') === 'present' ? '#059669' : '#DC2626' ?>;">
                    <?= ($a['status'] ?? '') === 'present' ? '● حاضر' : '● غائب' ?>
                </span>
            </div>
            <?php endforeach; ?>
        </div>
    </div>
    <?php endif; ?>

    <!-- Evaluations -->
    <?php if (!empty($evaluations)): ?>
    <div class="card" style="padding:20px;">
        <h4 style="margin-bottom:12px;">التقييمات</h4>
        <?php foreach (array_slice($evaluations, 0, 5) as $ev): ?>
        <div style="padding:10px;background:#F9FAFB;border-radius:6px;margin-bottom:8px;">
            <div style="display:flex;justify-content:space-between;">
                <span style="font-weight:600;"><?= e($ev['evaluation_date'] ?? '') ?></span>
                <span style="background:#EDE9FE;color:#7C3AED;padding:2px 8px;border-radius:10px;font-size:11px;"><?= e($ev['skill_level'] ?? '') ?></span>
            </div>
            <div style="font-size:13px;color:#6B7280;margin-top:4px;">الدرجة: <?= number_format((float) ($ev['overall_score'] ?? 0), 1) ?>/10</div>
            <?php if (!empty($ev['strengths_ar'])): ?><div style="font-size:12px;color:#059669;margin-top:3px;">نقاط القوة: <?= e($ev['strengths_ar']) ?></div><?php endif; ?>
        </div>
        <?php endforeach; ?>
    </div>
    <?php endif; ?>

    <!-- Medical -->
    <?php if (!empty($medical)): ?>
    <div class="card" style="padding:20px;">
        <h4 style="margin-bottom:12px;">الملف الطبي</h4>
        <?php foreach ($medical as $m): ?>
        <div style="padding:8px;border-bottom:1px solid #F3F4F6;font-size:13px;">
            <div style="display:flex;justify-content:space-between;">
                <span>فحص: <?= e($m['exam_date'] ?? '') ?></span>
                <span style="color:<?= strtotime($m['expiry_date'] ?? '') < time() ? '#DC2626' : '#059669' ?>;">
                    انتهاء: <?= e($m['expiry_date'] ?? '') ?>
                </span>
            </div>
            <div style="font-size:12px;color:#6B7280;"><?= e($m['certificate_type'] ?? '') ?> — <?= e($m['approval_status'] ?? '') ?></div>
        </div>
        <?php endforeach; ?>

        <?php if (!empty($injuries)): ?>
        <h5 style="margin-top:15px;color:#DC2626;">إصابات نشطة</h5>
        <?php foreach ($injuries as $inj): ?>
        <div style="padding:8px;background:#FEF2F2;border-radius:6px;margin-top:6px;font-size:13px;">
            <strong><?= e($inj['body_part'] ?? '') ?></strong> — <?= e($inj['description_ar'] ?? '') ?>
            <div style="font-size:11px;color:#6B7280;">منذ: <?= e($inj['occurred_date'] ?? '') ?></div>
        </div>
        <?php endforeach; ?>
        <?php endif; ?>
    </div>
    <?php endif; ?>

    <!-- Achievements -->
    <?php if (!empty($achievements)): ?>
    <div class="card" style="padding:20px;">
        <h4 style="margin-bottom:12px;">الإنجازات</h4>
        <div style="display:flex;flex-wrap:wrap;gap:8px;">
            <?php foreach ($achievements as $ach): ?>
            <div style="background:<?= e($ach['badge_color'] ?? '#FFD700') ?>20;border:1px solid <?= e($ach['badge_color'] ?? '#FFD700') ?>;border-radius:8px;padding:8px 12px;text-align:center;font-size:12px;">
                <div style="font-size:18px;"><?= e($ach['icon'] ?? '🏆') ?></div>
                <div style="font-weight:600;"><?= e($ach['name_ar'] ?? '') ?></div>
            </div>
            <?php endforeach; ?>
        </div>
    </div>
    <?php endif; ?>

    <!-- Subscriptions -->
    <?php if (!empty($subscriptions)): ?>
    <div class="card" style="padding:20px;">
        <h4 style="margin-bottom:12px;">الاشتراكات</h4>
        <?php foreach ($subscriptions as $sub): ?>
        <div style="display:flex;justify-content:space-between;padding:6px 0;border-bottom:1px solid #F3F4F6;font-size:13px;">
            <span><?= e($sub['subscription_month'] ?? '') ?></span>
            <span style="font-weight:600;color:<?= ($sub['status'] ?? '') === 'paid' ? '#059669' : '#DC2626' ?>;">
                <?= ($sub['status'] ?? '') === 'paid' ? 'مدفوع' : (($sub['status'] ?? '') === 'overdue' ? 'متأخر' : 'معلق') ?>
            </span>
        </div>
        <?php endforeach; ?>
    </div>
    <?php endif; ?>
</div>
<?php $__template->endSection(); ?>
