<?php
$__template->layout('Layout.main');
?>
<?php $__template->section('title'); ?>تعديل بيانات اللاعب<?php $__template->endSection(); ?>

<?php $__template->section('page_actions'); ?>
<a href="/sa/players/<?= (int) $player['id'] ?>" 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'); ?>

<form method="POST" action="/sa/players/<?= (int) $player['id'] ?>/update">
    <?= csrf_field() ?>

    <!-- Basic Information -->
    <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(250px, 1fr));gap:15px;">
            <div>
                <label class="form-label">نوع اللاعب <span style="color:#DC2626;">*</span></label>
                <select name="player_type" class="form-select" id="player_type" required>
                    <option value="">اختر...</option>
                    <option value="member" <?= (old('player_type') ?? $player['player_type']) === 'member' ? 'selected' : '' ?>>عضو</option>
                    <option value="non_member" <?= (old('player_type') ?? $player['player_type']) === 'non_member' ? 'selected' : '' ?>>غير عضو</option>
                </select>
            </div>
            <div id="member_id_field" style="<?= ($player['player_type'] ?? '') !== 'member' ? 'display:none;' : '' ?>">
                <label class="form-label">رقم العضوية <span style="color:#DC2626;">*</span></label>
                <input type="number" name="member_id" value="<?= e(old('member_id') ?? $player['member_id'] ?? '') ?>" class="form-input" placeholder="أدخل رقم العضوية">
            </div>
            <div>
                <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>
            </div>
            <div>
                <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" dir="ltr">
            </div>
            <div>
                <label class="form-label">الرقم القومي</label>
                <input type="text" name="national_id" value="<?= e(old('national_id') ?? $player['national_id'] ?? '') ?>" class="form-input" maxlength="14" dir="ltr">
            </div>
            <div>
                <label class="form-label">تاريخ الميلاد</label>
                <input type="date" name="date_of_birth" value="<?= e(old('date_of_birth') ?? $player['date_of_birth'] ?? '') ?>" class="form-input">
            </div>
            <div>
                <label class="form-label">النوع</label>
                <select name="gender" class="form-select">
                    <option value="male" <?= (old('gender') ?? $player['gender'] ?? '') === 'male' ? 'selected' : '' ?>>ذكر</option>
                    <option value="female" <?= (old('gender') ?? $player['gender'] ?? '') === 'female' ? 'selected' : '' ?>>أنثى</option>
                </select>
            </div>
            <div>
                <label class="form-label">الهاتف</label>
                <input type="text" name="phone" value="<?= e(old('phone') ?? $player['phone'] ?? '') ?>" class="form-input" dir="ltr">
            </div>
            <div>
                <label class="form-label">البريد الإلكتروني</label>
                <input type="email" name="email" value="<?= e(old('email') ?? $player['email'] ?? '') ?>" class="form-input" dir="ltr">
            </div>
        </div>
    </div>

    <!-- Guardian Information -->
    <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(250px, 1fr));gap:15px;">
            <div>
                <label class="form-label">اسم ولي الأمر</label>
                <input type="text" name="guardian_name" value="<?= e(old('guardian_name') ?? $player['guardian_name'] ?? '') ?>" class="form-input">
            </div>
            <div>
                <label class="form-label">هاتف ولي الأمر</label>
                <input type="text" name="guardian_phone" value="<?= e(old('guardian_phone') ?? $player['guardian_phone'] ?? '') ?>" class="form-input" dir="ltr">
            </div>
            <div>
                <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" dir="ltr">
            </div>
            <div>
                <label class="form-label">صلة القرابة</label>
                <select name="guardian_relationship" class="form-select">
                    <option value="">اختر...</option>
                    <option value="father" <?= (old('guardian_relationship') ?? $player['guardian_relationship'] ?? '') === 'father' ? 'selected' : '' ?>>أب</option>
                    <option value="mother" <?= (old('guardian_relationship') ?? $player['guardian_relationship'] ?? '') === 'mother' ? 'selected' : '' ?>>أم</option>
                    <option value="brother" <?= (old('guardian_relationship') ?? $player['guardian_relationship'] ?? '') === 'brother' ? 'selected' : '' ?>>أخ</option>
                    <option value="sister" <?= (old('guardian_relationship') ?? $player['guardian_relationship'] ?? '') === 'sister' ? 'selected' : '' ?>>أخت</option>
                    <option value="uncle" <?= (old('guardian_relationship') ?? $player['guardian_relationship'] ?? '') === 'uncle' ? 'selected' : '' ?>>عم / خال</option>
                    <option value="other" <?= (old('guardian_relationship') ?? $player['guardian_relationship'] ?? '') === 'other' ? 'selected' : '' ?>>أخرى</option>
                </select>
            </div>
        </div>
    </div>

    <!-- 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;">
            <textarea name="notes" class="form-input" rows="4" placeholder="ملاحظات إضافية..."><?= e(old('notes') ?? $player['notes'] ?? '') ?></textarea>
        </div>
    </div>

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

<script>
document.addEventListener('DOMContentLoaded', function() {
    if (typeof lucide !== 'undefined') lucide.createIcons();

    var playerType = document.getElementById('player_type');
    var memberField = document.getElementById('member_id_field');

    function toggleMemberId() {
        memberField.style.display = playerType.value === 'member' ? '' : 'none';
    }
    playerType.addEventListener('change', toggleMemberId);
});
</script>
<?php $__template->endSection(); ?>
