<h3>
  <%= @tournament.name %> Info
</h3>

<% if (can? :manage, @tournament) && @tournament.curently_generating_matches == 1 %>
  <div class="alert alert-info">
    <strong>Match Generation In Progress</strong>
    <p>Tournament bracket generation is currently running. Please refresh the page to check progress.</p>
  </div>
<% end %>

<% if (can? :manage, @tournament) && @tournament.has_active_jobs? %>
  <div class="alert alert-info">
    <strong>Background Jobs In Progress</strong>
    <p>The following background jobs are currently running:</p>
    <ul>
      <% @tournament.active_jobs.each do |job| %>
        <li><%= job.job_name %> - <%= job.status %> <%= "(#{job.details})" if job.details.present? %></li>
      <% end %>
    </ul>
    <p>Please refresh the page to check progress.</p>
  </div>
<% end %>

<p>
  <strong>Address:</strong>
  <%= @tournament.address %>
</p>
<p>
  <strong>Director:</strong>
  <%= @tournament.director %>
</p>
<p>
  <strong>Director email:</strong>
  <%= @tournament.director_email %>
</p>
<p>
  <strong>Tournament Type:</strong>
  <%= @tournament.tournament_type %>
</p>
<p>
  <strong>Tournament Date:</strong>
  <%= @tournament.date %>
</p>
<p>
  <strong>Tournament Information Is Public:</strong>
  <%= @tournament.is_public %>
</p>
<% if can? :read, @tournament %><p>Brackets and team scores can be found in the white nav-bar up top.</p><% end %>
<br>
<h3>Schools</h3>
<p>Click to see lineups, bout numbers, score breakdowns, and stats.</p>
<br>
<table class="table table-hover table-condensed">
  <thead>
    <tr>
      <th>Name</th>
      <% if can? :manage, @tournament %><th><%= link_to " New School" , "/schools/new?tournament=#{@tournament.id}", :class=>"fas fa-plus" %></th><% end %>
    </tr>
  </thead>
  <tbody>
    <% @schools.each do |school| %>
      <tr>
        <td>
          <% if can? :read, school %>
            <%= link_to "#{school.name}", school %>
          <% else %>
            <%= "#{school.name}" %>
          <% end %>
        </td>
        <td>
          <% if can? :manage, school %>
            <%= link_to edit_school_path(school), class: "text-decoration-none" do %>
              <span class="fas fa-edit" aria-hidden="true"></span>
            <% end %>
            <% if can? :manage, @tournament %>
              <%= link_to school, data: { turbo_method: :delete, turbo_confirm: "Are you sure you want to delete #{school.name}?" }, class: "text-decoration-none" do %>
                <span class="fas fa-trash-alt" aria-hidden="true"></span>
              <% end %>
            <% end %>
          <% end %>
        </td>
      </tr>
    <% end %>
   </tbody>
  </table>
<br>
<h3>Weight Class Seeds</h3>
<br>
<table class="table table-hover table-condensed">
  <thead>
    <tr>
      <th>Weight Class</th>
      <th>Bracket Size</th>
      <% if can? :manage, @tournament %><th><%= link_to " New Weight Class" , "/weights/new?tournament=#{@tournament.id}", :class=>"fas fa-plus" %></th><% end %>
    </tr>
  </thead>

  <tbody>
    <% @weights.each do |weight| %>
      <tr>
        <td>
          <% if can? :read, @tournament %>
            <%= link_to "#{weight.max}", weight %>
          <% else %>
            <%= "#{weight.max}" %>
          <% end %>
        </td>
        <td><%= weight.bracket_size %></td>
          <% if can? :manage, @tournament %>
          <td>
            <%= link_to edit_weight_path(weight), class: "text-decoration-none" do %>
              <span class="fas fa-edit" aria-hidden="true"></span>
            <% end %>
            <%= link_to weight, data: { turbo_method: :delete, turbo_confirm: "Are you sure you want to delete the #{weight.max} weight class?" }, class: "text-decoration-none" do %>
              <span class="fas fa-trash-alt" aria-hidden="true"></span>
            <% end %>
          </td>
          <% end %>
      </tr>
    <% end %>
  </tbody>
</table>
<% if can? :manage, @tournament %>
  <br>
  <br>
  <h3>Mats</h3><br>
  <table class="table table-hover table-condensed">
    <thead>
      <tr>
        <th>Name</th>
        <th>Current Match</th>
        <th><%= link_to " New Mat" , "/mats/new?tournament=#{@tournament.id}", :class=>"fas fa-plus" %></th>
      </tr>
    </thead>
    <tbody>
      <% @mats.each do |mat| %>
        <% current_match = mat.queue1_match %>
        <tr>
          <td><%= link_to "Mat #{mat.name}", mat %></td>
          <td>
            <% if current_match %>
              <%= link_to "Stat Match", stat_match_path(current_match), class: "btn btn-primary btn-sm" %>
              <%= link_to "State Match", state_mat_path(mat), class: "btn btn-success btn-sm" %>
              <%= link_to "Scoreboard", scoreboard_mat_path(mat, print: true), class: "btn btn-warning btn-sm", target: "_blank", rel: "noopener" %>
            <% else %>
              <%= link_to "Scoreboard", scoreboard_mat_path(mat, print: true), class: "btn btn-warning btn-sm", target: "_blank", rel: "noopener" %>
            <% end %>
          </td>
            <% if can? :manage, @tournament %>
            <td>
            <%= link_to mat, data: { turbo_method: :delete, turbo_confirm: "Are you sure you want to delete Mat #{mat.name}?" }, class: "text-decoration-none" do %>
              <span class="fas fa-trash-alt" aria-hidden="true"></span>
            <% end %>
             <%= link_to '', "/mats/#{mat.id}/assign_next_match", data: { turbo_method: :post }, :class=>"fas fa-solid fa-arrow-right" %>
             </td>
            <% end %>
        </tr>
      <% end %>
    </tbody>
  </table>
<% end %>
<br><br>
