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

<?php $__template->section('page_actions'); ?>
<a href="/players" 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" id="playerForm">
    <?= 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">نوع اللاعب <span style="color:#DC2626;">*</span></label>
                    <select name="player_type" id="playerType" class="form-input" required>
                        <option value="">-- اختر النوع --</option>
                        <?php foreach ($playerTypes as $key => $label): ?>
                        <option value="<?= e($key) ?>" <?= old('player_type') === $key ? 'selected' : '' ?>><?= e($label) ?></option>
                        <?php endforeach; ?>
                    </select>
                </div>
                <div class="form-group" id="memberIdGroup" style="display:none;">
                    <label class="form-label">رقم العضوية</label>
                    <input type="number" name="member_id" value="<?= e(old('member_id')) ?>" class="form-input" min="1" style="direction:ltr;text-align:left;" placeholder="رقم العضوية في النادي">
                </div>
                <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')) ?>" 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')) ?>" 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')) ?>" 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')) ?>" 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')) ?>" 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') === $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')) ?>" 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')) ?>" 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')) ?></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')) ?>" 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')) ?>" 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')) ?>" 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') === $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')) ?>" 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')) ?>" 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')) ?></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" 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();

    var playerTypeSelect = document.getElementById('playerType');
    var memberIdGroup = document.getElementById('memberIdGroup');

    function toggleMemberId() {
        if (playerTypeSelect.value === 'member') {
            memberIdGroup.style.display = '';
        } else {
            memberIdGroup.style.display = 'none';
        }
    }

    playerTypeSelect.addEventListener('change', toggleMemberId);
    toggleMemberId();
});
</script>
<?php $__template->endSection(); ?>
