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

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

{% block content %}
<header class="term-cmd">
  <div>
    <h1 class="term-title">{{ album.title }}</h1>
    <p class="term-sub">
      {{ t(key="album", lang=lang | default(value='sk')) }} &middot; {{ tracks | length }} {{ t(key="songs-title", lang=lang | default(value='sk')) }} &middot;
      {% if album.published %}<span class="t-green">{{ t(key="published", lang=lang | default(value='sk')) }}</span>{% else %}<span class="t-yellow">{{ t(key="draft", lang=lang | default(value='sk')) }}</span>{% endif %}
    </p>
  </div>
  <div class="term-cmd-actions">
    <a href="/admin/audio/albums/{{ album.id }}/tracks/upload" class="btn btn-primary btn-sm">{{ t(key="upload-song-into-album", lang=lang | default(value='sk')) }}</a>
    <a href="/audio/albums/{{ album.slug }}" class="btn btn-outline btn-sm">{{ t(key="view", 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-two-ways-title", lang=lang | default(value='sk')) }}</p>
  <div class="term-step">
    <span class="term-step-n">[a]</span>
    <span>{{ t(key="admin-two-ways-upload", lang=lang | default(value='sk')) }}</span>
  </div>
  <div class="term-step">
    <span class="term-step-n">[b]</span>
    <span>{{ t(key="admin-two-ways-pick", lang=lang | default(value='sk')) }}</span>
  </div>
</div>

<div class="card">
  <div class="term-head">
    <span class="term-head-name">~/audio/{{ album.slug }}/tracklist</span>
    <span class="term-head-meta term-tag is-purple">{{ tracks | length }} {{ t(key="songs-title", lang=lang | default(value='sk')) }}</span>
  </div>
  <div class="card-body">
    {% if available_tracks | length > 0 %}
      <form method="post" action="/admin/audio/albums/{{ album.id }}/tracks/add" class="space-y-2">
        <div class="form-control">
          <label class="label"><span class="label-text t-green">{{ t(key="admin-add-existing-song", lang=lang | default(value='sk')) }}</span></label>
          <select name="track_id" required class="select select-bordered w-full">
            {% for song in available_tracks %}
            <option value="{{ song.id }}">{{ song.title }}</option>
            {% endfor %}
          </select>
          <p class="term-help">{{ t(key="admin-existing-song-help", lang=lang | default(value='sk')) }}</p>
        </div>
        <button type="submit" class="btn btn-outline btn-sm">{{ t(key="admin-add-to-album", lang=lang | default(value='sk')) }}</button>
      </form>
      <div class="term-formdiv"></div>
    {% endif %}

    {% if tracks | length > 0 %}
      <div class="overflow-x-auto">
        <table class="table">
          <thead>
            <tr>
              <th>#</th>
              <th>{{ t(key="song", lang=lang | default(value='sk')) }}</th>
              <th>{{ t(key="status", lang=lang | default(value='sk')) }}</th>
              <th>{{ t(key="featured", 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="t-dim">{% if track.track_number %}{{ track.track_number }}{% else %}&mdash;{% endif %}</td>
              <td class="font-medium">{{ track.title }}</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>
                {% if track.featured %}
                <span class="term-tag is-aqua">{{ t(key="featured", lang=lang | default(value='sk')) }}</span>
                {% else %}
                <span class="t-dim">—</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 }}/remove-from-album">
                    <button type="submit" class="btn btn-ghost btn-sm">{{ t(key="remove-from-album", lang=lang | default(value='sk')) }}</button>
                  </form>
                  <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-album-empty", lang=lang | default(value='sk')) }}</p>
        <p class="term-empty-cmd">{{ t(key="admin-album-empty-help", lang=lang | default(value='sk')) }}</p>
        <div class="pt-2">
          <a href="/admin/audio/albums/{{ album.id }}/tracks/upload" class="btn btn-primary btn-sm">{{ t(key="upload-song-into-album", lang=lang | default(value='sk')) }}</a>
        </div>
      </div>
    {% endif %}
  </div>
</div>
{% endblock content %}
