{% extends 'base.html' %}
{% load static %}

{% block title %}Dashboard - webFirma{% endblock %}

{% block content %}
<div class="main-header">
  <h1>Dashboard</h1>
  <div class="header-actions">
    <div class="search-bar">
        <i data-feather="search"></i>
        <input type="text" placeholder="Search projects...">
    </div>
    {% if user.is_authenticated %}
    <a href="{% url 'add_project' %}" class="btn btn-primary"><i data-feather="plus"></i> Add project</a>
    {% endif %}
  </div>
</div>

<div class="analytics-grid">
    <div class="stat-card">
        <div class="stat-info">
            <h3>Total projects</h3>
            <p class="stat-number">{{ total_projects }}</p>
        </div>
        <div class="stat-icon">
            <i data-feather="archive"></i>
        </div>
    </div>
    <div class="stat-card planned">
        <div class="stat-info">
            <h3>Planned</h3>
            <p class="stat-number">{{ planned_projects }}</p>
        </div>
        <div class="stat-icon">
            <i data-feather="calendar"></i>
        </div>
    </div>
    <div class="stat-card in-progress">
        <div class="stat-info">
            <h3>In progress</h3>
            <p class="stat-number">{{ in_progress_projects }}</p>
        </div>
        <div class="stat-icon">
            <i data-feather="trending-up"></i>
        </div>
    </div>
    <div class="stat-card completed">
        <div class="stat-info">
            <h3>Completed</h3>
            <p class="stat-number">{{ completed_projects }}</p>
        </div>
        <div class="stat-icon">
            <i data-feather="check-circle"></i>
        </div>
    </div>
</div>

<div class="content-grid">
    {% if request.path == '/projects/' %}
    <div class="project-list-header">
        <h2>All Projects</h2>
    </div>
    {% endif %}
    {% if projects %}
        {% for project in projects %}
            <div class="project-card">
                <div class="card-header">
                    <h3>{{ project.name }}</h3>
                    <span class="badge status-{{ project.status|lower }}">{{ project.get_status_display }}</span>
                </div>
                <div class="card-body">
                    <p><strong>Client:</strong> {{ project.client.name }}</p>
                    <p><strong>Period:</strong> {{ project.start_date|date:"d M Y" }} - {{ project.end_date|date:"d M Y" }}</p>
                </div>
                <div class="card-footer">

                    {% if user.is_authenticated %}
                    <a href="{% url 'edit_project' project.id %}" class="btn-view">Edit</a>
                    <a href="{% url 'delete_project' project.id %}" class="btn-view">Delete</a>
                    {% endif %}
                </div>
            </div>
        {% endfor %}
    {% else %}
    <div class="empty-state">
        <div class="empty-state-icon">
            <i data-feather="briefcase"></i>
        </div>
        <h2>No projects yet</h2>
        <p>You don't have any projects yet. Add your first project to get started.</p>
        <a href="{% url 'add_project' %}" class="btn btn-primary">Add project</a>
    </div>
    {% endif %}
</div>
{% endblock %}
