<?php $__template->layout('Layout.main'); ?>
<?php $__template->section('title'); ?>إنشاء عقد أكاديمية جديد<?php $__template->endSection(); ?>

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

    <!-- Basic Information -->
    <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="file-text" 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="academy_id" class="form-input" required>
                        <option value="">-- اختر الأكاديمية --</option>
                        <?php foreach ($academies as $acad): ?>
                        <option value="<?= (int) $acad['id'] ?>" <?= old('academy_id') == $acad['id'] ? 'selected' : '' ?>><?= e($acad['name_ar']) ?></option>
                        <?php endforeach; ?>
                    </select>
                </div>
                <div class="form-group">
                    <label class="form-label">نوع العقد <span style="color:#DC2626;">*</span></label>
                    <select name="contract_type" class="form-input" required>
                        <?php foreach ($contractTypes as $key => $label): ?>
                        <option value="<?= e($key) ?>" <?= old('contract_type', 'revenue_share') === $key ? 'selected' : '' ?>><?= e($label) ?></option>
                        <?php endforeach; ?>
                    </select>
                </div>
            </div>
            <div style="display:grid;grid-template-columns:1fr 1fr;gap:20px;margin-top:15px;">
                <div class="form-group">
                    <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 style="direction:ltr;text-align:left;">
                </div>
                <div class="form-group">
                    <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 style="direction:ltr;text-align:left;">
                </div>
            </div>
        </div>
    </div>

    <!-- Financial Terms -->
    <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="banknote" style="width:18px;height:18px;color:#D97706;"></i>
            <h3 style="margin:0;color:#D97706;font-size:15px;">الشروط المالية</h3>
        </div>
        <div style="padding:20px;">
            <div style="display:grid;grid-template-columns:1fr 1fr 1fr;gap:20px;">
                <div class="form-group">
                    <label class="form-label">الحد الأدنى المضمون (ج.م)</label>
                    <input type="number" name="minimum_revenue_guarantee" value="<?= e(old('minimum_revenue_guarantee', '0')) ?>" class="form-input" min="0" step="0.01" style="direction:ltr;text-align:left;">
                </div>
                <div class="form-group">
                    <label class="form-label">نسبة عمولة النادي %</label>
                    <input type="number" name="club_commission_pct" value="<?= e(old('club_commission_pct', '0')) ?>" class="form-input" min="0" max="100" step="0.01" style="direction:ltr;text-align:left;">
                </div>
                <div class="form-group">
                    <label class="form-label">نسبة حصة الأكاديمية %</label>
                    <input type="number" name="academy_share_pct" value="<?= e(old('academy_share_pct', '0')) ?>" class="form-input" min="0" max="100" step="0.01" style="direction:ltr;text-align:left;">
                </div>
            </div>
            <div style="display:grid;grid-template-columns:1fr 1fr 1fr;gap:20px;margin-top:15px;">
                <div class="form-group">
                    <label class="form-label">الإيجار الشهري الثابت (ج.م)</label>
                    <input type="number" name="fixed_monthly_rent" value="<?= e(old('fixed_monthly_rent', '0')) ?>" class="form-input" min="0" step="0.01" style="direction:ltr;text-align:left;">
                </div>
                <div class="form-group">
                    <label class="form-label">مبلغ التأمين (ج.م)</label>
                    <input type="number" name="deposit_amount" value="<?= e(old('deposit_amount', '0')) ?>" class="form-input" min="0" step="0.01" style="direction:ltr;text-align:left;">
                </div>
                <div class="form-group">
                    <label class="form-label">حالة التأمين</label>
                    <select name="deposit_status" class="form-input">
                        <option value="pending" <?= old('deposit_status', 'pending') === 'pending' ? 'selected' : '' ?>>معلق</option>
                        <option value="paid" <?= old('deposit_status') === 'paid' ? 'selected' : '' ?>>مدفوع</option>
                        <option value="returned" <?= old('deposit_status') === 'returned' ? 'selected' : '' ?>>مسترد</option>
                        <option value="forfeited" <?= old('deposit_status') === 'forfeited' ? 'selected' : '' ?>>مصادر</option>
                    </select>
                </div>
            </div>
        </div>
    </div>

    <!-- Settlement & Penalty Settings -->
    <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="settings" style="width:18px;height:18px;color:#7C3AED;"></i>
            <h3 style="margin:0;color:#7C3AED;font-size:15px;">إعدادات التسوية والجزاءات</h3>
        </div>
        <div style="padding:20px;">
            <div style="display:grid;grid-template-columns:1fr 1fr 1fr 1fr;gap:20px;">
                <div class="form-group">
                    <label class="form-label">يوم التسوية</label>
                    <input type="number" name="settlement_day" value="<?= e(old('settlement_day', '5')) ?>" class="form-input" min="1" max="28" style="direction:ltr;text-align:left;">
                    <small style="color:#9CA3AF;font-size:11px;">يوم من الشهر (1-28)</small>
                </div>
                <div class="form-group">
                    <label class="form-label">فترة السماح (أيام)</label>
                    <input type="number" name="grace_period_days" value="<?= e(old('grace_period_days', '7')) ?>" class="form-input" min="0" style="direction:ltr;text-align:left;">
                </div>
                <div class="form-group">
                    <label class="form-label">نسبة الغرامة %</label>
                    <input type="number" name="penalty_rate_pct" value="<?= e(old('penalty_rate_pct', '0')) ?>" class="form-input" min="0" max="100" step="0.01" style="direction:ltr;text-align:left;">
                </div>
                <div class="form-group">
                    <label class="form-label">مهلة التجديد (أيام)</label>
                    <input type="number" name="renewal_notice_days" value="<?= e(old('renewal_notice_days', '30')) ?>" class="form-input" min="0" style="direction:ltr;text-align:left;">
                </div>
            </div>
            <div style="margin-top:15px;">
                <label style="display:flex;align-items:center;gap:8px;cursor:pointer;">
                    <input type="checkbox" name="auto_renew" value="1" <?= old('auto_renew') ? 'checked' : '' ?> style="width:18px;height:18px;">
                    <span class="form-label" style="margin:0;">تجديد تلقائي عند انتهاء العقد</span>
                </label>
            </div>
        </div>
    </div>

    <!-- Contract Document -->
    <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="upload" style="width:18px;height:18px;color:#2563EB;"></i>
            <h3 style="margin:0;color:#2563EB;font-size:15px;">مستند العقد</h3>
        </div>
        <div style="padding:20px;">
            <div class="form-group">
                <label class="form-label">مستند العقد (PDF)</label>
                <input type="file" name="contract_document" accept=".pdf" class="form-input">
                <small style="color:#6B7280;">PDF فقط — حد أقصى 10 ميجا</small>
            </div>
        </div>
    </div>

    <!-- Notes -->
    <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="message-square" style="width:18px;height:18px;color:#6B7280;"></i>
            <h3 style="margin:0;color:#6B7280;font-size:15px;">ملاحظات</h3>
        </div>
        <div style="padding:20px;">
            <textarea name="notes" class="form-input" rows="3" placeholder="ملاحظات إضافية..."><?= e(old('notes')) ?></textarea>
        </div>
    </div>

    <!-- Submit Buttons -->
    <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="/academy-contracts" 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(); ?>
