<?php $__template->layout('Layout.main'); ?>
<?php $__template->section('title'); ?>إنشاء خطة تقسيط — <?= e($member['full_name_ar']) ?><?php $__template->endSection(); ?>
<?php $__template->section('content'); ?>
<?php if ($existingActive): ?>
<div style="padding:15px;background:#FEF2F2;border:1px solid #FECACA;border-radius:8px;margin-bottom:20px;color:#DC2626;">
    <strong>⚠ يوجد خطة تقسيط نشطة بالفعل</strong> — خطة #<?= (int) $existingActive['id'] ?> بمبلغ <?= money($existingActive['total_with_interest']) ?>
    <a href="/installments/<?= (int) $existingActive['id'] ?>" style="color:#1e3a5f;margin-right:10px;">عرض الخطة</a>
</div>
<?php endif; ?>
<?php if (can('installment.create_plan')): ?>
<form method="POST" action="/installments/store/<?= (int) $member['id'] ?>">
    <?= csrf_field() ?>
    <div class="card" style="padding:20px;margin-bottom:20px;">
        <div style="margin-bottom:15px;padding:10px;background:#EFF6FF;border:1px solid #BFDBFE;border-radius:8px;">
            <strong>العضو:</strong> <?= e($member['full_name_ar']) ?> — <strong>قيمة العضوية:</strong> <?= $member['membership_value'] ? money($member['membership_value']) : '—' ?>
        </div>
        <div style="display:grid;grid-template-columns:1fr 1fr;gap:15px;">
            <div class="form-group"><label class="form-label">المبلغ الإجمالي <span style="color:#DC2626;">*</span></label><input type="number" name="total_amount" value="<?= e($member['membership_value'] ?? '') ?>" class="form-input" step="0.01" required style="direction:ltr;text-align:left;"></div>
            <div class="form-group"><label class="form-label">المقدم (≥25%) <span style="color:#DC2626;">*</span></label><input type="number" name="down_payment" class="form-input" step="0.01" required style="direction:ltr;text-align:left;" placeholder="الحد الأدنى 25%"></div>
            <div class="form-group"><label class="form-label">عدد الأشهر (≤30) <span style="color:#DC2626;">*</span></label><input type="number" name="number_of_months" class="form-input" min="1" max="30" required></div>
            <div class="form-group"><label class="form-label">تاريخ البداية <span style="color:#DC2626;">*</span></label><input type="date" name="start_date" value="<?= e(date('Y-m-d')) ?>" class="form-input" required></div>
            <div class="form-group"><label class="form-label">رقم إيصال المقدم</label><input type="text" name="down_payment_receipt" class="form-input"></div>
            <div class="form-group" style="grid-column:1/-1;"><label class="form-label">ملاحظات</label><textarea name="notes" class="form-textarea" rows="2"></textarea></div>
        </div>
    </div>
    <button type="submit" class="btn btn-primary">إنشاء خطة التقسيط</button>
    <a href="/members/<?= (int) $member['id'] ?>" class="btn btn-outline">إلغاء</a>
</form>
<?php endif; ?>
<?php $__template->endSection(); ?>