<% if @writable && @tournament.uses_knockout? %>

<%= t("tournaments.hub.knockout_how_title") %>

  1. <%= t("tournaments.hub.knockout_how_groups") %>
  2. <%= t("tournaments.hub.knockout_how_seed") %>
  3. <%= t("tournaments.hub.knockout_how_advance") %>
<% if @tournament.uses_groups? %> <%= button_to t("tournaments.hub.propose_knockout"), public_propose_knockout_tournament_path(@tournament), method: :post, class: "btn btn-primary" %> <% end %>
<% end %> <% @groups.each do |group| %>

<%= group.name %> — <%= t("tournaments.hub.standings") %>

<% rows = @standings_by_group[group] %> <% if rows.any? %> <% rows.each_with_index do |row, idx| %> <% end %>
<%= t("tournaments.hub.played") %> <%= t("tournaments.hub.won") %> <%= t("tournaments.hub.lost") %> <%= t("tournaments.hub.points") %>
<%= idx + 1 %>. <%= tournament_team_chip(row.participant) %> <%= row.played %> <%= row.won %> <%= row.lost %> <%= row.points %>
<% end %> <% end %> <% @rounds.each do |round| %>

<%= round.name %>

<% round_matches = @matches.select { |m| m.tournament_round_id == round.id } %> <% if round_matches.any? %>
<% if @writable %><% end %> <% round_matches.each do |match| %> <% form_id = "ko-edit-#{match.id}" %> <%= form_with url: public_tournament_match_path(@tournament, match), method: :patch, html: { id: form_id, class: "visually-hidden" } do %> <%= hidden_field_tag :tab, "tabellone", form: form_id %> <%= datetime_local_field_tag "match[scheduled_at]", tournament_datetime_local(match.scheduled_at), id: "ko_at_#{match.id}", form: form_id %> <% end %> <% if @writable %> <% end %> <% end %>
<%= t("tournaments.hub.datetime") %> <%= t("tournaments.hub.home") %> <%= t("tournaments.hub.away") %> <%= t("tournaments.hub.result") %>
<%= match.scheduled_at ? l(match.scheduled_at, format: :short) : "—" %> <%= render "public/tournaments/match_side_select", match: match, side: :home, form_id: form_id %> <% src = tournament_side_source_label(match, :home) %> <% if src.present? && match.home_participant_id.blank? %>
<%= src %>
<% end %>
<%= render "public/tournaments/match_side_select", match: match, side: :away, form_id: form_id %> <% src = tournament_side_source_label(match, :away) %> <% if src.present? && match.away_participant_id.blank? %>
<%= src %>
<% end %>
<% if tournament_match_sides_locked?(match) %> <%= match.home_score %>–<%= match.away_score %> <% elsif @writable %> <%= number_field_tag :home_score, match.home_score, id: "ko_home_score_#{match.id}", form: form_id %> <%= number_field_tag :away_score, match.away_score, id: "ko_away_score_#{match.id}", form: form_id %> <% else %> — <% end %> <%= submit_tag t("tournaments.hub.save_match"), form: form_id, class: "btn btn-secondary tournament-match-form__save" %>
<% else %>

<%= t("tournaments.hub.knockout_round_empty") %>

<% end %> <% end %>