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

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

<div class="card" style="max-width:800px;margin:0 auto;">
    <div style="padding:20px;border-bottom:1px solid #E5E7EB;">
        <h2 style="margin:0;font-size:18px;color:#1A1A2E;">
            <i data-lucide="heart-pulse" style="width:20px;height:20px;vertical-align:middle;margin-left:8px;color:#DC2626;"></i>
            تسجيل إصابة جديدة
        </h2>
    </div>

    <form method="POST" action="/injuries" style="padding:20px;">
        <?= csrf_field() ?>

        <!-- Player Selection -->
        <div style="margin-bottom:20px;">
            <label class="form-label">اللاعب <span style="color:#DC2626;">*</span></label>
            <select name="player_id" class="form-input" required>
                <option value="">-- اختر اللاعب --</option>
                <?php foreach ($players as $p): ?>
                <option value="<?= (int) $p['id'] ?>" <?= old('player_id') == $p['id'] ? 'selected' : '' ?>><?= e($p['full_name_ar']) ?> (<?= e($p['registration_serial'] ?? '') ?>)</option>
                <?php endforeach; ?>
            </select>
        </div>

        <!-- Discipline -->
        <div style="margin-bottom:20px;">
            <label class="form-label">النشاط الرياضي</label>
            <select name="discipline_id" class="form-input">
                <option value="">-- اختياري --</option>
                <?php foreach ($disciplines as $d): ?>
                <option value="<?= (int) $d['id'] ?>" <?= old('discipline_id') == $d['id'] ? 'selected' : '' ?>><?= e($d['name_ar']) ?></option>
                <?php endforeach; ?>
            </select>
        </div>

        <div style="display:grid;grid-template-columns:1fr 1fr;gap:15px;margin-bottom:20px;">
            <!-- Injury Type -->
            <div>
                <label class="form-label">نوع الإصابة <span style="color:#DC2626;">*</span></label>
                <select name="injury_type" class="form-input" required>
                    <option value="">-- اختر --</option>
                    <?php foreach ($injuryTypes as $key => $label): ?>
                    <option value="<?= e($key) ?>" <?= old('injury_type') === $key ? 'selected' : '' ?>><?= e($label) ?></option>
                    <?php endforeach; ?>
                </select>
            </div>

            <!-- Body Part -->
            <div>
                <label class="form-label">مكان الإصابة <span style="color:#DC2626;">*</span></label>
                <select name="body_part" class="form-input" required>
                    <option value="">-- اختر --</option>
                    <?php foreach ($bodyParts as $key => $label): ?>
                    <option value="<?= e($key) ?>" <?= old('body_part') === $key ? 'selected' : '' ?>><?= e($label) ?></option>
                    <?php endforeach; ?>
                </select>
            </div>
        </div>

        <div style="display:grid;grid-template-columns:1fr 1fr;gap:15px;margin-bottom:20px;">
            <!-- Severity -->
            <div>
                <label class="form-label">شدة الإصابة <span style="color:#DC2626;">*</span></label>
                <select name="severity" class="form-input" required>
                    <option value="">-- اختر --</option>
                    <?php foreach ($severities as $key => $label): ?>
                    <option value="<?= e($key) ?>" <?= old('severity') === $key ? 'selected' : '' ?>><?= e($label) ?></option>
                    <?php endforeach; ?>
                </select>
            </div>

            <!-- Occurred Date -->
            <div>
                <label class="form-label">تاريخ الإصابة <span style="color:#DC2626;">*</span></label>
                <input type="date" name="occurred_date" value="<?= e(old('occurred_date') ?? date('Y-m-d')) ?>" class="form-input" required>
            </div>
        </div>

        <div style="display:grid;grid-template-columns:1fr 1fr;gap:15px;margin-bottom:20px;">
            <!-- Occurred During -->
            <div>
                <label class="form-label">حدثت أثناء</label>
                <select name="occurred_during" class="form-input">
                    <option value="">-- اختياري --</option>
                    <?php foreach ($occurredDuring as $key => $label): ?>
                    <option value="<?= e($key) ?>" <?= old('occurred_during') === $key ? 'selected' : '' ?>><?= e($label) ?></option>
                    <?php endforeach; ?>
                </select>
            </div>

            <!-- Estimated Recovery -->
            <div>
                <label class="form-label">فترة التعافي المتوقعة (أيام)</label>
                <input type="number" name="estimated_recovery_days" value="<?= e(old('estimated_recovery_days') ?? '') ?>" class="form-input" min="1" max="365">
            </div>
        </div>

        <!-- Description -->
        <div style="margin-bottom:20px;">
            <label class="form-label">وصف الإصابة</label>
            <textarea name="description_ar" class="form-input" rows="3" placeholder="وصف تفصيلي لما حدث..."><?= e(old('description_ar') ?? '') ?></textarea>
        </div>

        <!-- Diagnosis -->
        <div style="display:grid;grid-template-columns:1fr 1fr;gap:15px;margin-bottom:20px;">
            <div>
                <label class="form-label">التشخيص</label>
                <textarea name="diagnosis_ar" class="form-input" rows="2" placeholder="التشخيص الطبي..."><?= e(old('diagnosis_ar') ?? '') ?></textarea>
            </div>
            <div>
                <label class="form-label">العلاج</label>
                <textarea name="treatment_ar" class="form-input" rows="2" placeholder="خطة العلاج..."><?= e(old('treatment_ar') ?? '') ?></textarea>
            </div>
        </div>

        <div style="display:grid;grid-template-columns:1fr 1fr;gap:15px;margin-bottom:20px;">
            <!-- Diagnosed By -->
            <div>
                <label class="form-label">تم التشخيص بواسطة</label>
                <input type="text" name="diagnosed_by" value="<?= e(old('diagnosed_by') ?? '') ?>" class="form-input" placeholder="اسم الطبيب / المعالج">
            </div>

            <!-- Follow Up Date -->
            <div>
                <label class="form-label">تاريخ المتابعة</label>
                <input type="date" name="follow_up_date" value="<?= e(old('follow_up_date') ?? '') ?>" class="form-input">
            </div>
        </div>

        <!-- Notes -->
        <div style="margin-bottom:20px;">
            <label class="form-label">ملاحظات</label>
            <textarea name="notes" class="form-input" rows="2" placeholder="ملاحظات إضافية..."><?= e(old('notes') ?? '') ?></textarea>
        </div>

        <!-- Actions -->
        <div style="display:flex;gap:10px;justify-content:flex-start;padding-top:15px;border-top:1px solid #E5E7EB;">
            <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="/injuries" class="btn btn-outline">إلغاء</a>
        </div>
    </form>
</div>

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