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

<?php $__template->section('page_actions'); ?>
<a href="/players/<?= (int) $player->id ?>" class="btn btn-outline"><i data-lucide="arrow-right" style="width:15px;height:15px;vertical-align:middle;margin-left:4px;"></i> العودة للملف</a>
<?php $__template->endSection(); ?>

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

<form method="POST" action="/players/<?= (int) $player->id ?>" id="playerEditForm">
    <?= csrf_field() ?>

    <!-- Section 1: Basic Data -->
    <div class="card" style="margin-bottom:20px;">
        <div style="padding:15px 20px;border-bottom:1px solid #E5E7EB;display:flex;align-items:center;gap:8px;">
            <i data-lucide="user" style="width:18px;height:18px;color:#0D7377;"></i>
            <h3 style="margin:0;color:#0D7377;font-size:15px;">البيانات الأساسية</h3>
        </div>
        <div style="padding:20px;">
            <div style="display:grid;grid-template-columns:1fr 1fr;gap:20px;">
                <div class="form-group">
                    <label class="form-label">نوع اللاعب</label>
                    <select name="player_type" class="form-input" disabled style="background:#F3F4F6;cursor:not-allowed;">
                        <?php foreach ($playerTypes as $key => $label): ?>
                        <option value="<?= e($key) ?>" <?= ($player->player_type ?? '') === $key ? 'selected' : '' ?>><?= e($label) ?></option>
                        <?php endforeach; ?>
                    </select>
                    <input type="hidden" name="player_type" value="<?= e($player->player_type ?? '') ?>">
                    <small style="color:#9CA3AF;font-size:11px;">لا يمكن تغيير نوع اللاعب بعد التسجيل</small>
                </div>
                <?php if (($player->player_type ?? '') === 'member'): ?>
                <div class="form-group">
                    <label class="form-label">رقم العضوية</label>
                    <input type="number" name="member_id" value="<?= e(old('member_id') ?: ($player->member_id ?? '')) ?>" class="form-input" min="1" style="direction:ltr;text-align:left;" placeholder="رقم العضوية في النادي">
                </div>
                <?php endif; ?>
                <div class="form-group" style="grid-column:1/-1;">
                    <label class="form-label">الاسم بالكامل (عربي) <span style="color:#DC2626;">*</span></label>
                    <input type="text" name="full_name_ar" value="<?= e(old('full_name_ar') ?: ($player->full_name_ar ?? '')) ?>" class="form-input" required placeholder="الاسم رباعي بالعربي" style="font-size:16px;">
                </div>
                <div class="form-group" style="grid-column:1/-1;">
                    <label class="form-label">الاسم بالكامل (إنجليزي)</label>
                    <input type="text" name="full_name_en" value="<?= e(old('full_name_en') ?: ($player->full_name_en ?? '')) ?>" class="form-input" placeholder="Full name in English" style="direction:ltr;text-align:left;">
                </div>
                <div class="form-group">
                    <label class="form-label">الرقم القومي <span style="color:#DC2626;">*</span></label>
                    <input type="text" name="national_id" value="<?= e(old('national_id') ?: ($player->national_id ?? '')) ?>" class="form-input" maxlength="14" style="direction:ltr;text-align:left;font-size:16px;letter-spacing:1px;" placeholder="أدخل 14 رقم">
                </div>
                <div class="form-group">
                    <label class="form-label">رقم جواز السفر</label>
                    <input type="text" name="passport_number" value="<?= e(old('passport_number') ?: ($player->passport_number ?? '')) ?>" class="form-input" style="direction:ltr;text-align:left;" placeholder="رقم جواز السفر (اختياري)">
                </div>
                <div class="form-group">
                    <label class="form-label">تاريخ الميلاد <span style="color:#DC2626;">*</span></label>
                    <input type="date" name="date_of_birth" value="<?= e(old('date_of_birth') ?: ($player->date_of_birth ?? '')) ?>" class="form-input" required>
                </div>
                <div class="form-group">
                    <label class="form-label">النوع <span style="color:#DC2626;">*</span></label>
                    <select name="gender" class="form-input" required>
                        <option value="">-- اختر --</option>
                        <?php foreach ($genders as $key => $label): ?>
                        <option value="<?= e($key) ?>" <?= (old('gender') ?: ($player->gender ?? '')) === $key ? 'selected' : '' ?>><?= e($label) ?></option>
                        <?php endforeach; ?>
                    </select>
                </div>
            </div>
        </div>
    </div>

    <!-- Section 2: Contact & Guardian -->
    <div class="card" style="margin-bottom:20px;">
        <div style="padding:15px 20px;border-bottom:1px solid #E5E7EB;display:flex;align-items:center;gap:8px;">
            <i data-lucide="phone" style="width:18px;height:18px;color:#0D7377;"></i>
            <h3 style="margin:0;color:#0D7377;font-size:15px;">بيانات التواصل والولي</h3>
        </div>
        <div style="padding:20px;">
            <div style="display:grid;grid-template-columns:1fr 1fr;gap:20px;">
                <div class="form-group">
                    <label class="form-label">رقم الهاتف</label>
                    <input type="tel" name="phone" value="<?= e(old('phone') ?: ($player->phone ?? '')) ?>" class="form-input" maxlength="15" style="direction:ltr;text-align:left;" placeholder="01XXXXXXXXX">
                </div>
                <div class="form-group">
                    <label class="form-label">البريد الإلكتروني</label>
                    <input type="email" name="email" value="<?= e(old('email') ?: ($player->email ?? '')) ?>" class="form-input" style="direction:ltr;text-align:left;" placeholder="email@example.com">
                </div>
                <div class="form-group" style="grid-column:1/-1;">
                    <label class="form-label">العنوان</label>
                    <textarea name="address" class="form-input" rows="2" placeholder="عنوان السكن..."><?= e(old('address') ?: ($player->address ?? '')) ?></textarea>
                </div>
            </div>

            <div style="border-top:1px solid #E5E7EB;margin:20px 0;padding-top:20px;">
                <h4 style="margin:0 0 15px;color:#374151;font-size:14px;"><i data-lucide="shield" style="width:16px;height:16px;vertical-align:middle;margin-left:4px;"></i> بيانات ولي الأمر</h4>
                <div style="display:grid;grid-template-columns:1fr 1fr;gap:20px;">
                    <div class="form-group">
                        <label class="form-label">اسم ولي الأمر</label>
                        <input type="text" name="guardian_name" value="<?= e(old('guardian_name') ?: ($player->guardian_name ?? '')) ?>" class="form-input" placeholder="الاسم الكامل لولي الأمر">
                    </div>
                    <div class="form-group">
                        <label class="form-label">هاتف ولي الأمر</label>
                        <input type="tel" name="guardian_phone" value="<?= e(old('guardian_phone') ?: ($player->guardian_phone ?? '')) ?>" class="form-input" maxlength="15" style="direction:ltr;text-align:left;" placeholder="01XXXXXXXXX">
                    </div>
                    <div class="form-group">
                        <label class="form-label">الرقم القومي لولي الأمر</label>
                        <input type="text" name="guardian_national_id" value="<?= e(old('guardian_national_id') ?: ($player->guardian_national_id ?? '')) ?>" class="form-input" maxlength="14" style="direction:ltr;text-align:left;" placeholder="14 رقم">
                    </div>
                    <div class="form-group">
                        <label class="form-label">صلة القرابة</label>
                        <select name="guardian_relationship" class="form-input">
                            <option value="">-- اختر --</option>
                            <?php foreach ($relationships as $key => $label): ?>
                            <option value="<?= e($key) ?>" <?= (old('guardian_relationship') ?: ($player->guardian_relationship ?? '')) === $key ? 'selected' : '' ?>><?= e($label) ?></option>
                            <?php endforeach; ?>
                        </select>
                    </div>
                </div>
            </div>

            <div style="border-top:1px solid #E5E7EB;margin:20px 0;padding-top:20px;">
                <h4 style="margin:0 0 15px;color:#374151;font-size:14px;"><i data-lucide="graduation-cap" style="width:16px;height:16px;vertical-align:middle;margin-left:4px;"></i> البيانات التعليمية</h4>
                <div style="display:grid;grid-template-columns:1fr 1fr;gap:20px;">
                    <div class="form-group">
                        <label class="form-label">اسم المدرسة</label>
                        <input type="text" name="school_name" value="<?= e(old('school_name') ?: ($player->school_name ?? '')) ?>" class="form-input" placeholder="اسم المدرسة">
                    </div>
                    <div class="form-group">
                        <label class="form-label">الصف الدراسي</label>
                        <input type="text" name="school_grade" value="<?= e(old('school_grade') ?: ($player->school_grade ?? '')) ?>" class="form-input" placeholder="مثال: الصف الخامس الابتدائي">
                    </div>
                </div>
            </div>

            <div class="form-group" style="margin-top:10px;">
                <label class="form-label">ملاحظات</label>
                <textarea name="notes" class="form-input" rows="3" placeholder="أي ملاحظات إضافية..."><?= e(old('notes') ?: ($player->notes ?? '')) ?></textarea>
            </div>
        </div>
    </div>

    <!-- Submit -->
    <div style="display:flex;gap:10px;justify-content:flex-start;">
        <button type="submit" class="btn btn-primary" style="padding:12px 30px;font-size:15px;">
            <i data-lucide="check" style="width:16px;height:16px;vertical-align:middle;margin-left:4px;"></i> حفظ التعديلات
        </button>
        <a href="/players/<?= (int) $player->id ?>" class="btn btn-outline" style="padding:12px 30px;font-size:15px;">إلغاء</a>
    </div>
</form>

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