<?php require __DIR__ . '/../../layouts/header.php'; ?>

<div class="d-flex justify-content-between align-items-center mb-4">
    <h1 class="fw-bold mb-0"><?= e(trans('edit_user')) ?></h1>
    <a href="<?= e(base_path('admin/users')) ?>" class="btn ec-btn btn-outline-secondary rounded-3"><?= e(trans('back')) ?></a>
</div>

<div class="ec-card  ">
    <div class="ec-card-body p-4">
        <form method="post" action="<?= e(base_path('admin/users/edit?id=' . (int) $userRow['id'])) ?>">
            <input type="hidden" name="_csrf" value="<?= e(csrf_token()) ?>">

            <div class="row g-3">
                <div class="col-md-6">
                    <label class="form-label ec-required"><?= e(trans('first_name')) ?></label>
                    <input type="text" name="first_name" class="form-control rounded-3" value="<?= e((string) $userRow['first_name']) ?>" required>
                </div>
                <div class="col-md-6">
                    <label class="form-label ec-required"><?= e(trans('last_name')) ?></label>
                    <input type="text" name="last_name" class="form-control rounded-3" value="<?= e((string) $userRow['last_name']) ?>" required>
                </div>
                <div class="col-md-6">
                    <label class="form-label ec-required"><?= e(trans('email')) ?></label>
                    <input type="email" name="email" class="form-control rounded-3" value="<?= e((string) $userRow['email']) ?>" required>
                </div>
                <div class="col-md-6">
                    <label class="form-label ec-required"><?= e(trans('role')) ?></label>
                    <select name="role_id" class="form-select rounded-3" required>
                        <?php foreach ($roles as $role): ?>
                            <option value="<?= e((string) $role['id']) ?>" <?= (int) $userRow['role_id'] === (int) $role['id'] ? 'selected' : '' ?>>
                                <?= e(role_label((string) $role['code'])) ?>
                            </option>
                        <?php endforeach; ?>
                    </select>
                </div>
                <div class="col-md-6">
                    <label class="form-label"><?= e(trans('password')) ?> <small class="text-muted">(optional)</small></label>
                    <input type="password" name="password" class="form-control rounded-3">
                </div>
                <div class="col-md-6">
                    <label class="form-label"><?= e(trans('confirm_password')) ?></label>
                    <input type="password" name="confirm_password" class="form-control rounded-3">
                </div>
                <div class="col-md-6">
                    <label class="form-label"><?= e(trans('language_pref')) ?></label>
                    <select name="preferred_lang" class="form-select rounded-3">
                        <option value="en" <?= (string) $userRow['preferred_lang'] === 'en' ? 'selected' : '' ?>>English</option>
                        <option value="ar" <?= (string) $userRow['preferred_lang'] === 'ar' ? 'selected' : '' ?>>العربية</option>
                    </select>
                </div>
                <div class="col-md-6 d-flex align-items-end">
                    <div class="form-check">
                        <input class="form-check-input" type="checkbox" name="is_active" id="is_active" <?= (int) $userRow['is_active'] === 1 ? 'checked' : '' ?>>
                        <label class="form-check-label" for="is_active"><?= e(trans('active')) ?></label>
                    </div>
                </div>
            </div>

            <div class="mt-4 d-flex gap-2">
                <button type="submit" class="btn ec-btn btn-success rounded-3"><?= e(trans('save')) ?></button>
                <a href="<?= e(base_path('admin/users')) ?>" class="btn ec-btn btn-outline-secondary rounded-3"><?= e(trans('cancel')) ?></a>
            </div>
        </form>
    </div>
</div>

<?php require __DIR__ . '/../../layouts/footer.php'; ?>
