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

<?php
$p = $profile;
$doc_label = array(
	'approved' => array('label' => 'Approved', 'class' => 'ca-badge-soft ca-badge-approved'),
	'pending' => array('label' => 'Pending', 'class' => 'ca-badge-soft ca-badge-pending'),
	'declined' => array('label' => 'Declined', 'class' => 'ca-badge-soft ca-badge-declined'),
	'none' => array('label' => 'Not uploaded', 'class' => 'ca-badge-soft ca-badge-none'),
);
?>

<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">User profile</p>
				<h1 class="ca-title"><?php echo htmlspecialchars($p['name']); ?></h1>
				<p class="ca-sub mb-2">Internal ID: <code class="small"><?php echo htmlspecialchars($p['id']); ?></code> · Sample data only.</p>
				<div class="d-flex flex-wrap gap-2 align-items-center">
					<?php foreach ($p['roles'] as $r): ?>
						<span class="ca-role-chip"><?php echo htmlspecialchars($r); ?></span>
					<?php endforeach; ?>
					<?php if ($p['status'] === 'Active'): ?>
						<span class="badge rounded-pill ca-pill bg-success">Active</span>
					<?php else: ?>
						<span class="badge rounded-pill ca-pill bg-secondary">Inactive</span>
					<?php endif; ?>
				</div>
			</div>
			<div class="col-lg-4 text-lg-end">
				<div class="ca-nav justify-content-lg-end flex-column flex-sm-row gap-2">
					<a href="<?php echo base_url('admin/users'); ?>" class="btn btn-light"><i class="fa-solid fa-arrow-left me-2"></i>Back to users</a>
					<button type="button" class="btn btn-outline-secondary" disabled>Edit (demo)</button>
				</div>
			</div>
		</div>
	</div>

	<div class="row g-3">
		<div class="col-lg-4">
			<div class="ca-card mb-3">
				<div class="ca-card-header">
					<h5 class="ca-card-title mb-0">Contact</h5>
				</div>
				<div class="ca-card-body">
					<p class="mb-2"><span class="text-muted small d-block">Email</span><a href="mailto:<?php echo htmlspecialchars($p['email']); ?>"><?php echo htmlspecialchars($p['email']); ?></a></p>
					<p class="mb-2"><span class="text-muted small d-block">Phone</span><?php echo htmlspecialchars($p['phone']); ?></p>
					<p class="mb-2"><span class="text-muted small d-block">Member since</span><?php echo htmlspecialchars($p['signup']); ?></p>
					<p class="mb-0"><span class="text-muted small d-block">Timezone</span><?php echo htmlspecialchars($p['timezone']); ?></p>
				</div>
			</div>
			<div class="ca-card">
				<div class="ca-card-header">
					<h5 class="ca-card-title mb-0">Location &amp; languages</h5>
				</div>
				<div class="ca-card-body">
					<p class="mb-2"><span class="text-muted small d-block">Address</span><?php echo htmlspecialchars($p['address']); ?></p>
					<p class="mb-2"><span class="text-muted small d-block">City / state</span><?php echo htmlspecialchars($p['city_state']); ?></p>
					<p class="mb-0"><span class="text-muted small d-block">Languages</span><?php echo htmlspecialchars(implode(', ', $p['languages'])); ?></p>
				</div>
			</div>
		</div>
		<div class="col-lg-8">
			<div class="ca-card mb-3">
				<div class="ca-card-header">
					<h5 class="ca-card-title mb-0">About</h5>
				</div>
				<div class="ca-card-body">
					<p class="mb-3"><?php echo nl2br(htmlspecialchars($p['bio'])); ?></p>
					<p class="mb-0"><span class="text-muted small d-block">Typical availability</span><strong><?php echo htmlspecialchars($p['availability']); ?></strong></p>
				</div>
			</div>

			<div class="row g-3 mb-3">
				<div class="col-md-4">
					<div class="ca-stat h-100">
						<p class="ca-stat-label">Jobs completed</p>
						<p class="ca-stat-value mb-0"><?php echo (int) $p['jobs_completed']; ?></p>
					</div>
				</div>
				<div class="col-md-4">
					<div class="ca-stat h-100">
						<p class="ca-stat-label">Hours (this month)</p>
						<p class="ca-stat-value mb-0"><?php echo htmlspecialchars($p['hours_this_month']); ?></p>
					</div>
				</div>
				<div class="col-md-4">
					<div class="ca-stat h-100">
						<p class="ca-stat-label">Avg. rating</p>
						<p class="ca-stat-value mb-0"><?php echo htmlspecialchars($p['rating_avg']); ?> <span class="fs-5 text-warning">★</span></p>
						<p class="small text-muted mb-0"><?php echo (int) $p['reviews']; ?> reviews (table)</p>
					</div>
				</div>
			</div>

			<div class="ca-card mb-3">
				<div class="ca-card-header">
					<h5 class="ca-card-title mb-0">Documents</h5>
					<p class="mt-2 mb-0">Docs uploaded flag (table): <strong><?php echo htmlspecialchars($p['docs']); ?></strong></p>
				</div>
				<div class="ca-card-body p-0">
					<div class="ca-table-wrap border-0 rounded-0 border-top">
						<table class="table ca-table ca-table-sm mb-0">
							<thead>
								<tr>
									<th>Document</th>
									<th>Status</th>
								</tr>
							</thead>
							<tbody>
								<?php foreach ($p['documents'] as $d): ?>
									<?php
									$st = isset($doc_label[$d['state']]) ? $doc_label[$d['state']] : $doc_label['pending'];
									?>
									<tr>
										<td><?php echo htmlspecialchars($d['label']); ?></td>
										<td><span class="<?php echo $st['class']; ?>"><?php echo htmlspecialchars($st['label']); ?></span></td>
									</tr>
								<?php endforeach; ?>
							</tbody>
						</table>
					</div>
				</div>
			</div>

			<div class="ca-card">
				<div class="ca-card-header">
					<h5 class="ca-card-title mb-0">Recent reviews (sample)</h5>
				</div>
				<div class="ca-card-body">
					<?php foreach ($p['recent_reviews'] as $i => $rev): ?>
						<div class="pb-3 mb-3<?php echo ($i < count($p['recent_reviews']) - 1) ? ' border-bottom' : ''; ?>">
							<div class="d-flex justify-content-between flex-wrap gap-2">
								<strong class="small"><?php echo htmlspecialchars($rev['from']); ?></strong>
								<span class="small text-muted"><?php echo htmlspecialchars($rev['when']); ?></span>
							</div>
							<p class="mb-0 mt-2 small"><?php echo htmlspecialchars($rev['snippet']); ?></p>
						</div>
					<?php endforeach; ?>
				</div>
			</div>
		</div>
	</div>
</div>
