{% extends "layouts/base.html" %}
{% load i18n %}

{% block title %}{% trans "Project Templates" %} - PX360{% endblock %}

{% block extra_css %}
<style>
    /* Page Header Gradient */
    .page-header-gradient {
        background: linear-gradient(135deg, #005696 0%, #0069a8 50%, #007bbd 100%);
        color: white;
        padding: 1.5rem 2rem;
        border-radius: 1rem;
        margin-bottom: 1.5rem;
        box-shadow: 0 10px 15px -3px rgba(0, 86, 150, 0.2);
    }

    /* Section Cards */
    .section-card {
        background: white;
        border-radius: 1rem;
        border: 2px solid #e2e8f0;
        box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
        overflow: hidden;
        transition: all 0.3s ease;
    }
    .section-card:hover {
        border-color: #005696;
        box-shadow: 0 10px 25px -5px rgba(0, 86, 150, 0.15);
    }

    .section-header {
        padding: 1rem 1.5rem;
        border-bottom: 2px solid #e2e8f0;
        background: linear-gradient(to right, #f8fafc, #f1f5f9);
        display: flex;
        align-items: center;
        gap: 0.75rem;
    }

    .section-icon {
        width: 40px;
        height: 40px;
        border-radius: 0.75rem;
        display: flex;
        align-items: center;
        justify-content: center;
    }
</style>
{% endblock %}

{% block content %}
<!-- Page Header Gradient -->
<div class="page-header-gradient">
    <div class="flex justify-between items-start">
        <div>
            <h1 class="text-2xl font-bold flex items-center gap-3">
                <i data-lucide="layout-template" class="w-7 h-7"></i>
                {% trans "Project Templates" %}
            </h1>
            <p class="text-sm opacity-90 mt-1">{% trans "Reusable templates for quality improvement projects" %}</p>
        </div>
        <div class="flex items-center gap-3">
            <a href="{% url 'projects:project_list' %}" class="bg-white/20 text-white border-2 border-white/30 px-4 py-2 rounded-xl text-sm font-bold hover:bg-white hover:text-[#005696] flex items-center gap-2 transition">
                <i data-lucide="kanban" class="w-4 h-4"></i> {% trans "View Projects" %}
            </a>
            {% if can_create %}
            <a href="{% url 'projects:template_create' %}" class="bg-white text-[#005696] px-4 py-2 rounded-xl text-sm font-bold shadow-lg hover:bg-white/90 flex items-center gap-2 transition">
                <i data-lucide="plus" class="w-4 h-4"></i> {% trans "New Template" %}
            </a>
            {% endif %}
        </div>
    </div>
</div>

<!-- Templates Grid -->
{% if templates %}
<div class="grid grid-cols-3 gap-6">
    {% for template in templates %}
    <div class="section-card overflow-hidden hover:shadow-md transition-shadow">
        <div class="p-6">
            <div class="flex items-start justify-between mb-3">
                <div class="flex items-center gap-3">
                    <div class="section-icon bg-blue/10">
                        <i data-lucide="layout-template" class="w-5 h-5 text-blue"></i>
                    </div>
                    <div>
                        <h3 class="font-bold text-navy">{{ template.name }}</h3>
                        {% if template.is_active %}
                        <span class="text-[10px] font-bold text-green-600 uppercase">{% trans "Active" %}</span>
                        {% else %}
                        <span class="text-[10px] font-bold text-slate uppercase">{% trans "Inactive" %}</span>
                        {% endif %}
                    </div>
                </div>
            </div>
            
            {% if template.description %}
            <p class="text-xs text-slate mb-4 line-clamp-2">{{ template.description }}</p>
            {% endif %}
            
            <div class="flex items-center gap-4 text-xs text-slate mb-4">
                <span class="flex items-center gap-1">
                    <i data-lucide="check-square" class="w-3 h-3"></i>
                    {{ template.tasks.count }} {% trans "tasks" %}
                </span>
                <span class="flex items-center gap-1">
                    <i data-lucide="calendar" class="w-3 h-3"></i>
                    {{ template.created_at|date:"M d, Y" }}
                </span>
            </div>
            
            <div class="flex items-center gap-2 pt-4 border-t">
                {% if can_edit %}
                <a href="{% url 'projects:template_detail' pk=template.pk %}" class="flex-1 bg-blue/10 text-blue text-center px-3 py-2 rounded-lg text-xs font-bold hover:bg-blue/20 transition">
                    {% trans "View" %}
                </a>
                {% else %}
                <a href="{% url 'projects:template_detail' pk=template.pk %}" class="flex-1 bg-slate-100 text-slate text-center px-3 py-2 rounded-lg text-xs font-bold hover:bg-slate-200 transition">
                    {% trans "View" %}
                </a>
                {% endif %}
                <a href="{% url 'projects:project_create_from_template' template_pk=template.pk %}" class="flex-1 bg-[#005696] text-white text-center px-3 py-2 rounded-lg text-xs font-bold hover:bg-[#0069a8] transition">
                    {% trans "Use" %}
                </a>
            </div>
        </div>
    </div>
    {% endfor %}
</div>
{% else %}
<div class="section-card p-12 text-center">
    <div class="section-icon bg-[#005696] mx-auto mb-4 w-16 h-16">
        <i data-lucide="layout-template" class="w-8 h-8 text-white"></i>
    </div>
    <h3 class="text-lg font-bold text-navy mb-2">{% trans "No Templates Yet" %}</h3>
    <p class="text-sm text-slate mb-6">{% trans "Create templates to quickly start new quality improvement projects" %}</p>
    {% if can_create %}
    <a href="{% url 'projects:template_create' %}" class="bg-[#005696] text-white px-5 py-2.5 rounded-xl text-sm font-bold shadow-lg shadow-[#005696]/20 hover:bg-[#0069a8] inline-flex items-center gap-2 transition">
        <i data-lucide="plus" class="w-4 h-4"></i> {% trans "Create First Template" %}
    </a>
    {% endif %}
</div>
{% endif %}
{% endblock %}
