{% extends "base.html" %}

{% block title %}Reports - {{ 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('reports.export_csv') }}" class="btn btn-outline-light btn-sm">
                <i class="fas fa-download"></i> Export CSV
            </a>
            {% endset %}
            {{ page_header('fas fa-chart-line', 'Reports', 'Analytics and summaries at a glance', actions) }}
        </div>
    </div>

    <!-- Summary Cards -->
    <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">
                <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-clock"></i>
                            </div>
                        </div>
                        <div class="flex-grow-1 ms-3">
                            <div class="summary-label">Total Hours</div>
                            <div class="summary-value">{{ "%.1f"|format(summary.total_hours) }}h</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">
                <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-dollar-sign"></i>
                            </div>
                        </div>
                        <div class="flex-grow-1 ms-3">
                            <div class="summary-label">Billable Hours</div>
                            <div class="summary-value">{{ "%.1f"|format(summary.billable_hours) }}h</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">
                <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-project-diagram"></i>
                            </div>
                        </div>
                        <div class="flex-grow-1 ms-3">
                            <div class="summary-label">Active Projects</div>
                            <div class="summary-value">{{ summary.active_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">
                <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-users"></i>
                            </div>
                        </div>
                        <div class="flex-grow-1 ms-3">
                            <div class="summary-label">Users</div>
                            <div class="summary-value">{{ summary.total_users }}</div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <!-- Report Options -->
    <div class="row">
        <div class="col-md-6 mb-4">
            <div class="card h-100 border-0 shadow-sm hover-lift">
                <div class="card-header bg-white">
                    <h5 class="mb-0">
                        <i class="fas fa-project-diagram"></i> Project Reports
                    </h5>
                </div>
                <div class="card-body">
                    <p class="text-muted">Generate detailed reports by project with time breakdowns and user statistics.</p>
                    <div class="d-grid">
                        <a href="{{ url_for('reports.project_report') }}" class="btn btn-primary">
                            <i class="fas fa-chart-bar"></i> Project Report
                        </a>
                        <a href="{{ url_for('reports.task_report') }}" class="btn btn-outline-primary mt-2">
                            <i class="fas fa-tasks"></i> Finished Tasks Report
                        </a>
                    </div>
                </div>
            </div>
        </div>

        <div class="col-md-6 mb-4">
            <div class="card h-100 border-0 shadow-sm hover-lift">
                <div class="card-header bg-white">
                    <h5 class="mb-0">
                        <i class="fas fa-user"></i> User Reports
                    </h5>
                </div>
                <div class="card-body">
                    <p class="text-muted">View time tracking statistics by user with project breakdowns and productivity metrics.</p>
                    <div class="d-grid">
                        <a href="{{ url_for('reports.user_report') }}" class="btn btn-primary">
                            <i class="fas fa-chart-pie"></i> User Report
                        </a>
                    </div>
                </div>
            </div>
        </div>

        <div class="col-md-6 mb-4">
            <div class="card h-100 border-0 shadow-sm hover-lift">
                <div class="card-header bg-white">
                    <h5 class="mb-0">
                        <i class="fas fa-calendar-alt"></i> Summary Report
                    </h5>
                </div>
                <div class="card-body">
                    <p class="text-muted">Get an overview of key metrics including total hours, billable amounts, and trends.</p>
                    <div class="d-grid">
                        <a href="{{ url_for('reports.summary_report') }}" class="btn btn-primary">
                            <i class="fas fa-chart-line"></i> Summary Report
                        </a>
                    </div>
                </div>
            </div>
        </div>

        <div class="col-md-6 mb-4">
            <div class="card h-100 border-0 shadow-sm hover-lift">
                <div class="card-header bg-white">
                    <h5 class="mb-0">
                        <i class="fas fa-chart-line"></i> Visual Analytics
                    </h5>
                </div>
                <div class="card-body">
                    <p class="text-muted">Interactive charts and graphs for better data visualization and insights.</p>
                    <div class="d-grid">
                        <a href="{{ url_for('analytics.analytics_dashboard') }}" class="btn btn-primary">
                            <i class="fas fa-chart-area"></i> View Analytics
                        </a>
                    </div>
                </div>
            </div>
        </div>
        
        <div class="col-md-6 mb-4">
            <div class="card h-100 border-0 shadow-sm hover-lift">
                <div class="card-header bg-white">
                    <h5 class="mb-0">
                        <i class="fas fa-download"></i> Data Export
                    </h5>
                </div>
                <div class="card-body">
                    <p class="text-muted">Export time entries to CSV format for external analysis or backup purposes.</p>
                    <div class="d-grid">
                        <a href="{{ url_for('reports.export_csv') }}" class="btn btn-outline-primary">
                            <i class="fas fa-file-csv"></i> Export CSV
                        </a>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <!-- Recent Activity -->
    <div class="row">
        <div class="col-12">
            <div class="card shadow-sm border-0">
                <div class="card-header bg-white py-3">
                    <h5 class="mb-0">
                        <i class="fas fa-history"></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 class="table-light">
                                <tr>
                                    <th>User</th>
                                    <th>Project</th>
                                    <th>Date</th>
                                    <th>Duration</th>
                                    <th>Notes</th>
                                    <th>Billable</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') }}</td>
                                    <td>
                                        <strong>{{ entry.duration_formatted }}</strong>
                                    </td>
                                    <td>
                                        {% if entry.notes %}
                                        <span title="{{ entry.notes }}">{{ entry.notes[:50] }}{% if entry.notes|length > 50 %}...{% endif %}</span>
                                        {% else %}
                                        <span class="text-muted">-</span>
                                        {% endif %}
                                    </td>
                                    <td>
                                        {% if entry.billable %}
                                        <span class="badge bg-success">Yes</span>
                                        {% else %}
                                        <span class="badge bg-secondary">No</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">No time entries have been recorded recently.</p>
                        </div>
                    </div>
                    {% endif %}
                </div>
            </div>
        </div>
    </div>
</div>
{% endblock %}
