<?php $__template->layout('Layout.main'); ?>
<?php $__template->section('title'); ?>تعديل العضو: <?= e($member->full_name_ar) ?><?php $__template->endSection(); ?>
<?php $__template->section('content'); ?>
<form method="POST" action="/members/<?= (int) $member->id ?>">
    <?= csrf_field() ?>

    <?php if (!empty($isSuperAdmin)): ?>
    <!-- ═══ SuperAdmin Only: Name & National ID ═══ -->
    <div class="card" style="margin-bottom:20px;padding:20px;border-right:4px solid #DC2626;">
        <div style="display:flex;align-items:center;gap:10px;margin-bottom:15px;">
            <h3 style="color:#DC2626;margin:0;">🔒 صلاحيات المشرف العام</h3>
            <span style="background:#FEF2F2;color:#DC2626;padding:3px 10px;border-radius:4px;font-size:11px;font-weight:600;">SUPER ADMIN ONLY</span>
        </div>
        <p style="color:#6B7280;font-size:13px;margin-bottom:15px;">⚠ تغيير هذه البيانات يؤثر على كل سجلات العضو — تأكد من صحة البيانات قبل الحفظ</p>
        <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="text" name="full_name_ar" value="<?= e($member->full_name_ar) ?>" class="form-input" style="font-size:16px;font-weight:600;border-color:#DC2626;" required minlength="5" maxlength="200">
            </div>
            <div class="form-group">
                <label class="form-label">الرقم القومي</label>
                <input type="text" name="national_id" value="<?= e($member->national_id ?? '') ?>" class="form-input" maxlength="14" style="direction:ltr;text-align:left;font-size:16px;letter-spacing:1px;border-color:#DC2626;">
                <small style="color:#DC2626;font-size:11px;">تغيير الرقم القومي سيعيد حساب تاريخ الميلاد والنوع والمحافظة</small>
            </div>
        </div>
    </div>
    <?php endif; ?>

    <div class="card" style="margin-bottom:20px;padding:20px;">
        <h3 style="color:#0D7377;margin-bottom:15px;">البيانات الأساسية (للقراءة فقط)</h3>
        <div style="display:grid;grid-template-columns:1fr 1fr;gap:15px;">
            <?php if (empty($isSuperAdmin)): ?>
            <div class="form-group"><label class="form-label">الاسم بالعربي 🔒</label><input type="text" value="<?= e($member->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($member->national_id ?: '—') ?>" class="form-input" disabled style="background:#F3F4F6;direction:ltr;text-align:left;"></div>
            <?php endif; ?>
            <div class="form-group"><label class="form-label">تاريخ الميلاد</label><input type="text" value="<?= e($member->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($member->getGenderLabel()) ?>" class="form-input" disabled style="background:#F3F4F6;"></div>
        </div>
    </div>

    <div class="card" style="margin-bottom:20px;padding: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($member->full_name_en ?? '') ?>" class="form-input"></div>
            <div class="form-group"><label class="form-label">الحالة الاجتماعية</label>
                <select name="marital_status" class="form-select"><option value="">—</option><option value="single" <?= $member->marital_status === 'single' ? 'selected' : '' ?>>أعزب</option><option value="married" <?= $member->marital_status === 'married' ? 'selected' : '' ?>>متزوج</option><option value="divorced" <?= $member->marital_status === 'divorced' ? 'selected' : '' ?>>مطلق</option><option value="widowed" <?= $member->marital_status === 'widowed' ? 'selected' : '' ?>>أرمل</option></select>
            </div>
            <div class="form-group"><label class="form-label">رقم المحمول <span style="color:#DC2626;">*</span></label><input type="tel" name="phone_mobile" value="<?= e($member->phone_mobile) ?>" class="form-input" required style="direction:ltr;text-align:left;"></div>
            <div class="form-group"><label class="form-label">تليفون المنزل</label><input type="tel" name="phone_home" value="<?= e($member->phone_home ?? '') ?>" class="form-input" style="direction:ltr;text-align:left;"></div>
            <div class="form-group"><label class="form-label">البريد الإلكتروني</label><input type="email" name="email" value="<?= e($member->email ?? '') ?>" class="form-input" style="direction:ltr;text-align:left;"></div>
            <div class="form-group"><label class="form-label">شخص للطوارئ</label><input type="text" name="emergency_name" value="<?= e($member->emergency_name ?? '') ?>" class="form-input"></div>
            <div class="form-group"><label class="form-label">هاتف الطوارئ</label><input type="tel" name="emergency_phone" value="<?= e($member->emergency_phone ?? '') ?>" class="form-input" style="direction:ltr;text-align:left;"></div>
            <div class="form-group"><label class="form-label">المهنة</label><input type="text" name="occupation" value="<?= e($member->occupation ?? '') ?>" class="form-input"></div>
            <div class="form-group"><label class="form-label">المركز الوظيفي</label><input type="text" name="job_title" value="<?= e($member->job_title ?? '') ?>" class="form-input"></div>
            <div class="form-group" style="grid-column:1/-1;"><label class="form-label">عنوان السكن</label><textarea name="residence_address" class="form-textarea" rows="2"><?= e($member->residence_address ?? '') ?></textarea></div>
            <div class="form-group">
                <label class="form-label">المحافظة</label>
                <select name="governorate" class="form-select"><option value="">—</option>
                    <?php foreach ($governorates as $g): ?><option value="<?= e($g['name_ar']) ?>" <?= $member->governorate === $g['name_ar'] ? 'selected' : '' ?>><?= e($g['name_ar']) ?></option><?php endforeach; ?>
                </select>
            </div>
            <div class="form-group"><label class="form-label">المنطقة</label><input type="text" name="area" value="<?= e($member->area ?? '') ?>" class="form-input"></div>
        </div>
    </div>

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