<%- include('../partials/header') %>
<%- include('../partials/sidebar') %>

<div class="dashboard-header" style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 30px;">
  <div>
    <h1 class="text-gradient">Podcasts</h1>
    <p style="color: var(--text-muted);">Gerencie episódios gravados.</p>
  </div>
  <a href="/admin/podcasts/novo" class="btn btn-primary">
    <i class="fas fa-plus"></i> Novo Episódio
  </a>
</div>

<div class="card">
  <div style="overflow-x: auto;">
    <table style="width: 100%; border-collapse: collapse; text-align: left;">
      <thead>
        <tr style="border-bottom: 1px solid var(--border-color);">
          <th style="padding: 15px; color: var(--text-muted); font-weight: 500;">Capa</th>
          <th style="padding: 15px; color: var(--text-muted); font-weight: 500;">Título</th>
          <th style="padding: 15px; color: var(--text-muted); font-weight: 500;">Data</th>
          <th style="padding: 15px; color: var(--text-muted); font-weight: 500;">Ações</th>
        </tr>
      </thead>
      <tbody>
        <% if (podcasts.length > 0) { %>
          <% podcasts.forEach(pod => { %>
            <tr style="border-bottom: 1px solid rgba(42, 52, 74, 0.5);">
              <td style="padding: 15px;">
                <% if(pod.capa_url) { %>
                  <img src="<%= pod.capa_url %>" style="width: 50px; height: 50px; border-radius: 8px; object-fit: cover;">
                <% } else { %>
                  <div style="width: 50px; height: 50px; border-radius: 8px; background: var(--bg-dark); display: flex; align-items: center; justify-content: center; color: var(--text-muted);"><i class="fas fa-podcast"></i></div>
                <% } %>
              </td>
              <td style="padding: 15px; font-weight: 600;">
                <%= pod.titulo %>
                <br><audio controls src="<%= pod.arquivo_url %>" style="height: 30px; margin-top: 5px;"></audio>
              </td>
              <td style="padding: 15px; color: var(--text-muted); font-size: 0.9rem;"><%= new Date(pod.data_publicacao).toLocaleDateString() %></td>
              <td style="padding: 15px;">
                <form action="/admin/podcasts/delete/<%= pod.id %>" method="POST" style="display:inline;" onsubmit="return confirm('Excluir podcast?');">
                  <button type="submit" class="btn btn-danger" style="padding: 8px 15px; font-size: 0.8rem;">
                    <i class="fas fa-trash"></i>
                  </button>
                </form>
              </td>
            </tr>
          <% }) %>
        <% } else { %>
          <tr><td colspan="4" style="padding: 30px; text-align: center; color: var(--text-muted);">Nenhum podcast.</td></tr>
        <% } %>
      </tbody>
    </table>
  </div>
</div>
<%- include('../partials/footer') %>
