<link href="<?php echo base_url('assets/css/admin-panel.css'); ?>?v=20260827a" rel="stylesheet">

<?php
$u = $user;
$uid = isset($u['uid']) ? (string) $u['uid'] : '';
?>

<div class="care-admin">
	<div class="ca-hero">
		<div class="ca-hero-inner row align-items-center g-3">
			<div class="col-lg-8">
				<p class="ca-kicker">Users · Edit</p>
				<h1 class="ca-title">Edit profile</h1>
				<p class="ca-sub mb-0">Public profile fields only. Passwords are never shown or stored from this form.</p>
			</div>
			<div class="col-lg-4">
				<div class="ca-nav justify-content-lg-end">
					<a class="btn btn-light" href="<?php echo base_url('admin/user_view/' . rawurlencode($uid)); ?>">Cancel</a>
					<button form="formUserEdit" type="submit" class="btn btn-primary">Save changes</button>
				</div>
			</div>
		</div>
	</div>

	<div class="ca-card">
		<div class="ca-card-header">
			<h5 class="ca-card-title mb-0">Account</h5>
		</div>
		<div class="ca-card-body">
			<form id="formUserEdit" method="post" action="<?php echo base_url('admin/user_update/' . rawurlencode($uid)); ?>" autocomplete="off">
				<div class="row g-3">
					<div class="col-md-6">
						<label class="form-label">Display name</label>
						<input class="form-control" name="displayName" value="<?php echo htmlspecialchars($u['displayName']); ?>">
					</div>
					<div class="col-md-6">
						<label class="form-label">Username</label>
						<input class="form-control" name="username" value="<?php echo htmlspecialchars($u['username']); ?>" required>
					</div>
					<div class="col-md-6">
						<label class="form-label">Email</label>
						<input class="form-control" value="<?php echo htmlspecialchars($u['email']); ?>" disabled>
						<div class="form-text">Email is managed by authentication and is not edited here.</div>
					</div>
					<div class="col-md-6">
						<label class="form-label">Age group</label>
						<select class="form-select" name="ageGroup">
							<?php
							$ages = array('', '13-14', '15-16', '17-18', '18-19');
							foreach ($ages as $age):
							?>
								<option value="<?php echo htmlspecialchars($age); ?>" <?php echo $u['ageGroup'] === $age ? 'selected' : ''; ?>>
									<?php echo $age === '' ? 'Not set' : $age; ?>
								</option>
							<?php endforeach; ?>
						</select>
					</div>
					<div class="col-md-6">
						<label class="form-label">Status</label>
						<select class="form-select" name="status">
							<?php foreach (array('active', 'suspended', 'blocked', 'deleted') as $st): ?>
								<option value="<?php echo $st; ?>" <?php echo $u['status'] === $st ? 'selected' : ''; ?>><?php echo ucfirst($st); ?></option>
							<?php endforeach; ?>
						</select>
					</div>
					<div class="col-12">
						<label class="form-label">Bio</label>
						<textarea class="form-control" name="bio" rows="3"><?php echo htmlspecialchars($u['bio']); ?></textarea>
					</div>
				</div>
			</form>
		</div>
	</div>
</div>
