<?php $__template->layout('Layout.main'); ?>
<?php $__template->section('title'); ?>تعديل الموظف: <?= e($employee->full_name_ar) ?><?php $__template->endSection(); ?>
<?php $__template->section('content'); ?>
<form method="POST" action="/users/<?= (int) $employee->id ?>">
    <?= csrf_field() ?>
    <div class="card" style="padding:20px;margin-bottom:20px;">
        <div style="display:grid;grid-template-columns:1fr 1fr;gap:20px;">
            <div class="form-group">
                <label class="form-label">اسم المستخدم</label>
                <input type="text" value="<?= e($employee->username) ?>" class="form-input" disabled style="background:#f3f4f6;">
            </div>
            <div class="form-group">
                <label class="form-label">كلمة مرور جديدة (اتركه فارغاً للإبقاء)</label>
                <input type="password" name="new_password" class="form-input" minlength="8">
            </div>
            <div class="form-group">
                <label class="form-label">الاسم بالعربي <span style="color:#DC2626;">*</span></label>
                <input type="text" name="full_name_ar" value="<?= e($employee->full_name_ar) ?>" class="form-input" required>
            </div>
            <div class="form-group">
                <label class="form-label">الاسم بالإنجليزي</label>
                <input type="text" name="full_name_en" value="<?= e($employee->full_name_en ?? '') ?>" class="form-input">
            </div>
            <div class="form-group">
                <label class="form-label">البريد الإلكتروني</label>
                <input type="email" name="email" value="<?= e($employee->email ?? '') ?>" class="form-input">
            </div>
            <div class="form-group">
                <label class="form-label">رقم الهاتف</label>
                <input type="text" name="phone" value="<?= e($employee->phone ?? '') ?>" class="form-input">
            </div>
            <div class="form-group">
                <label class="form-label">الفرع</label>
                <select name="branch_id" class="form-select">
                    <option value="">جميع الفروع</option>
                    <?php foreach ($branches as $b): ?>
                        <option value="<?= (int) $b['id'] ?>" <?= (int) $employee->branch_id === (int) $b['id'] ? 'selected' : '' ?>><?= e($b['name_ar']) ?></option>
                    <?php endforeach; ?>
                </select>
            </div>
            <div class="form-group">
                <label class="form-label">الحالة</label>
                <select name="is_active" class="form-select">
                    <option value="1" <?= $employee->is_active ? 'selected' : '' ?>>نشط</option>
                    <option value="0" <?= !$employee->is_active ? 'selected' : '' ?>>معطل</option>
                </select>
            </div>
        </div>
    </div>
    <div class="card" style="padding:20px;margin-bottom:20px;">
        <h3 style="margin-bottom:15px;">الأدوار</h3>
        <div style="display:grid;grid-template-columns:repeat(auto-fill, minmax(200px, 1fr));gap:10px;">
            <?php foreach ($allRoles as $role): ?>
                <label style="display:flex;align-items:center;gap:8px;cursor:pointer;">
                    <input type="checkbox" name="roles[]" value="<?= (int) $role['id'] ?>"
                        <?= in_array($role['id'], $currentRoleIds) ? 'checked' : '' ?>>
                    <span><?= e($role['name_ar']) ?></span>
                </label>
            <?php endforeach; ?>
        </div>
    </div>
    <button type="submit" class="btn btn-primary">حفظ التعديلات</button>
    <a href="/users" class="btn btn-outline">إلغاء</a>
</form>
<?php $__template->endSection(); ?>