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

<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">Compliance</p>
				<h1 class="ca-title"><?php echo isset($page_title) ? htmlspecialchars($page_title) : 'Documents'; ?></h1>
				<p class="ca-sub">Open each file in a new tab to review the actual upload. In production, use your storage URLs (or embed PDF/image preview in-page). Sample rows only.</p>
			</div>
			<div class="col-lg-4">
				<div class="ca-nav justify-content-lg-end">
					<a href="<?php echo base_url('admin'); ?>" class="btn btn-light">Overview</a>
					<a href="<?php echo base_url('admin/users'); ?>" class="btn btn-primary">Users</a>
				</div>
			</div>
		</div>
	</div>

	<div class="ca-card">
		<div class="ca-card-body p-0">
			<div class="ca-table-wrap border-0">
				<table class="table ca-table table-striped mb-0 align-middle">
					<thead>
						<tr>
							<th>Name</th>
							<th>Role</th>
							<th>Summary</th>
							<th>View files</th>
							<th>Status</th>
							<th class="text-end">Actions</th>
						</tr>
					</thead>
					<tbody>
						<?php foreach ($rows as $r): ?>
						<tr>
							<td class="fw-semibold"><?php echo htmlspecialchars($r['name']); ?></td>
							<td><?php echo htmlspecialchars($r['roles']); ?></td>
							<td><span class="small text-muted"><?php echo htmlspecialchars($r['docs']); ?></span></td>
							<td>
								<?php if (!empty($r['files']) && is_array($r['files'])): ?>
									<div class="d-flex flex-wrap gap-1">
										<?php foreach ($r['files'] as $f): ?>
											<?php
											$u = isset($f['url']) ? $f['url'] : '#';
											$is_pdf = (isset($f['type']) && $f['type'] === 'pdf');
											$lab = isset($f['label']) ? $f['label'] : 'File';
											?>
											<a href="<?php echo htmlspecialchars($u); ?>" class="btn btn-sm btn-outline-secondary rounded-pill px-2 py-0 ca-doc-preview-link" target="_blank" rel="noopener noreferrer" title="Open in new tab">
												<?php if ($is_pdf): ?>
													<i class="fa-regular fa-file-pdf text-danger me-1"></i>
												<?php else: ?>
													<i class="fa-regular fa-image text-primary me-1"></i>
												<?php endif; ?>
												<span class="small"><?php echo htmlspecialchars($lab); ?></span>
											</a>
										<?php endforeach; ?>
									</div>
								<?php else: ?>
									<span class="small text-muted">—</span>
								<?php endif; ?>
							</td>
							<td>
								<?php if ($r['status'] === 'Pending'): ?>
									<span class="ca-badge-soft ca-badge-pending">Pending</span>
								<?php elseif ($r['status'] === 'Verified'): ?>
									<span class="ca-badge-soft ca-badge-approved"><i class="fa-solid fa-check me-1"></i>Verified</span>
								<?php else: ?>
									<span class="ca-badge-soft ca-badge-declined">Rejected</span>
								<?php endif; ?>
							</td>
							<td class="text-end">
								<?php if ($r['status'] === 'Pending'): ?>
									<button type="button" class="btn btn-sm btn-ca-success rounded-pill px-3" title="Mark verified (sample)"><i class="fa-solid fa-check"></i> Verify</button>
									<button type="button" class="btn btn-sm btn-outline-danger rounded-pill px-3">Reject</button>
								<?php else: ?>
									<button type="button" class="btn btn-sm btn-light border rounded-pill" disabled>Change</button>
								<?php endif; ?>
							</td>
						</tr>
						<?php endforeach; ?>
					</tbody>
				</table>
			</div>
		</div>
	</div>
</div>
