{% extends "pi_fyad/base.html" %}
{% load pi_fyad_tags %}

{% block pi_content %}

<div class="d-flex justify-content-between align-items-center mb-4">
    <h4><i class="fas fa-clipboard-list me-2"></i>Planet Templates</h4>
    {% if perms.pi_fyad.manage_templates %}
    <a href="{% url 'pi_fyad:template_create' %}" class="btn btn-primary">
        <i class="fas fa-plus me-1"></i>New Template
    </a>
    {% endif %}
</div>

<div class="row">
    {% for template in templates %}
    <div class="col-lg-6 col-xl-4 mb-4">
        <div class="card pi-card h-100">
            <div class="card-header d-flex align-items-center justify-content-between">
                <div>
                    {% eve_planet_image template.planet_type_id 28 %}
                    <strong class="ms-2">{{ template.name }}</strong>
                </div>
                <span class="badge bg-{% if template.visibility == 'public' %}success{% elif template.visibility == 'alliance' %}primary{% elif template.visibility == 'corp' %}info{% else %}secondary{% endif %}">
                    {{ template.get_visibility_display }}
                </span>
            </div>
            <div class="card-body">
                {% if template.description %}
                <p class="card-text small text-muted mb-3">{{ template.description|truncatewords:30 }}</p>
                {% endif %}

                <div class="row text-center small">
                    <div class="col-4">
                        <div class="fw-bold">{{ template.pin_count }}</div>
                        <div class="text-muted">Pins</div>
                    </div>
                    <div class="col-4">
                        <div class="fw-bold">{{ template.factory_count }}</div>
                        <div class="text-muted">Factories</div>
                    </div>
                    <div class="col-4">
                        <div class="fw-bold">{{ template.extractor_count }}</div>
                        <div class="text-muted">Extractors</div>
                    </div>
                </div>

                {% if template.output_products %}
                <div class="mt-3">
                    <small class="text-muted">Outputs:</small>
                    {% for product in template.output_products %}
                    <span class="badge bg-outline-secondary ms-1">{{ product }}</span>
                    {% endfor %}
                </div>
                {% endif %}
            </div>
            <div class="card-footer d-flex justify-content-between align-items-center">
                <small class="text-muted">
                    {% if template.created_by %}
                    {% eve_character_portrait template.created_by.character_id 20 %}
                    {{ template.created_by.character_name }}
                    {% endif %}
                </small>
                <a href="{% url 'pi_fyad:template_detail' template.pk %}"
                   class="btn btn-sm btn-outline-primary">
                    <i class="fas fa-eye me-1"></i>View
                </a>
            </div>
        </div>
    </div>
    {% empty %}
    <div class="col-12">
        <div class="alert alert-info">
            <i class="fas fa-info-circle me-2"></i>
            No templates found. Create one by pasting your PI clipboard export.
        </div>
    </div>
    {% endfor %}
</div>

{% endblock %}
