<?php $__template->layout('Layout.main'); ?>
<?php $__template->section('title'); ?>تعديل بيانات الزوج: <?= e($spouse->full_name_ar) ?><?php $__template->endSection(); ?>
<?php $__template->section('content'); ?>

<form method="POST" action="/members/<?= (int) $member['id'] ?>/spouses/<?= (int) $spouse->id ?>" enctype="multipart/form-data">
    <?= csrf_field() ?>
    <div class="card" style="padding:20px;margin-bottom:20px;">
        <h3 style="color:#0D7377;margin-bottom:15px;">البيانات الأساسية (للقراءة فقط)</h3>
        <div style="display:grid;grid-template-columns:1fr 1fr;gap:15px;">
            <div class="form-group"><label class="form-label">الاسم</label><input type="text" value="<?= e($spouse->full_name_ar) ?>" class="form-input" disabled style="background:#F3F4F6;"></div>
            <div class="form-group"><label class="form-label">الرقم القومي</label><input type="text" value="<?= e($spouse->national_id ?: '—') ?>" class="form-input" disabled style="background:#F3F4F6;direction:ltr;text-align:left;"></div>
            <div class="form-group"><label class="form-label">تاريخ الميلاد</label><input type="text" value="<?= e($spouse->date_of_birth) ?>" class="form-input" disabled style="background:#F3F4F6;"></div>
            <div class="form-group"><label class="form-label">تاريخ الزواج</label><input type="text" value="<?= e($spouse->marriage_date) ?>" class="form-input" disabled style="background:#F3F4F6;"></div>
            <div class="form-group"><label class="form-label">الترتيب</label><input type="text" value="<?= (int) $spouse->spouse_order ?>" class="form-input" disabled style="background:#F3F4F6;"></div>
            <div class="form-group"><label class="form-label">التصنيف</label><input type="text" value="<?= e($spouse->getClassificationLabel()) ?>" class="form-input" disabled style="background:#F3F4F6;"></div>
        </div>
    </div>
    <div class="card" style="padding:20px;margin-bottom:20px;">
        <h3 style="color:#0D7377;margin-bottom:15px;">البيانات القابلة للتعديل</h3>
        <div style="display:grid;grid-template-columns:1fr 1fr;gap:15px;">
            <div class="form-group"><label class="form-label">الاسم بالإنجليزي</label><input type="text" name="full_name_en" value="<?= e($spouse->full_name_en ?? '') ?>" class="form-input"></div>
            <div class="form-group"><label class="form-label">الديانة</label>
                <select name="religion" class="form-select"><option value="">—</option><option value="muslim" <?= $spouse->religion === 'muslim' ? 'selected' : '' ?>>مسلم</option><option value="christian" <?= $spouse->religion === 'christian' ? 'selected' : '' ?>>مسيحي</option><option value="other" <?= $spouse->religion === 'other' ? 'selected' : '' ?>>أخرى</option></select>
            </div>
            <div class="form-group"><label class="form-label">المؤهل الدراسي</label>
                <select name="qualification_id" class="form-select"><option value="">—</option>
                    <?php foreach ($qualifications as $q): ?><option value="<?= (int) $q['id'] ?>" <?= (int) ($spouse->qualification_id ?? 0) === (int) $q['id'] ? 'selected' : '' ?>><?= e($q['name_ar']) ?></option><?php endforeach; ?>
                </select>
            </div>
            <div class="form-group"><label class="form-label">الوظيفة</label><input type="text" name="occupation" value="<?= e($spouse->occupation ?? '') ?>" class="form-input"></div>
            <div class="form-group"><label class="form-label">رقم المحمول</label><input type="tel" name="mobile" value="<?= e($spouse->mobile ?? '') ?>" class="form-input" style="direction:ltr;text-align:left;"></div>
            <div class="form-group"><label class="form-label">تليفون العمل</label><input type="tel" name="work_phone" value="<?= e($spouse->work_phone ?? '') ?>" class="form-input" style="direction:ltr;text-align:left;"></div>
            <div class="form-group" style="grid-column:1/-1;"><label class="form-label">عنوان العمل</label><input type="text" name="work_address" value="<?= e($spouse->work_address ?? '') ?>" class="form-input"></div>
        </div>
    </div>
    <!-- Profile Photo -->
    <div class="card" style="padding:20px;margin-bottom:20px;border-right:4px solid #7C3AED;">
        <h3 style="color:#7C3AED;margin-bottom:15px;">الصورة الشخصية</h3>
        <?php $currentPhoto = $spouse->photo_path ?? null; $required = false; $fieldName = 'photo'; $label = 'الصورة الشخصية'; include \App\Core\App::getInstance()->basePath() . '/app/Shared/Components/photo-upload-field.php'; ?>
    </div>

    <button type="submit" class="btn btn-primary">حفظ التعديلات</button>
    <a href="/members/<?= (int) $member['id'] ?>" class="btn btn-outline">إلغاء</a>
</form>
<?php $__template->endSection(); ?>