<?php
$__template->layout('Layout.main');
?>
<?php $__template->section('title'); ?>عقد تأجير جديد<?php $__template->endSection(); ?>

<?php $__template->section('page_actions'); ?>
<a href="/rentals" 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="/rentals/contracts">
    <?= \App\Core\CSRF::field() ?>

    <div class="card" style="margin-bottom:20px;">
        <div style="padding:15px 20px;border-bottom:1px solid #E5E7EB;">
            <h3 style="margin:0;color:#0D7377;">بيانات العقد</h3>
        </div>
        <div style="padding:20px;display:grid;grid-template-columns:1fr 1fr;gap:15px;">

            <div>
                <label class="form-label">الجهة المستأجرة <span style="color:#DC2626;">*</span></label>
                <select name="entity_id" class="form-input" required>
                    <option value="">-- اختر الجهة --</option>
                    <?php foreach ($entities as $ent): ?>
                    <option value="<?= (int) $ent['id'] ?>" <?= (string) old('entity_id') === (string) $ent['id'] ? 'selected' : '' ?>><?= e($ent['name_ar']) ?></option>
                    <?php endforeach; ?>
                </select>
            </div>

            <div>
                <label class="form-label">المرفق <span style="color:#DC2626;">*</span></label>
                <select name="facility_id" class="form-input" required>
                    <option value="">-- اختر المرفق --</option>
                    <?php foreach ($facilities as $fac): ?>
                    <option value="<?= (int) $fac['id'] ?>" <?= (string) old('facility_id') === (string) $fac['id'] ? 'selected' : '' ?>><?= e($fac['name_ar']) ?></option>
                    <?php endforeach; ?>
                </select>
            </div>

            <div>
                <label class="form-label">نوع النشاط</label>
                <select name="activity_type" class="form-input">
                    <option value="">-- اختر --</option>
                    <option value="practice" <?= old('activity_type') === 'practice' ? 'selected' : '' ?>>تدريب</option>
                    <option value="competitive" <?= old('activity_type') === 'competitive' ? 'selected' : '' ?>>تنافسي</option>
                </select>
            </div>

            <div>
                <label class="form-label">الفترة الزمنية</label>
                <select name="time_tier" class="form-input">
                    <option value="AM" <?= old('time_tier', 'AM') === 'AM' ? 'selected' : '' ?>>صباحي</option>
                    <option value="PM" <?= old('time_tier', 'AM') === 'PM' ? '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">عدد الوحدات <span style="color:#DC2626;">*</span></label>
                <input type="number" name="total_units" value="<?= e(old('total_units')) ?>" class="form-input" min="1" required>
            </div>

            <div>
                <label class="form-label">سعر الوحدة <span style="color:#DC2626;">*</span></label>
                <input type="number" name="unit_rate" value="<?= e(old('unit_rate')) ?>" class="form-input" step="0.01" min="0.01" required>
            </div>

            <div>
                <label class="form-label">نسبة التأمين (%)</label>
                <input type="number" name="deposit_percentage" value="<?= e(old('deposit_percentage')) ?>" class="form-input" step="0.01" min="0" placeholder="10%">
            </div>

            <div></div>

            <div style="grid-column:1/-1;">
                <label class="form-label">ملاحظات</label>
                <textarea name="notes" class="form-input" rows="3" style="resize:vertical;"><?= e(old('notes')) ?></textarea>
            </div>

        </div>
    </div>

    <div style="display:flex;gap:10px;">
        <button type="submit" class="btn btn-primary">إنشاء العقد</button>
        <a href="/rentals" class="btn btn-outline">إلغاء</a>
    </div>
</form>

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