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

<?php
$u = isset($user) && is_array($user) ? $user : array();
function h($v) { return htmlspecialchars((string) $v, ENT_QUOTES, 'UTF-8'); }
$fullName = trim((isset($u['firstName']) ? $u['firstName'] : '') . ' ' . (isset($u['lastName']) ? $u['lastName'] : ''));
$fullName = $fullName !== '' ? $fullName : (isset($u['uid']) ? $u['uid'] : 'Family host');
$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">AOUST portal</p>
				<h1 class="ca-title"><?php echo h($fullName); ?></h1>
				<p class="ca-sub mb-0"><span class="badge bg-primary-subtle text-primary border border-primary-subtle">Family host</span> · Firestore <strong>Users</strong></p>
			</div>
			<div class="col-lg-4">
				<div class="ca-nav justify-content-lg-end">
					<a class="btn btn-light border" href="<?php echo base_url('admin/aoust_users?type=family_host'); ?>">Back</a>
					<a class="btn btn-primary" href="<?php echo base_url('admin/aoust_user_edit/' . rawurlencode($uid)); ?>">Edit</a>
				</div>
			</div>
		</div>
	</div>

	<div class="row g-3">
		<div class="col-12 col-lg-4">
			<div class="ca-card h-100">
				<div class="ca-card-header">
					<h5 class="ca-card-title mb-0"><i class="fa-regular fa-id-badge me-2 text-success"></i>Account</h5>
				</div>
				<div class="ca-card-body">
					<div class="d-flex align-items-center gap-3">
						<?php if (!empty($u['profileImage'])): ?>
							<img src="<?php echo h($u['profileImage']); ?>" alt="Profile image" style="width:72px;height:72px;border-radius:18px;object-fit:cover;border:1px solid rgba(0,0,0,0.08);">
						<?php else: ?>
							<div style="width:72px;height:72px;border-radius:18px;display:flex;align-items:center;justify-content:center;background:rgba(13,110,253,0.12);border:1px solid rgba(13,110,253,0.22);font-weight:800;color:#0a58ca;">
								<?php echo h(strtoupper(substr($fullName, 0, 1))); ?>
							</div>
						<?php endif; ?>
						<div class="min-w-0">
							<div class="fw-semibold"><?php echo h($fullName); ?></div>
							<div class="text-muted small">UID: <span class="font-monospace"><?php echo h($uid); ?></span></div>
							<div class="text-muted small"><?php echo h(isset($u['email']) ? $u['email'] : ''); ?></div>
						</div>
					</div>

					<hr>

					<div class="row g-2">
						<div class="col-6">
							<div class="text-muted small">Status</div>
							<div>
								<?php if (!empty($u['isActive'])): ?>
									<span class="badge bg-success-subtle text-success border border-success-subtle">Active</span>
								<?php else: ?>
									<span class="badge bg-secondary-subtle text-secondary border border-secondary-subtle">Inactive</span>
								<?php endif; ?>
							</div>
						</div>
						<div class="col-6">
							<div class="text-muted small">Verified</div>
							<div>
								<?php if (!empty($u['isVerifiedUser'])): ?>
									<span class="badge bg-primary-subtle text-primary border border-primary-subtle">Yes</span>
								<?php else: ?>
									<span class="badge bg-light text-dark border">No</span>
								<?php endif; ?>
							</div>
						</div>
						<div class="col-6">
							<div class="text-muted small">Smoker (house)</div>
							<div class="fw-semibold"><?php echo isset($u['doYouSmoke']) ? ($u['doYouSmoke'] ? 'Yes' : 'No') : '—'; ?></div>
						</div>
						<div class="col-6">
							<div class="text-muted small">Phone</div>
							<div class="fw-semibold"><?php echo h(isset($u['phone']) ? $u['phone'] : '—'); ?></div>
						</div>
					</div>
				</div>
			</div>
		</div>

		<div class="col-12 col-lg-8">
			<div class="ca-card">
				<div class="ca-card-header d-flex align-items-center justify-content-between">
					<h5 class="ca-card-title mb-0"><i class="fa-solid fa-location-dot me-2 text-success"></i>Host location</h5>
					<?php
					$lat = isset($u['lat']) ? $u['lat'] : null;
					$lon = isset($u['lon']) ? $u['lon'] : null;
					$gmaps = ($lat !== null && $lon !== null) ? ('https://www.google.com/maps?q=' . rawurlencode($lat . ',' . $lon)) : '';
					?>
					<?php if ($gmaps): ?>
						<a class="btn btn-sm btn-light border" target="_blank" rel="noopener noreferrer" href="<?php echo h($gmaps); ?>">
							<i class="fa-solid fa-arrow-up-right-from-square me-1"></i>Open map
						</a>
					<?php endif; ?>
				</div>
				<div class="ca-card-body">
					<div class="row g-3">
						<div class="col-12">
							<div class="text-muted small">Address</div>
							<div class="fw-semibold"><?php echo h(isset($u['address']) ? $u['address'] : '—'); ?></div>
						</div>
						<div class="col-12 col-md-4">
							<div class="text-muted small">City</div>
							<div class="fw-semibold"><?php echo h(isset($u['city']) ? $u['city'] : '—'); ?></div>
						</div>
						<div class="col-12 col-md-4">
							<div class="text-muted small">Postal code</div>
							<div class="fw-semibold"><?php echo h(isset($u['postalCode']) ? $u['postalCode'] : '—'); ?></div>
						</div>
						<div class="col-12 col-md-4">
							<div class="text-muted small">Country</div>
							<div class="fw-semibold"><?php echo h(isset($u['countryName']) ? $u['countryName'] : '—'); ?></div>
						</div>
					</div>
				</div>
			</div>

			<div class="ca-card mt-3">
				<div class="ca-card-header">
					<h5 class="ca-card-title mb-0"><i class="fa-regular fa-file-lines me-2 text-success"></i>About / bio</h5>
				</div>
				<div class="ca-card-body">
					<?php echo nl2br(h(isset($u['bio']) ? $u['bio'] : '')); ?>
				</div>
			</div>

			<div class="ca-card mt-3">
				<div class="ca-card-header">
					<h5 class="ca-card-title mb-0"><i class="fa-solid fa-shield-halved me-2 text-success"></i>Verification documents</h5>
				</div>
				<div class="ca-card-body">
					<div class="row g-2">
						<div class="col-12 col-md-6">
							<div class="p-3 border rounded-3">
								<div class="fw-semibold mb-1">Government ID</div>
								<div class="small text-muted mb-2"><?php echo !empty($u['isApprovedGovernmentID']) ? 'Approved' : 'Not approved'; ?></div>
								<?php if (!empty($u['governmentIdUrl'])): ?>
									<a class="btn btn-sm btn-light border" target="_blank" rel="noopener noreferrer" href="<?php echo h($u['governmentIdUrl']); ?>">
										<i class="fa-solid fa-arrow-up-right-from-square me-1"></i>Open file
									</a>
								<?php else: ?>
									<span class="text-muted small">—</span>
								<?php endif; ?>
							</div>
						</div>
						<div class="col-12 col-md-6">
							<div class="p-3 border rounded-3">
								<div class="fw-semibold mb-1">Police check</div>
								<div class="small text-muted mb-2"><?php echo !empty($u['isApprovedPoliceChekcurl']) ? 'Approved' : 'Not approved'; ?></div>
								<?php if (!empty($u['policeChekcUrl'])): ?>
									<a class="btn btn-sm btn-light border" target="_blank" rel="noopener noreferrer" href="<?php echo h($u['policeChekcUrl']); ?>">
										<i class="fa-solid fa-arrow-up-right-from-square me-1"></i>Open file
									</a>
								<?php else: ?>
									<span class="text-muted small">—</span>
								<?php endif; ?>
							</div>
						</div>
						<div class="col-12 col-md-6">
							<div class="p-3 border rounded-3">
								<div class="fw-semibold mb-1">Reference letter</div>
								<div class="small text-muted mb-2"><?php echo !empty($u['isApproveReferenceLetter']) ? 'Approved' : 'Not approved'; ?></div>
								<?php if (!empty($u['referenceLetterUrl'])): ?>
									<a class="btn btn-sm btn-light border" target="_blank" rel="noopener noreferrer" href="<?php echo h($u['referenceLetterUrl']); ?>">
										<i class="fa-solid fa-arrow-up-right-from-square me-1"></i>Open file
									</a>
								<?php else: ?>
									<span class="text-muted small">—</span>
								<?php endif; ?>
							</div>
						</div>
					</div>
				</div>
			</div>
		</div>
	</div>
</div>

