<?php defined('BASEPATH') OR exit('No direct script access allowed'); ?>
<section class="panel">
	<div class="actions" style="justify-content:flex-start; margin-top:0; margin-bottom:18px;">
		<a class="btn btn-outline" href="<?php echo site_url('configuracion'); ?>">Regresar</a>
	</div>

	<div class="actions" style="justify-content:flex-start; margin-top:0; margin-bottom:18px;">
		<a class="btn<?php echo ($active_tab ?? 'pending') === 'pending' ? '' : ' btn-outline'; ?>" href="<?php echo site_url('configuracion/notificaciones'); ?>">Pendientes</a>
		<a class="btn<?php echo ($active_tab ?? 'pending') === 'reviewed' ? '' : ' btn-outline'; ?>" href="<?php echo site_url('configuracion/notificaciones?tab=reviewed'); ?>">Revisadas</a>
	</div>

	<?php if (!empty($flash_message)) { ?>
		<div class="empty" style="background: #e9f7ef; color: #1f5c3a;"><?php echo htmlspecialchars($flash_message, ENT_QUOTES, 'UTF-8'); ?></div>
	<?php } ?>
	<?php if (!empty($flash_error)) { ?>
		<div class="empty" style="background: #fdecea; color: #7a2d2d;"><?php echo htmlspecialchars($flash_error, ENT_QUOTES, 'UTF-8'); ?></div>
	<?php } ?>

	<?php if (empty($notifications)) { ?>
		<div class="empty" style="margin-top:14px;">
			<?php echo ($active_tab ?? 'pending') === 'reviewed' ? 'No hay notificaciones revisadas.' : 'No hay notificaciones pendientes.'; ?>
		</div>
	<?php } else { ?>
		<?php foreach ($notifications as $notification) { ?>
			<div class="panel" style="margin-top:14px; background: var(--card); box-shadow: inset 0 0 0 1px rgba(77, 116, 195, 0.12);">
				<h2 style="margin-bottom:6px;"><?php echo htmlspecialchars((string) $notification['message'], ENT_QUOTES, 'UTF-8'); ?></h2>
				<p>
					Creada por
					<strong><?php echo htmlspecialchars((string) $notification['created_by_name'], ENT_QUOTES, 'UTF-8'); ?></strong>
					el <?php echo !empty($notification['created_at']) ? date('d/m/Y h:i A', strtotime($notification['created_at'])) : '-'; ?>
				</p>
				<?php if (!empty($notification['is_reviewed'])) { ?>
					<p style="margin-top:6px;">
						Revisada por
						<strong><?php echo htmlspecialchars((string) $notification['reviewed_by_name'], ENT_QUOTES, 'UTF-8'); ?></strong>
						el <?php echo !empty($notification['reviewed_at']) ? date('d/m/Y h:i A', strtotime($notification['reviewed_at'])) : '-'; ?>
					</p>
				<?php } else { ?>
					<form method="post" action="<?php echo site_url('configuracion/notificaciones'); ?>" class="actions" style="justify-content:flex-end;">
						<input type="hidden" name="action_type" value="review" />
						<input type="hidden" name="notification_id" value="<?php echo (int) $notification['id']; ?>" />
						<button class="btn" type="submit">Revisado</button>
					</form>
				<?php } ?>
			</div>
		<?php } ?>
	<?php } ?>
</section>
