<?php $pageTitle = 'Edit User'; ?>
<div class="mb-3"><a href="<?= base_url('admin/users') ?>" class="text-secondary"><i class="fas fa-arrow-left me-1"></i> Back</a></div>
<div class="card-cix" style="max-width:700px;">
    <div class="card-cix-header"><h5 class="mb-0"><i class="fas fa-user-edit text-orange me-2"></i> Edit User</h5></div>
    <?php if (!empty($error)): ?><div class="alert-cix alert-cix-error"><?= $error ?></div><?php endif; ?>
    <form method="POST" action="<?= base_url('admin/user-edit/' . $userEdit['id']) ?>">
        <?= csrf_field() ?>
        <div class="row g-3">
            <div class="col-md-6"><div class="form-group-cix"><label class="form-label-cix">First Name *</label><input type="text" name="first_name" class="form-control-cix" value="<?= e($userEdit['first_name']) ?>" required></div></div>
            <div class="col-md-6"><div class="form-group-cix"><label class="form-label-cix">Last Name *</label><input type="text" name="last_name" class="form-control-cix" value="<?= e($userEdit['last_name']) ?>" required></div></div>
            <div class="col-md-6"><div class="form-group-cix"><label class="form-label-cix">Email *</label><input type="email" name="email" class="form-control-cix" value="<?= e($userEdit['email']) ?>" required></div></div>
            <div class="col-md-6"><div class="form-group-cix"><label class="form-label-cix">Phone</label><input type="text" name="phone" class="form-control-cix" value="<?= e($userEdit['phone'] ?? '') ?>"></div></div>
            <div class="col-md-6"><div class="form-group-cix"><label class="form-label-cix">Role</label><select name="role_id" class="form-control-cix"><?php foreach ($roles as $r): ?><option value="<?= $r['id'] ?>" <?= $userEdit['role_id'] == $r['id'] ? 'selected' : '' ?>><?= e($r['name']) ?></option><?php endforeach; ?></select></div></div>
            <div class="col-md-6"><div class="form-group-cix"><label class="form-label-cix">New Password (blank = keep)</label><input type="password" name="new_password" class="form-control-cix"></div></div>
            <div class="col-md-6"><div class="form-check mt-4"><input class="form-check-input" type="checkbox" name="is_active" value="1" <?= $userEdit['is_active'] ? 'checked' : '' ?>><label class="form-check-label text-secondary">Active</label></div></div>
        </div>
        <button type="submit" class="btn-cix btn-cix-accent mt-3"><i class="fas fa-save"></i> Update User</button>
    </form>
</div>
