<?php $__template->layout('Layout.main'); ?>
<?php $__template->section('title'); ?>إنشاء موظف جديد<?php $__template->endSection(); ?>
<?php $__template->section('content'); ?>
<form method="POST" action="/users">
    <?= 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">اسم المستخدم <span style="color:#DC2626;">*</span></label>
                <input type="text" name="username" value="<?= e(old('username')) ?>" class="form-input" required>
            </div>
            <div class="form-group">
                <label class="form-label">كلمة المرور <span style="color:#DC2626;">*</span></label>
                <input type="password" name="password" class="form-input" required minlength="8">
                <small style="color:#6B7280;">سيُطلب من الموظف تغييرها عند أول تسجيل دخول</small>
            </div>
            <div class="form-group">
                <label class="form-label">الاسم بالعربي <span style="color:#DC2626;">*</span></label>
                <input type="text" name="full_name_ar" value="<?= e(old('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(old('full_name_en')) ?>" class="form-input">
            </div>
            <div class="form-group">
                <label class="form-label">البريد الإلكتروني</label>
                <input type="email" name="email" value="<?= e(old('email')) ?>" class="form-input">
            </div>
            <div class="form-group">
                <label class="form-label">رقم الهاتف</label>
                <input type="text" name="phone" value="<?= e(old('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'] ?>"><?= e($b['name_ar']) ?></option>
                    <?php endforeach; ?>
                </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 ($roles as $role): ?>
                <label style="display:flex;align-items:center;gap:8px;cursor:pointer;">
                    <input type="checkbox" name="roles[]" value="<?= (int) $role['id'] ?>">
                    <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(); ?>