<?php $__template->layout('Layout.main'); ?>
<?php $__template->section('title'); ?>حالة طلاق #<?= (int) $case['id'] ?><?php $__template->endSection(); ?>
<?php $__template->section('content'); ?>
<div class="card" style="padding:20px;margin-bottom:20px;">
    <table style="width:100%;max-width:600px;font-size:14px;">
        <tr><td style="padding:6px 0;color:#6B7280;width:35%;">العضو</td><td style="padding:6px 0;"><a href="/members/<?= (int) $case['member_id'] ?>" style="color:#0D7377;font-weight:600;"><?= e($case['member_name']) ?></a></td></tr>
        <tr><td style="padding:6px 0;color:#6B7280;">الزوج/ة</td><td style="padding:6px 0;font-weight:600;"><?= e($case['spouse_name']) ?></td></tr>
        <tr><td style="padding:6px 0;color:#6B7280;">تاريخ الطلاق</td><td style="padding:6px 0;"><?= e($case['divorce_date']) ?></td></tr>
        <tr><td style="padding:6px 0;color:#6B7280;">النوع</td><td style="padding:6px 0;font-weight:600;"><?= e(\App\Modules\Divorce\Models\DivorceCase::getCaseTypeLabel($case['divorce_case_type'])) ?></td></tr>
        <tr><td style="padding:6px 0;color:#6B7280;">الحالة</td><td style="padding:6px 0;font-weight:700;color:<?= match($case['status']) { 'completed' => '#059669', 'fee_paid' => '#2563EB', default => '#D97706' } ?>;">● <?= match($case['status']) { 'completed' => 'مكتمل', 'fee_paid' => 'تم الدفع', default => 'مقدّم' } ?></td></tr>
        <?php if ($case['spouse_new_membership_number']): ?><tr><td style="padding:6px 0;color:#6B7280;">رقم العضوية الجديد</td><td style="padding:6px 0;font-weight:700;color:#0D7377;font-size:20px;"><?= e($case['spouse_new_membership_number']) ?></td></tr><?php endif; ?>
    </table>
</div>

<!-- Fee Breakdown -->
<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="receipt" style="width:18px;height:18px;color:#D97706;"></i>
        <h3 style="margin:0;color:#D97706;font-size:15px;">تفصيل الرسوم</h3>
    </div>
    <div style="padding:20px;">
        <table style="width:100%;max-width:500px;font-size:14px;">
            <?php if (!empty($case['membership_value']) && bccomp($case['membership_value'], '0', 2) > 0): ?>
            <tr>
                <td style="padding:8px 0;color:#6B7280;">قيمة العضوية</td>
                <td style="padding:8px 0;font-weight:600;direction:ltr;text-align:left;"><?= money($case['membership_value']) ?></td>
            </tr>
            <?php endif; ?>
            <tr>
                <td style="padding:8px 0;color:#6B7280;">نسبة رسوم الطلاق</td>
                <td style="padding:8px 0;font-weight:600;"><?= e($case['fee_percentage'] ?? '0') ?>%</td>
            </tr>
            <tr style="border-top:1px solid #E5E7EB;">
                <td style="padding:10px 0;color:#6B7280;">رسوم الطلاق (<?= e($case['fee_percentage'] ?? '0') ?>% من قيمة العضوية)</td>
                <td style="padding:10px 0;font-weight:700;direction:ltr;text-align:left;color:#0D7377;"><?= money($percentageFee ?? '0') ?></td>
            </tr>
            <tr>
                <td style="padding:8px 0;color:#6B7280;">رسوم الاستمارة</td>
                <td style="padding:8px 0;font-weight:600;direction:ltr;text-align:left;"><?= money($formFee ?? '0') ?></td>
            </tr>
            <tr style="border-top:2px solid #0D7377;">
                <td style="padding:12px 0;font-weight:700;font-size:16px;">الإجمالي المطلوب</td>
                <td style="padding:12px 0;font-weight:800;font-size:22px;color:#DC2626;direction:ltr;text-align:left;"><?= money($case['fee_amount'] ?? '0') ?></td>
            </tr>
        </table>
    </div>
</div>

<?php if (!in_array($case['status'], ['completed', 'fee_paid']) && bccomp($case['fee_amount'] ?? '0', '0', 2) > 0): ?>
<div class="card" style="padding:20px;margin-bottom:20px;background:#FFF7ED;border:2px solid #F59E0B;">
    <h4 style="margin:0 0 15px;color:#D97706;">💰 دفع رسوم الطلاق</h4>
    <form method="POST" action="/divorce/<?= (int) $case['id'] ?>/pay">
        <?= csrf_field() ?>
        <input type="hidden" name="amount" value="<?= e($case['fee_amount']) ?>">
        <div style="display:flex;gap:10px;align-items:end;">
            <div class="form-group"><label class="form-label">المبلغ</label><input type="text" value="<?= money($case['fee_amount']) ?>" class="form-input" style="background:#F3F4F6;font-weight:700;font-size:18px;" readonly></div>
            <div class="form-group"><label class="form-label">طريقة الدفع</label><select name="payment_method" class="form-select"><option value="cash">نقدي</option><option value="visa">فيزا</option><option value="bank_transfer">تحويل</option></select></div>
            <button type="submit" class="btn btn-primary" style="padding:10px 25px;" onclick="return confirm('تأكيد الدفع؟')">💰 ادفع</button>
        </div>
    </form>
</div>
<?php endif; ?>

<?php if ($case['status'] !== 'completed'): ?>
<form method="POST" action="/divorce/<?= (int) $case['id'] ?>/complete">
    <?= csrf_field() ?>
    <button type="submit" class="btn btn-primary" onclick="return confirm('⚠ إتمام حالة الطلاق — سيتم إنشاء عضوية جديدة. متأكد؟')">✅ إتمام حالة الطلاق</button>
</form>
<?php endif; ?>
<script>document.addEventListener('DOMContentLoaded', function() { if (typeof lucide !== 'undefined') lucide.createIcons(); });</script>
<?php $__template->endSection(); ?>