<?php
$__template->layout('Layout.main');
?>
<?php $__template->section('title'); ?>إضافة عقد - <?= e($academy['name_ar'] ?? '') ?><?php $__template->endSection(); ?>

<?php $__template->section('page_actions'); ?>
<a href="/sa/academies/<?= (int) $academy['id'] ?>/contracts" 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/academies/<?= (int) $academy['id'] ?>/contracts" enctype="multipart/form-data">
    <?= csrf_field() ?>

    <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>
                <input type="text" name="contract_number" value="<?= e(old('contract_number') ?? '') ?>" class="form-input" dir="ltr" required maxlength="50" placeholder="مثال: CTR-2026-001">
            </div>
            <div>
                <label class="form-label">نوع العقد <span style="color:#DC2626;">*</span></label>
                <select name="contract_type" class="form-select" required>
                    <option value="revenue_share" <?= (old('contract_type') ?? '') === 'revenue_share' ? 'selected' : '' ?>>نسبة إيرادات</option>
                    <option value="fixed_rent" <?= old('contract_type') === 'fixed_rent' ? 'selected' : '' ?>>إيجار ثابت</option>
                    <option value="hybrid" <?= old('contract_type') === 'hybrid' ? 'selected' : '' ?>>مختلط</option>
                </select>
            </div>
            <div>
                <label class="form-label">تاريخ البداية <span style="color:#DC2626;">*</span></label>
                <input type="date" name="start_date" value="<?= e(old('start_date') ?? '') ?>" class="form-input" required>
            </div>
            <div>
                <label class="form-label">تاريخ النهاية <span style="color:#DC2626;">*</span></label>
                <input type="date" name="end_date" value="<?= e(old('end_date') ?? '') ?>" class="form-input" required>
            </div>
            <div>
                <label class="form-label">نسبة النادي (%)</label>
                <input type="number" name="club_commission_pct" value="<?= e(old('club_commission_pct') ?? '0') ?>" class="form-input" step="0.1" min="0" max="100">
            </div>
            <div>
                <label class="form-label">نسبة الأكاديمية (%)</label>
                <input type="number" name="academy_share_pct" value="<?= e(old('academy_share_pct') ?? '0') ?>" class="form-input" step="0.1" min="0" max="100">
            </div>
            <div>
                <label class="form-label">الإيجار الشهري الثابت</label>
                <input type="number" name="fixed_monthly_rent" value="<?= e(old('fixed_monthly_rent') ?? '0') ?>" class="form-input" step="0.01" min="0">
            </div>
            <div>
                <label class="form-label">مبلغ التأمين</label>
                <input type="number" name="deposit_amount" value="<?= e(old('deposit_amount') ?? '0') ?>" class="form-input" step="0.01" min="0">
            </div>
            <div>
                <label class="form-label">ملف العقد (PDF) <span style="color:#DC2626;">*</span></label>
                <input type="file" name="contract_pdf" class="form-input" required accept=".pdf">
            </div>
            <div style="grid-column:1 / -1;">
                <label class="form-label">ملاحظات</label>
                <textarea name="notes" class="form-input" rows="3" placeholder="ملاحظات على العقد..."><?= e(old('notes') ?? '') ?></textarea>
            </div>
        </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/academies/<?= (int) $academy['id'] ?>/contracts" class="btn btn-outline">إلغاء</a>
    </div>
</form>

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