{% extends "base.html" %}

{% block title %}{{ _('Finished Tasks Report') }} - {{ app_name }}{% endblock %}

{% block content %}
<div class="container-fluid">
    <div class="row">
        <div class="col-12">
            <div class="d-flex justify-content-between align-items-center mb-4">
                <div>
                    <nav aria-label="breadcrumb">
                        <ol class="breadcrumb">
                            <li class="breadcrumb-item"><a href="{{ url_for('reports.reports') }}">{{ _('Reports') }}</a></li>
                            <li class="breadcrumb-item active">{{ _('Finished Tasks') }}</li>
                        </ol>
                    </nav>
                    <h1 class="h3 mb-0">
                        <i class="fas fa-tasks text-primary"></i> {{ _('Finished Tasks Report') }}
                    </h1>
                </div>
            </div>
        </div>
    </div>

    <!-- Filters -->
    <div class="row mb-4">
        <div class="col-12">
            <div class="card border-0 shadow-sm">
                <div class="card-header bg-white">
                    <h5 class="mb-0">
                        <i class="fas fa-filter"></i> {{ _('Filters') }}
                    </h5>
                </div>
                <div class="card-body">
                    <form method="GET" class="row g-3">
                        <div class="col-md-3">
                            <label for="start_date" class="form-label">{{ _('Start Date') }}</label>
                            <input type="date" class="form-control" id="start_date" name="start_date" 
                                   value="{{ start_date or '' }}">
                        </div>
                        <div class="col-md-3">
                            <label for="end_date" class="form-label">{{ _('End Date') }}</label>
                            <input type="date" class="form-control" id="end_date" name="end_date" 
                                   value="{{ end_date or '' }}">
                        </div>
                        <div class="col-md-3">
                            <label for="project" class="form-label">{{ _('Project') }}</label>
                            <select class="form-select" id="project" name="project_id">
                                <option value="">{{ _('All Projects') }}</option>
                                {% for project in projects %}
                                <option value="{{ project.id }}" {% if selected_project|int == project.id %}selected{% endif %}>
                                    {{ project.name }}
                                </option>
                                {% endfor %}
                            </select>
                        </div>
                        <div class="col-md-3">
                            <label for="user" class="form-label">{{ _('User') }}</label>
                            <select class="form-select" id="user" name="user_id">
                                <option value="">{{ _('All Users') }}</option>
                                {% for user in users %}
                                <option value="{{ user.id }}" {% if selected_user|int == user.id %}selected{% endif %}>
                                    {{ user.display_name }}
                                </option>
                                {% endfor %}
                            </select>
                        </div>
                        <div class="col-12">
                            <button type="submit" class="btn btn-primary">
                                <i class="fas fa-search"></i> {{ _('Apply Filters') }}
                            </button>
                            <a href="{{ url_for('reports.task_report') }}" class="btn btn-outline-secondary">
                                <i class="fas fa-times"></i> {{ _('Clear') }}
                            </a>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>

    <!-- Summary 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">
                <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-tasks"></i>
                            </div>
                        </div>
                        <div class="flex-grow-1 ms-3">
                            <div class="summary-label">{{ _('Finished Tasks') }}</div>
                            <div class="summary-value">{{ summary.tasks_count }}</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-clock"></i>
                            </div>
                        </div>
                        <div class="flex-grow-1 ms-3">
                            <div class="summary-label">{{ _('Total Hours') }}</div>
                            <div class="summary-value">{{ "%.2f"|format(summary.total_hours) }}h</div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <!-- Finished Tasks Table -->
    <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-list"></i> {{ _('Finished Tasks') }} ({{ tasks|length }})
                    </h5>
                </div>
                <div class="card-body p-0">
                    {% if tasks %}
                    <div class="table-responsive">
                        <table class="table table-hover mb-0">
                            <thead class="table-light">
                                <tr>
                                    <th>{{ _('Task') }}</th>
                                    <th>{{ _('Project') }}</th>
                                    <th>{{ _('Assignee') }}</th>
                                    <th>{{ _('Completed') }}</th>
                                    <th>{{ _('Hours') }}</th>
                                    <th>{{ _('Entries') }}</th>
                                    <th>{{ _('Actions') }}</th>
                                </tr>
                            </thead>
                            <tbody>
                                {% for row in tasks %}
                                <tr>
                                    <td>
                                        <div>
                                            <strong>{{ row.task.name }}</strong>
                                            {% if row.task.description %}
                                            <br><small class="text-muted">{{ row.task.description[:60] }}{% if row.task.description|length > 60 %}...{% endif %}</small>
                                            {% endif %}
                                        </div>
                                    </td>
                                    <td>
                                        <a href="{{ url_for('projects.view_project', project_id=row.project.id) }}">
                                            {{ row.project.name }}
                                        </a>
                                    </td>
                                    <td>
                                        {% if row.assignee %}
                                        {{ row.assignee.display_name }}
                                        {% else %}
                                        <span class="text-muted">{{ _('Unassigned') }}</span>
                                        {% endif %}
                                    </td>
                                    <td>
                                        {% if row.completed_at %}
                                        {{ row.completed_at.strftime('%Y-%m-%d') }}
                                        {% else %}
                                        <span class="text-muted">-</span>
                                        {% endif %}
                                    </td>
                                    <td><strong>{{ "%.2f"|format(row.hours) }}h</strong></td>
                                    <td>{{ row.entries_count }}</td>
                                    <td>
                                        <a href="{{ url_for('tasks.view_task', task_id=row.task.id) }}" class="btn btn-sm btn-outline-primary">
                                            <i class="fas fa-eye"></i>
                                        </a>
                                    </td>
                                </tr>
                                {% endfor %}
                            </tbody>
                        </table>
                    </div>
                    {% else %}
                    <div class="text-center py-5">
                        <div class="empty-state">
                            <i class="fas fa-tasks fa-3x text-muted mb-3"></i>
                            <h5 class="text-muted">{{ _('No Finished Tasks Found') }}</h5>
                            <p class="text-muted">{{ _('Try adjusting your filters.') }}</p>
                        </div>
                    </div>
                    {% endif %}
                </div>
            </div>
        </div>
    </div>
</div>
{% endblock %}


