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

{% block title %}{{ t(key="songs-title-admin", lang=lang | default(value='sk')) }}{% endblock title %}
{% block crumb %}audio/songs{% endblock crumb %}

{% block content %}
<header class="term-cmd">
  <div>
    <h1 class="term-title">{{ t(key="songs-title-admin", lang=lang | default(value='sk')) }}</h1>
    <p class="term-sub">{{ t(key="admin-songs-desc", lang=lang | default(value='sk')) }}</p>
  </div>
  <div class="term-cmd-actions">
    <a href="/admin/audio/tracks/upload" class="btn btn-primary btn-sm">{{ t(key="upload-song", lang=lang | default(value='sk')) }}</a>
    <a href="/admin/audio/albums" class="btn btn-outline btn-sm">{{ t(key="albums-title", lang=lang | default(value='sk')) }}</a>
  </div>
</header>

<div class="term-note">
  <p class="term-note-title">{{ t(key="admin-audio-how", lang=lang | default(value='sk')) }}</p>
  <div class="term-step">
    <span class="term-step-n">[1]</span>
    <span>{{ t(key="admin-audio-step-upload", lang=lang | default(value='sk')) }}</span>
  </div>
  <div class="term-step">
    <span class="term-step-n">[2]</span>
    <span>{{ t(key="admin-audio-step-album", lang=lang | default(value='sk')) }}</span>
  </div>
  <p class="term-note-foot">{{ t(key="admin-audio-note", lang=lang | default(value='sk')) }}</p>
</div>

<div class="card">
  <div class="term-head">
    <span class="term-head-name">~/audio/songs/</span>
    <span class="term-head-meta term-tag is-green">{{ tracks | length }} {{ t(key="songs-title", lang=lang | default(value='sk')) }}</span>
  </div>
  <div class="card-body">
    {% if tracks | length > 0 %}
      <div class="overflow-x-auto">
        <table class="table">
          <thead>
            <tr>
              <th>{{ t(key="song", lang=lang | default(value='sk')) }}</th>
              <th>{{ t(key="where", 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 track in tracks %}
            <tr>
              <td class="font-medium">{{ track.title }}</td>
              <td>
                {% if track.album_id %}
                <span class="term-tag is-purple">{{ t(key="in-album", lang=lang | default(value='sk')) }}</span>
                {% else %}
                <span class="term-tag is-blue">{{ t(key="single", lang=lang | default(value='sk')) }}</span>
                {% endif %}
              </td>
              <td>
                {% if track.published %}
                <span class="term-tag is-green">{{ t(key="published", lang=lang | default(value='sk')) }}</span>
                {% else %}
                <span class="term-tag">{{ t(key="draft", lang=lang | default(value='sk')) }}</span>
                {% endif %}
              </td>
              <td>
                <div class="flex flex-wrap gap-2">
                  <a href="/audio/tracks/{{ track.id }}/stream" class="btn btn-ghost btn-sm">{{ t(key="play", lang=lang | default(value='sk')) }}</a>
                  {% if track.published %}
                  <form method="post" action="/admin/audio/tracks/{{ track.id }}/unpublish">
                    <button type="submit" class="btn btn-ghost btn-sm">{{ t(key="unpublish", lang=lang | default(value='sk')) }}</button>
                  </form>
                  {% else %}
                  <form method="post" action="/admin/audio/tracks/{{ track.id }}/publish">
                    <button type="submit" class="btn btn-ghost btn-sm t-green">{{ t(key="publish", lang=lang | default(value='sk')) }}</button>
                  </form>
                  {% endif %}
                  <form method="post" action="/admin/audio/tracks/{{ track.id }}/delete">
                    <button type="submit" class="btn btn-ghost btn-sm t-red">{{ t(key="delete", lang=lang | default(value='sk')) }}</button>
                  </form>
                </div>
              </td>
            </tr>
            {% endfor %}
          </tbody>
        </table>
      </div>
    {% else %}
      <div class="term-empty">
        <p class="font-medium">{{ t(key="admin-no-songs", lang=lang | default(value='sk')) }}</p>
        <p class="term-empty-cmd">{{ t(key="admin-upload-first-song", lang=lang | default(value='sk')) }}</p>
        <div class="pt-2">
          <a href="/admin/audio/tracks/upload" class="btn btn-primary btn-sm">{{ t(key="upload-song", lang=lang | default(value='sk')) }}</a>
        </div>
      </div>
    {% endif %}
  </div>
</div>
{% endblock content %}
