{% extends "admin/base.html" %}
{% load i18n %}
{% block content %}
<div class="portal-v4-page portal-template-center">
  <section class="portal-v4-hero portal-template-hero">
    <div>
      <span class="portal-eyebrow">BIBLIOTECA KREATE4WEB</span>
      <h1>Centro de templates</h1>
      <p>Aceda num único local aos modelos de email, respostas, documentos, checklists e formulários reutilizáveis.</p>
    </div>
    <div class="portal-v4-actions">
      <a href="{% url 'admin:notifications_notificationtemplate_add' %}"><span class="material-symbols-outlined">add_email</span>Novo email</a>
      <a href="{% url 'admin:template_library_reusabletemplate_add' %}"><span class="material-symbols-outlined">note_add</span>Novo conteúdo</a>
      <a href="{% url 'admin:template_library_formtemplate_add' %}"><span class="material-symbols-outlined">post_add</span>Novo formulário</a>
    </div>
  </section>

  <div class="portal-v4-kpis portal-template-kpis">
    <a href="{% url 'admin:notifications_notificationtemplate_changelist' %}"><span class="material-symbols-outlined">mail</span><small>Templates de email</small><strong>{{ counts.emails }}</strong></a>
    <a href="{% url 'admin:template_library_reusabletemplate_changelist' %}"><span class="material-symbols-outlined">content_copy</span><small>Conteúdos reutilizáveis</small><strong>{{ counts.reusable }}</strong></a>
    <a href="{% url 'admin:template_library_formtemplate_changelist' %}"><span class="material-symbols-outlined">dynamic_form</span><small>Formulários</small><strong>{{ counts.forms }}</strong></a>
    <div class="is-success"><span class="material-symbols-outlined">verified</span><small>Ativos</small><strong>{{ counts.active }}</strong></div>
  </div>

  <section class="portal-v4-panel portal-template-categories">
    <header><div><span>ORGANIZAÇÃO</span><h2>Categorias</h2></div><a href="{% url 'admin:template_library_templatecategory_changelist' %}">Gerir categorias</a></header>
    <div class="portal-template-category-grid">
      {% for category in categories %}
      <div class="portal-template-category-card tone-{{ category.tone }}">
        <span class="material-symbols-outlined">{{ category.icon }}</span>
        <div><strong>{{ category.name }}</strong><small>{{ category.description|default:"Categoria de conteúdos"|truncatechars:80 }}</small></div>
      </div>
      {% empty %}<p class="portal-v4-empty">Ainda não existem categorias.</p>{% endfor %}
    </div>
  </section>

  <div class="portal-v4-grid portal-v4-grid-3 portal-template-columns">
    <section class="portal-v4-panel">
      <header><div><span>EMAIL</span><h2>Modelos de comunicação</h2></div><a href="{% url 'admin:notifications_notificationtemplate_changelist' %}">Ver todos</a></header>
      <div class="portal-v4-list compact">
        {% for item in email_templates %}
        <a href="{% url 'admin:notifications_notificationtemplate_change' item.pk %}">
          <i class="material-symbols-outlined">drafts</i>
          <div><strong>{{ item.subject_template }}</strong><small>{{ item.get_notification_type_display }} · {{ item.code }}</small></div>
          <b>{% if item.is_active %}Ativo{% else %}Inativo{% endif %}</b>
        </a>
        {% empty %}<p class="portal-v4-empty">Sem modelos de email.</p>{% endfor %}
      </div>
    </section>

    <section class="portal-v4-panel">
      <header><div><span>CONTEÚDO</span><h2>Textos reutilizáveis</h2></div><a href="{% url 'admin:template_library_reusabletemplate_changelist' %}">Ver todos</a></header>
      <div class="portal-v4-list compact">
        {% for item in reusable_templates %}
        <a href="{% url 'reusable_template_preview' item.pk %}">
          <i class="material-symbols-outlined">content_copy</i>
          <div><strong>{{ item.name }}</strong><small>{{ item.get_kind_display }} · {{ item.category|default:"Sem categoria" }}</small></div>
          <b>{{ item.usage_count }}×</b>
        </a>
        {% empty %}<p class="portal-v4-empty">Sem conteúdos reutilizáveis.</p>{% endfor %}
      </div>
    </section>

    <section class="portal-v4-panel">
      <header><div><span>FORMULÁRIOS</span><h2>Estruturas de recolha</h2></div><a href="{% url 'admin:template_library_formtemplate_changelist' %}">Ver todos</a></header>
      <div class="portal-v4-list compact">
        {% for item in forms %}
        <a href="{% url 'form_template_preview' item.pk %}">
          <i class="material-symbols-outlined">dynamic_form</i>
          <div><strong>{{ item.name }}</strong><small>{{ item.get_purpose_display }} · v{{ item.version }}</small></div>
          <b>{{ item.active_fields_count }} campos</b>
        </a>
        {% empty %}<p class="portal-v4-empty">Sem formulários configurados.</p>{% endfor %}
      </div>
    </section>
  </div>
</div>
{% endblock %}
