<?php $__template->layout('Layout.main'); ?>
<?php $__template->section('title'); ?>تعديل عقد <?= e($contract->contract_number) ?><?php $__template->endSection(); ?>

<?php $__template->section('page_actions'); ?>
<a href="/academy-contracts/<?= (int) $contract->id ?>" 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/<?= (int) $contract->id ?>">
    <?= 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 1fr;gap:20px;">
                <div class="form-group">
                    <label class="form-label">رقم العقد</label>
                    <input type="text" value="<?= e($contract->contract_number) ?>" class="form-input" disabled style="direction:ltr;text-align:left;background:#F9FAFB;">
                </div>
                <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', (string) $contract->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', $contract->contract_type) === $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', $contract->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', $contract->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', (string) $contract->minimum_revenue_guarantee)) ?>" 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', (string) $contract->club_commission_pct)) ?>" 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', (string) $contract->academy_share_pct)) ?>" 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', (string) $contract->fixed_monthly_rent)) ?>" 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', (string) $contract->deposit_amount)) ?>" 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', $contract->deposit_status) === 'pending' ? 'selected' : '' ?>>معلق</option>
                        <option value="paid" <?= old('deposit_status', $contract->deposit_status) === 'paid' ? 'selected' : '' ?>>مدفوع</option>
                        <option value="returned" <?= old('deposit_status', $contract->deposit_status) === 'returned' ? 'selected' : '' ?>>مسترد</option>
                        <option value="forfeited" <?= old('deposit_status', $contract->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', (string) $contract->settlement_day)) ?>" 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', (string) $contract->grace_period_days)) ?>" 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', (string) $contract->penalty_rate_pct)) ?>" 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', (string) $contract->renewal_notice_days)) ?>" 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', (string) $contract->auto_renew) ? 'checked' : '' ?> style="width:18px;height:18px;">
                    <span class="form-label" style="margin:0;">تجديد تلقائي عند انتهاء العقد</span>
                </label>
            </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', $contract->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/<?= (int) $contract->id ?>" 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(); ?>
