{% extends "base.html" %}

{% block title %}{{ _('Admin Dashboard') }} - {{ app_name }}{% endblock %}

{% block content %}
<div class="container-fluid">
    {% from "_components.html" import page_header %}
    <div class="row">
        <div class="col-12">
            {% set actions %}
            <a href="{{ url_for('admin.system_info') }}" class="btn btn-outline-primary me-2">
                <i class="fas fa-info-circle me-2"></i>{{ _('System Info') }}
            </a>
            <a href="{{ url_for('admin.backup') }}" class="btn btn-outline-primary me-2">
                <i class="fas fa-download me-2"></i>{{ _('Create Backup') }}
            </a>
            <a href="{{ url_for('admin.restore') }}" class="btn btn-outline-primary me-2">
                <i class="fas fa-undo-alt me-2"></i>{{ _('Restore') }}
            </a>
            <a href="{{ url_for('admin.license_status') }}" class="btn btn-outline-primary">
                <i class="fas fa-chart-bar me-2"></i>{{ _('Metrics Status') }}
            </a>
            {% endset %}
            {{ page_header('fas fa-cogs', _('Admin Dashboard'), _('Manage users, system settings, and core operations at a glance.'), actions) }}
        </div>
    </div>

    <!-- System Statistics -->
    <div class="row section-spacing">
        <div class="col-md-3 col-sm-6 mb-3">
            {% from "_components.html" import summary_card %}
            {{ summary_card('fas fa-users', 'primary', 'Total Users', stats.total_users) }}
        </div>
        <div class="col-md-3 col-sm-6 mb-3">
            {{ summary_card('fas fa-project-diagram', 'success', 'Total Projects', stats.total_projects) }}
        </div>
        <div class="col-md-3 col-sm-6 mb-3">
            {{ summary_card('fas fa-clock', 'info', 'Time Entries', stats.total_entries) }}
        </div>
        <div class="col-md-3 col-sm-6 mb-3">
            {{ summary_card('fas fa-stopwatch', 'warning', 'Total Hours', "%.1f"|format(stats.total_hours) ~ 'h') }}
        </div>
    </div>

    <!-- Quick Actions -->
    <div class="row section-spacing">
        <div class="col-md-6 mb-4">
            <div class="card hover-lift">
                <div class="card-header">
                    <h5 class="mb-0 d-flex align-items-center">
                        <i class="fas fa-user-cog me-2 text-primary"></i>{{ _('User Management') }}
                    </h5>
                </div>
                <div class="card-body">
                    <div class="d-grid gap-2">
                        <a href="{{ url_for('admin.list_users') }}" class="btn btn-primary">
                            <i class="fas fa-users me-2"></i>{{ _('Manage Users') }}
                        </a>
                        <a href="{{ url_for('admin.create_user') }}" class="btn btn-success">
                            <i class="fas fa-user-plus me-2"></i>{{ _('Create New User') }}
                        </a>
                    </div>
                </div>
            </div>
        </div>
        <div class="col-md-6 mb-4">
            <div class="card hover-lift">
                <div class="card-header">
                    <h5 class="mb-0 d-flex align-items-center">
                        <i class="fas fa-cog me-2 text-primary"></i>{{ _('System Settings') }}
                    </h5>
                </div>
                <div class="card-body">
                    <div class="d-grid gap-2">
                        <a href="{{ url_for('admin.settings') }}" class="btn btn-outline-primary">
                            <i class="fas fa-sliders-h me-2"></i>{{ _('Configure Settings') }}
                        </a>
                        <a href="{{ url_for('admin.backup') }}" class="btn btn-outline-primary">
                            <i class="fas fa-download me-2"></i>{{ _('Create Backup') }}
                        </a>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <!-- Recent Activity -->
    <div class="row">
        <div class="col-md-8 mb-4">
            <div class="card hover-lift">
                <div class="card-header">
                    <h5 class="mb-0 d-flex align-items-center">
                        <i class="fas fa-history me-2 text-primary"></i>{{ _('Recent Activity') }}
                    </h5>
                </div>
                <div class="card-body p-0">
                    {% if recent_entries %}
                    <div class="table-responsive">
                        <table class="table table-hover mb-0">
                            <thead>
                                <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>{{ entry.duration_formatted }}</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-chart-line"></i> {{ _('Metrics Status') }}
						</a>
					</div>
				</div>
			</div>
		</div>
	</div>
</div>
{% endblock %}
