package views

templ BaseLayout(title string, content templ.Component) {
	<!DOCTYPE html>
	<html lang="en">
	<head>
		<meta charset="UTF-8" />
		<meta name="viewport" content="width=device-width, initial-scale=1.0" />
		<title>{ title } - Nerd Monitor</title>
		<script src="https://unpkg.com/htmx.org@2.0.4"></script>
		<script>
			document.addEventListener('DOMContentLoaded', function() {
				// Connect to Server-Sent Events for real-time updates
				const eventSource = new EventSource('/api/events');
				eventSource.onmessage = function(event) {
					console.log('SSE message received:', event.data);
				};
				eventSource.addEventListener('stats-update', function(event) {
					console.log('Stats update event:', event.data);
					// Trigger HTMX updates using HTMX's API
					const agentTable = document.getElementById('agent-table-container');
					const cpuStats = document.getElementById('cpu-stats');
					if (agentTable) htmx.trigger(agentTable, 'stats-update');
					if (cpuStats) htmx.trigger(cpuStats, 'stats-update');
				});
				eventSource.addEventListener('connected', function(event) {
					console.log('SSE connected');
				});
				eventSource.onerror = function(event) {
					console.log('SSE error:', event);
				};
			});
		</script>
		<style>
			* {
				margin: 0;
				padding: 0;
				box-sizing: border-box;
			}
			
			body {
				font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
				background-color: #0f172a;
				color: #e2e8f0;
				line-height: 1.5;
				min-height: 100vh;
			}
			
			header {
				background-color: #1e293b;
				border-bottom: 1px solid #334155;
				padding: 1rem 2rem;
				box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
			}
			
			.header-container {
				max-width: 1400px;
				margin: 0 auto;
				display: flex;
				justify-content: space-between;
				align-items: center;
			}
			
			h1 {
				font-size: 1.5rem;
				font-weight: 600;
			}
			
			.nav-links {
				display: flex;
				gap: 1rem;
				align-items: center;
			}
			
			a {
				color: #3b82f6;
				text-decoration: none;
				transition: color 0.2s;
			}
			
			a:hover {
				color: #60a5fa;
			}
			
			main {
				max-width: 1400px;
				margin: 0 auto;
				padding: 2rem;
			}
			
			.container {
				width: 100%;
			}
			
			.grid {
				display: grid;
				grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
				gap: 1.5rem;
				margin-top: 1.5rem;
			}
			
			.card {
				background-color: #1e293b;
				border: 1px solid #334155;
				border-radius: 0.5rem;
				padding: 1.5rem;
				box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
				transition: border-color 0.2s;
			}
			
			.card:hover {
				border-color: #3b82f6;
			}
			
			.card-title {
				font-size: 1.125rem;
				font-weight: 600;
				margin-bottom: 1rem;
				display: flex;
				justify-content: space-between;
				align-items: center;
			}
			
			.status-badge {
				display: inline-block;
				padding: 0.25rem 0.75rem;
				border-radius: 9999px;
				font-size: 0.875rem;
				font-weight: 500;
			}
			
			.status-green {
				background-color: #10b981;
				color: #ffffff;
			}
			
			.status-yellow {
				background-color: #f59e0b;
				color: #ffffff;
			}
			
			.status-red {
				background-color: #ef4444;
				color: #ffffff;
			}
			
			.metric-row {
				display: flex;
				justify-content: space-between;
				padding: 0.75rem 0;
				border-bottom: 1px solid #334155;
			}
			
			.metric-row:last-child {
				border-bottom: none;
			}
			
			.metric-label {
				color: #94a3b8;
				font-size: 0.875rem;
			}
			
			.metric-value {
				font-weight: 600;
				color: #e2e8f0;
			}
			
			.progress-bar {
				width: 100%;
				height: 8px;
				background-color: #334155;
				border-radius: 4px;
				overflow: hidden;
				margin-top: 0.5rem;
			}
			
			.progress-fill {
				height: 100%;
				background-color: #3b82f6;
				transition: width 0.3s;
			}
			
			.progress-high {
				background-color: #ef4444;
			}
			
			.progress-medium {
				background-color: #f59e0b;
			}
			
			.btn {
				display: inline-block;
				padding: 0.5rem 1rem;
				background-color: #3b82f6;
				color: #ffffff;
				border: none;
				border-radius: 0.375rem;
				cursor: pointer;
				font-size: 0.875rem;
				font-weight: 500;
				transition: background-color 0.2s;
				text-decoration: none;
			}
			
			.btn:hover {
				background-color: #2563eb;
			}
			
			.btn-danger {
				background-color: #ef4444;
			}
			
			.btn-danger:hover {
				background-color: #dc2626;
			}
			
			.btn-group {
				display: flex;
				gap: 0.5rem;
				margin-top: 1rem;
			}
			
			.alert {
				padding: 1rem;
				border-radius: 0.375rem;
				margin-bottom: 1.5rem;
				border-left: 4px solid;
			}
			
			.alert-warning {
				background-color: #7c2d12;
				border-color: #f59e0b;
				color: #fed7aa;
			}
			
			.alert-info {
				background-color: #0c4a6e;
				border-color: #3b82f6;
				color: #bfdbfe;
			}
			
			table {
				width: 100%;
				border-collapse: collapse;
				margin-top: 1rem;
			}
			
			th {
				background-color: #334155;
				padding: 1rem;
				text-align: left;
				font-weight: 600;
				border-bottom: 1px solid #475569;
				font-size: 0.875rem;
				color: #cbd5e1;
			}
			
			td {
				padding: 1rem;
				border-bottom: 1px solid #334155;
			}
			
			tr:hover {
				background-color: #1e293b;
			}
			
			.timestamp {
				color: #94a3b8;
				font-size: 0.875rem;
			}
			
			.logout-btn {
				background-color: #64748b;
				color: #ffffff;
				padding: 0.5rem 1rem;
				border: none;
				border-radius: 0.375rem;
				cursor: pointer;
				font-size: 0.875rem;
				font-weight: 500;
				transition: background-color 0.2s;
				text-decoration: none;
			}
			
			.logout-btn:hover {
				background-color: #475569;
			}
			
			.back-link {
				display: inline-block;
				margin-bottom: 1rem;
				color: #3b82f6;
				text-decoration: none;
			}
			
			.back-link:hover {
				text-decoration: underline;
			}
		</style>
	</head>
	<body>
		<header>
			<div class="header-container">
				<h1>Nerd Monitor</h1>
				<div class="nav-links">
					<a href="/">Dashboard</a>
					<form method="POST" action="/logout" style="margin: 0;">
						<button type="submit" class="logout-btn">Logout</button>
					</form>
				</div>
			</div>
		</header>
		<main>
			<div class="container">
				@content
			</div>
		</main>
	</body>
	</html>
}
