<div class="row justify-content-center"><div class="col-lg-8"><div class="card">
    <div class="card-header"><h5 class="mb-0"><?= $staff ? 'Edit Staff' : 'Create Staff' ?></h5></div>
    <div class="card-body">
        <form method="POST" action="<?= $staff ? '/admin/staff/' . $staff['id'] : '/admin/staff' ?>" data-ajax="true">
            <?= csrf_field() ?>
            <div class="row g-3">
                <div class="col-md-4"><label class="form-label">Staff # <span class="text-danger">*</span></label><input type="text" name="staff_number" class="form-control" value="<?= e($staff['staff_number'] ?? '') ?>" required><div class="invalid-feedback" data-field="staff_number"></div></div>
                <div class="col-md-4"><label class="form-label">First Name (EN) <span class="text-danger">*</span></label><input type="text" name="first_name_en" class="form-control" value="<?= e($staff['first_name_en'] ?? '') ?>" required></div>
                <div class="col-md-4"><label class="form-label">Last Name (EN) <span class="text-danger">*</span></label><input type="text" name="last_name_en" class="form-control" value="<?= e($staff['last_name_en'] ?? '') ?>" required></div>
                <div class="col-md-4"><label class="form-label">First Name (AR)</label><input type="text" name="first_name_ar" class="form-control" value="<?= e($staff['first_name_ar'] ?? '') ?>"></div>
                <div class="col-md-4"><label class="form-label">Last Name (AR)</label><input type="text" name="last_name_ar" class="form-control" value="<?= e($staff['last_name_ar'] ?? '') ?>"></div>
                <div class="col-md-4"><label class="form-label">Gender</label><select name="gender" class="form-select"><option value="">-</option><option value="male" <?= selected('male', $staff['gender'] ?? '') ?>>Male</option><option value="female" <?= selected('female', $staff['gender'] ?? '') ?>>Female</option></select></div>
                <div class="col-md-4"><label class="form-label">Department</label><select name="department_id" class="form-select"><option value="">-</option><?php foreach($departments as $d): ?><option value="<?= $d['id'] ?>" <?= selected($d['id'], $staff['department_id'] ?? '') ?>><?= e($d['name_en']) ?></option><?php endforeach; ?></select></div>
                <div class="col-md-4"><label class="form-label">Position</label><select name="position_id" class="form-select"><option value="">-</option><?php foreach($positions as $p): ?><option value="<?= $p['id'] ?>" <?= selected($p['id'], $staff['position_id'] ?? '') ?>><?= e($p['title_en']) ?></option><?php endforeach; ?></select></div>
                <div class="col-md-4"><label class="form-label">Linked User</label><select name="user_id" class="form-select"><option value="">-</option><?php foreach($users as $u): ?><option value="<?= $u['id'] ?>" <?= selected($u['id'], $staff['user_id'] ?? '') ?>><?= e($u['full_name_en']) ?> (<?= e($u['username']) ?>)</option><?php endforeach; ?></select></div>
                <div class="col-md-4"><label class="form-label">Phone</label><input type="text" name="phone" class="form-control" value="<?= e($staff['phone'] ?? '') ?>"></div>
                <div class="col-md-4"><label class="form-label">Email</label><input type="email" name="email" class="form-control" value="<?= e($staff['email'] ?? '') ?>"></div>
                <div class="col-md-4"><label class="form-label">Hire Date <span class="text-danger">*</span></label><input type="date" name="hire_date" class="form-control datepicker" value="<?= e($staff['hire_date'] ?? '') ?>" required></div>
                <?php if ($staff): ?>
                <div class="col-md-4"><label class="form-label">Status</label><select name="status" class="form-select"><option value="active" <?= selected('active', $staff['status']) ?>>Active</option><option value="on_leave" <?= selected('on_leave', $staff['status']) ?>>On Leave</option><option value="suspended" <?= selected('suspended', $staff['status']) ?>>Suspended</option><option value="terminated" <?= selected('terminated', $staff['status']) ?>>Terminated</option></select></div>
                <?php endif; ?>
            </div>
            <div class="mt-4 d-flex gap-2"><button type="submit" class="btn btn-primary"><i class="fas fa-save me-1"></i>Save</button><a href="/admin/staff" class="btn btn-secondary">Cancel</a></div>
        </form>
    </div>
</div></div></div>