<?php
defined('BASEPATH') OR exit('No direct script access allowed');
/** ADMIN USER FORM — Expects: $u, $mode. */
?>
<div class="page-head">
	<div><h2><?= $mode === 'edit' ? 'Edit' : 'Add' ?> Admin User</h2></div>
	<a href="<?= base_url('admin/users') ?>" class="btn btn-ghost">← Back</a>
</div>

<form action="<?= base_url('admin/users/save') ?>" method="post">
	<?= form_hidden($this->security->get_csrf_token_name(), $this->security->get_csrf_hash()) ?>
	<input type="hidden" name="id" value="<?= (int) $u['id'] ?>">

	<div class="card" style="max-width:640px;">
		<div class="card-head"><h3>Account Details</h3></div>
		<div class="card-body">
			<div class="form-grid cols-2">
				<div class="fld"><label>Full Name <span class="req">*</span></label>
					<input type="text" name="name" value="<?= html_escape($u['name']) ?>" required></div>
				<div class="fld"><label>Email Address <span class="req">*</span></label>
					<input type="email" name="email" value="<?= html_escape($u['email']) ?>" required></div>
				<div class="fld"><label>Role <span class="req">*</span></label>
					<select name="role">
						<option value="editor" <?= $u['role'] === 'editor' ? 'selected' : '' ?>>Editor / Staff</option>
						<option value="super_admin" <?= $u['role'] === 'super_admin' ? 'selected' : '' ?>>Super Admin</option>
					</select>
				</div>
				<div class="fld"><label><?= $mode === 'edit' ? 'New Password' : 'Password' ?> <?php if ($mode !== 'edit'): ?><span class="req">*</span><?php endif; ?></label>
					<input type="password" name="password" <?= $mode !== 'edit' ? 'required' : '' ?> placeholder="<?= $mode === 'edit' ? 'Leave blank to keep current' : 'Min 8 characters' ?>">
				</div>
				<div class="fld fld-full"><label class="check">
					<input type="checkbox" name="is_active" value="1" <?= $u['is_active'] ? 'checked' : '' ?>>
					<span>Account is active</span>
				</label></div>
			</div>
			<p class="hint" style="margin-top:6px;">
				<strong>Editors</strong> can manage content. <strong>Super Admins</strong> additionally manage users and settings.
			</p>
		</div>
	</div>

	<div class="card" style="max-width:640px;"><div class="card-body"><div class="form-actions">
		<button type="submit" class="btn btn-primary"><?= bloom_icon('check', 16) ?> Save User</button>
		<a href="<?= base_url('admin/users') ?>" class="btn btn-ghost">Cancel</a>
	</div></div></div>
</form>
