{% extends "admin/base.html" %}

{% block title %}{{ t(key="admin-blog-articles", lang=lang | default(value='sk')) }}{% endblock title %}

{% block content %}
<div class="space-y-2">
  <div class="flex flex-wrap items-center justify-between gap-3">
    <div>
      <h1 class="text-2xl font-bold">{{ t(key="admin-blog-articles", lang=lang | default(value='sk')) }}</h1>
      <p class="text-sm opacity-70">{{ t(key="admin-blog-index-desc", lang=lang | default(value='sk')) }}</p>
    </div>
    <a href="/admin/blog/articles/new" class="btn btn-neutral btn-sm">{{ t(key="new-article", lang=lang | default(value='sk')) }}</a>
  </div>

  <div class="card border border-base-300 bg-base-100 shadow-sm">
    <div class="card-body">
      {% if articles | length > 0 %}
        <div class="overflow-x-auto">
          <table class="table">
            <thead>
              <tr>
                <th>{{ t(key="title", lang=lang | default(value='sk')) }}</th>
                <th>{{ t(key="status", lang=lang | default(value='sk')) }}</th>
                <th class="text-right">{{ t(key="actions", lang=lang | default(value='sk')) }}</th>
              </tr>
            </thead>
            <tbody>
              {% for article in articles %}
                <tr>
                  <td class="font-medium">{{ article.title }}</td>
                  <td>
                    {% if article.published %}
                    <span class="badge">{{ t(key="published", lang=lang | default(value='sk')) }}</span>
                    {% else %}
                    <span class="badge opacity-70">{{ t(key="draft", lang=lang | default(value='sk')) }}</span>
                    {% endif %}
                  </td>
                  <td>
                    <div class="flex gap-2">
                      <a href="/admin/blog/articles/{{ article.id }}/edit" class="btn btn-ghost btn-sm">{{ t(key="edit", lang=lang | default(value='sk')) }}</a>
                      <form method="post" action="/admin/blog/articles/{{ article.id }}/delete">
                        <button type="submit" class="btn btn-ghost btn-sm">{{ t(key="delete", lang=lang | default(value='sk')) }}</button>
                      </form>
                    </div>
                  </td>
                </tr>
              {% endfor %}
            </tbody>
          </table>
        </div>
      {% else %}
        <div class="text-center">
          <p class="font-medium">{{ t(key="admin-no-articles", lang=lang | default(value='sk')) }}</p>
          <p class="text-sm opacity-70">{{ t(key="admin-create-first-post", lang=lang | default(value='sk')) }}</p>
          <div class="pt-2">
            <a href="/admin/blog/articles/new" class="btn btn-neutral btn-sm">{{ t(key="new-article", lang=lang | default(value='sk')) }}</a>
          </div>
        </div>
      {% endif %}
    </div>
  </div>
</div>
{% endblock content %}
