<% content_for :title, "Partite — #{@team.name}" %>
<% content_for :robots, "noindex, nofollow" %>

<div class="wrap" style="padding-top:20px;max-width:720px">
  <nav class="team-dashboard-nav" aria-label="Percorso">
    <%= link_to "← #{@team.name}", public_team_details_path(@team), class: "team-dashboard-nav__club" %>
  </nav>

  <header style="margin:16px 0 20px">
    <h1>Partite — <%= @team.name %></h1>
    <p style="color:#888;margin-top:8px">
      Programma qui da PC data, avversario e luogo. Quando sei in palestra apri l’app Match Live TV,
      seleziona questa squadra e avvia la diretta sulla partita.
    </p>
  </header>

  <div style="display:flex;gap:12px;flex-wrap:wrap;margin-bottom:20px">
    <%= link_to "Programma partita", new_public_team_match_path(@team), class: "btn btn-primary" %>
    <%= link_to "Dettagli squadra", public_team_details_path(@team), class: "btn btn-secondary" %>
    <%= link_to "Dirette e programma", public_live_index_path(club_id: @club.id), class: "btn btn-secondary" %>
  </div>

  <div class="card">
    <% if @matches.any? %>
      <table class="data">
        <thead>
          <tr>
            <th>Avversario</th>
            <th>Data e ora</th>
            <th>Luogo</th>
            <th>Stato</th>
            <th></th>
          </tr>
        </thead>
        <tbody>
          <% @matches.each do |match| %>
            <tr>
              <td><strong><%= match.opponent_name %></strong></td>
              <td>
                <% if match.scheduled_at %>
                  <%= l_local(match.scheduled_at) %>
                <% else %>
                  <span style="color:#888">Senza orario</span>
                <% end %>
              </td>
              <td><%= match.location.presence || "—" %></td>
              <td>
                <% label = match.public_status_label %>
                <% if label == "In corso / da riprendere" %>
                  <span style="color:#e53935;font-weight:600"><%= label %></span>
                <% else %>
                  <%= label %>
                <% end %>
              </td>
              <td style="white-space:nowrap">
                <%= link_to "Modifica", edit_public_team_match_path(@team, match) %>
                <% if match.deletable? %>
                  ·
                  <%= button_to "Elimina", public_team_match_path(@team, match),
                        method: :delete,
                        form: { data: { turbo_confirm: "Eliminare questa partita?" } },
                        class: "btn btn-secondary",
                        style: "padding:4px 10px;font-size:0.8rem;display:inline" %>
                <% end %>
              </td>
            </tr>
          <% end %>
        </tbody>
      </table>
    <% else %>
      <p style="color:#888;margin:0">
        Nessuna partita in calendario.
        <%= link_to "Programma la prima", new_public_team_match_path(@team) %>.
      </p>
    <% end %>
  </div>
</div>
