{% extends "base.html" %}

{% block title %}Admin Dashboard - {{ app_name }}{% endblock %}

{% block content %}
<div class="container-fluid">
	<div class="row">
		<div class="col-12">
			<div class="card stats-card hover-lift mb-4">
				<div class="card-body d-flex flex-column flex-md-row justify-content-between align-items-start align-items-md-center">
					<div class="mb-3 mb-md-0">
						<h1 class="h3 mb-1"><i class="fas fa-cogs me-2"></i>Admin Dashboard</h1>
						<p class="mb-0">Manage users, system settings, and core operations at a glance.</p>
					</div>
					<div class="d-flex flex-wrap gap-2">
						<a href="{{ url_for('admin.system_info') }}" class="btn btn-outline-light btn-sm">
							<i class="fas fa-info-circle"></i> System Info
						</a>
						<a href="{{ url_for('admin.backup') }}" class="btn btn-outline-light btn-sm">
							<i class="fas fa-download"></i> Create Backup
						</a>
						<a href="{{ url_for('admin.restore') }}" class="btn btn-outline-light btn-sm">
							<i class="fas fa-undo-alt"></i> Restore
						</a>
						<a href="{{ url_for('admin.license_status') }}" class="btn btn-outline-light btn-sm">
							<i class="fas fa-key"></i> License Status
						</a>
					</div>
				</div>
			</div>
		</div>
	</div>

	<!-- System Statistics -->
	<div class="row mb-4">
		<div class="col-md-3 col-sm-6 mb-3">
			<div class="card border-0 shadow-sm h-100 summary-card hover-lift">
				<div class="card-body p-3">
					<div class="d-flex align-items-center">
						<div class="flex-shrink-0">
							<div class="summary-icon bg-primary bg-opacity-10 text-primary">
								<i class="fas fa-users"></i>
							</div>
						</div>
						<div class="flex-grow-1 ms-3">
							<div class="summary-label">Total Users</div>
							<div class="summary-value">{{ stats.total_users }}</div>
						</div>
					</div>
				</div>
			</div>
		</div>
		<div class="col-md-3 col-sm-6 mb-3">
			<div class="card border-0 shadow-sm h-100 summary-card hover-lift">
				<div class="card-body p-3">
					<div class="d-flex align-items-center">
						<div class="flex-shrink-0">
							<div class="summary-icon bg-success bg-opacity-10 text-success">
								<i class="fas fa-project-diagram"></i>
							</div>
						</div>
						<div class="flex-grow-1 ms-3">
							<div class="summary-label">Total Projects</div>
							<div class="summary-value">{{ stats.total_projects }}</div>
						</div>
					</div>
				</div>
			</div>
		</div>
		<div class="col-md-3 col-sm-6 mb-3">
			<div class="card border-0 shadow-sm h-100 summary-card hover-lift">
				<div class="card-body p-3">
					<div class="d-flex align-items-center">
						<div class="flex-shrink-0">
							<div class="summary-icon bg-info bg-opacity-10 text-info">
								<i class="fas fa-clock"></i>
							</div>
						</div>
						<div class="flex-grow-1 ms-3">
							<div class="summary-label">Time Entries</div>
							<div class="summary-value">{{ stats.total_entries }}</div>
						</div>
					</div>
				</div>
			</div>
		</div>
		<div class="col-md-3 col-sm-6 mb-3">
			<div class="card border-0 shadow-sm h-100 summary-card hover-lift">
				<div class="card-body p-3">
					<div class="d-flex align-items-center">
						<div class="flex-shrink-0">
							<div class="summary-icon bg-warning bg-opacity-10 text-warning">
								<i class="fas fa-dollar-sign"></i>
							</div>
						</div>
						<div class="flex-grow-1 ms-3">
							<div class="summary-label">Total Hours</div>
							<div class="summary-value">{{ "%.1f"|format(stats.total_hours) }}h</div>
						</div>
					</div>
				</div>
			</div>
		</div>
	</div>

	<!-- Quick Actions -->
	<div class="row mb-4">
		<div class="col-md-6">
			<div class="card shadow-sm border-0 hover-lift">
				<div class="card-header bg-white py-3">
					<h6 class="m-0 font-weight-bold text-primary">
						<i class="fas fa-user-cog me-2"></i>User Management
					</h6>
				</div>
				<div class="card-body">
					<div class="d-grid gap-2">
						<a href="{{ url_for('admin.list_users') }}" class="btn btn-soft-primary">
							<i class="fas fa-users"></i> Manage Users
						</a>
						<a href="{{ url_for('admin.create_user') }}" class="btn btn-soft-success">
							<i class="fas fa-user-plus"></i> Create New User
						</a>
					</div>
				</div>
			</div>
		</div>

		<div class="col-md-6">
			<div class="card shadow-sm border-0 hover-lift">
				<div class="card-header bg-white py-3">
					<h6 class="m-0 font-weight-bold text-primary">
						<i class="fas fa-cog me-2"></i>System Settings
					</h6>
				</div>
				<div class="card-body">
					<div class="d-grid gap-2">
						<a href="{{ url_for('admin.settings') }}" class="btn btn-soft-secondary">
							<i class="fas fa-sliders-h"></i> Configure Settings
						</a>
						<a href="{{ url_for('admin.backup') }}" class="btn btn-soft-primary">
							<i class="fas fa-download"></i> Create Backup
						</a>
					</div>
				</div>
			</div>
		</div>
	</div>

	<!-- Recent Activity -->
	<div class="row">
		<div class="col-md-8">
			<div class="card shadow-sm border-0 hover-lift">
				<div class="card-header bg-white py-3">
					<h6 class="m-0 font-weight-bold text-primary">
						<i class="fas fa-history me-2"></i>Recent Activity
					</h6>
				</div>
				<div class="card-body p-0">
					{% if recent_entries %}
					<div class="table-responsive">
						<table class="table table-hover mb-0">
							<thead class="table-light">
								<tr>
									<th>User</th>
									<th>Project</th>
									<th>Date</th>
									<th>Duration</th>
									<th>Status</th>
								</tr>
							</thead>
							<tbody>
								{% for entry in recent_entries %}
								<tr>
									<td>{{ entry.user.display_name }}</td>
									<td>
										<a href="{{ url_for('projects.view_project', project_id=entry.project.id) }}">
											{{ entry.project.name }}
										</a>
									</td>
									<td>{{ entry.start_time.strftime('%Y-%m-%d %H:%M') }}</td>
									<td>
										<strong>{{ entry.duration_formatted }}</strong>
									</td>
									<td>
										{% if entry.end_time %}
										<span class="badge bg-success">Completed</span>
										{% else %}
										<span class="badge bg-warning">Running</span>
										{% endif %}
									</td>
								</tr>
								{% endfor %}
							</tbody>
						</table>
					</div>
					{% else %}
					<div class="text-center py-5">
						<div class="empty-state">
							<i class="fas fa-clock fa-3x text-muted mb-3"></i>
							<h5 class="text-muted">No recent activity</h5>
							<p class="text-muted mb-0">No time entries have been recorded recently.</p>
						</div>
					</div>
					{% endif %}
				</div>
			</div>
		</div>

		<div class="col-md-4">
			<div class="card shadow-sm border-0 mt-3">
				<div class="card-header bg-white py-3">
					<h6 class="m-0 font-weight-bold text-primary">
						<i class="fas fa-tools me-2"></i>Quick Actions
					</h6>
				</div>
				<div class="card-body">
					<div class="d-grid gap-2">
						<a href="{{ url_for('projects.create_project') }}" class="btn btn-outline-primary">
							<i class="fas fa-plus"></i> New Project
						</a>
						<a href="{{ url_for('reports.reports') }}" class="btn btn-outline-info">
							<i class="fas fa-chart-line"></i> View Reports
						</a>
						<a href="{{ url_for('admin.system_info') }}" class="btn btn-outline-secondary">
							<i class="fas fa-info-circle"></i> System Info
						</a>
						<a href="{{ url_for('admin.license_status') }}" class="btn btn-outline-info">
							<i class="fas fa-key"></i> License Status
						</a>
					</div>
				</div>
			</div>
		</div>
	</div>
</div>
{% endblock %}
