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

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

<%= button_to t("tournaments.hub.generate_group_matches"), public_generate_group_matches_tournament_path(@tournament), method: :post, class: "btn btn-secondary" %> <% end %> <% if @matches.any? %>

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

"> <% @matches.each do |match| %> <% form_id = "match-edit-#{match.id}" %> <% courts = (@tournament.court_list + [match.court]).compact_blank.uniq %> <%= form_with url: public_tournament_match_path(@tournament, match), method: :patch, html: { id: form_id, class: "visually-hidden" } do %> <%= hidden_field_tag :tab, @tab, form: form_id %> <% end %> <% if @writable %> <% else %> <% end %> <% end %>
<%= t("tournaments.hub.datetime") %> <%= t("tournaments.hub.court") %> <%= t("tournaments.hub.round") %> <%= t("tournaments.hub.home") %> <%= t("tournaments.hub.away") %> <%= t("tournaments.hub.result") %>
<%= datetime_local_field_tag "match[scheduled_at]", tournament_datetime_local(match.scheduled_at), id: "match_at_#{match.id}", form: form_id, required: true, class: "tournament-match-form__datetime" %> <%= select_tag "match[court]", options_for_select(courts, match.court), id: "match_court_#{match.id}", form: form_id, include_blank: true, class: "tournament-match-form__court" %> <%= tournament_phase_label(match) %> <%= render "public/tournaments/match_side_select", match: match, side: :home, form_id: form_id %> <%= button_to public_swap_tournament_match_path(@tournament, match), method: :post, class: "tournament-match-swap__btn", title: t("tournaments.hub.swap_sides"), form: { class: "tournament-match-swap__form", data: { turbo: false } } do %> <%= t("tournaments.hub.swap_sides") %> <% end %> <%= render "public/tournaments/match_side_select", match: match, side: :away, form_id: form_id %> <% if match.played? || match.result_status.to_s.start_with?("walkover") %> <%= match.home_score %>–<%= match.away_score %> <% else %> <%= number_field_tag :home_score, match.home_score, id: "home_score_#{match.id}", form: form_id, data: { swap_score: "home" } %> <%= number_field_tag :away_score, match.away_score, id: "away_score_#{match.id}", form: form_id, data: { swap_score: "away" } %> <% end %> <%= submit_tag t("tournaments.hub.save_match"), form: form_id, class: "btn btn-secondary tournament-match-form__save" %> <% if match.deletable? %> <%= button_to t("matches.index.delete"), public_tournament_match_path(@tournament, match), method: :delete, class: "btn btn-secondary tournament-match-form__save", form: { class: "tournament-match-delete-form", data: { turbo_confirm: match.matchup_label } } %> <% end %> <%= match.scheduled_at ? l(match.scheduled_at, format: :short) : "—" %> <%= match.court || "—" %> <%= tournament_phase_label(match) %> <%= tournament_team_chip(match.home_participant, name: match.home_display_name) %> <%= tournament_team_chip(match.away_participant, name: match.away_display_name) %> <% if match.home_score.present? %> <%= match.home_score %>–<%= match.away_score %> <% else %> — <% end %>
<% else %>

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

<% end %> <% if @writable %>
<%= t("tournaments.hub.schedule_another") %> <%= form_with url: public_tournament_matches_path(@tournament), method: :post, html: { class: "tournament-form", style: "margin-top:16px" } do %>
<%= label_tag "match[home_participant_id]", t("tournaments.hub.home") %> <%= select_tag "match[home_participant_id]", options_from_collection_for_select(@participants, :id, :name), include_blank: t("tournaments.tbd") %>
<%= label_tag "match[away_participant_id]", t("tournaments.hub.away") %> <%= select_tag "match[away_participant_id]", options_from_collection_for_select(@participants, :id, :name), include_blank: t("tournaments.tbd") %>
<%= label_tag "match[court]", t("tournaments.hub.court") %> <%= select_tag "match[court]", options_for_select(@tournament.court_list) %>
<%= label_tag "match[scheduled_at]", t("tournaments.hub.datetime") %> <%= datetime_local_field_tag "match[scheduled_at]", nil, required: true %>
<% if @groups.any? %>
<%= label_tag "match[tournament_group_id]", t("tournaments.hub.group") %> <%= select_tag "match[tournament_group_id]", options_from_collection_for_select(@groups, :id, :name), include_blank: true %>
<% end %> <% if @rounds.any? %>
<%= label_tag "match[tournament_round_id]", t("tournaments.hub.round") %> <%= select_tag "match[tournament_round_id]", options_from_collection_for_select(@rounds, :id, :name), include_blank: t("tournaments.hub.no_round") %>
<% end %>
<%= submit_tag t("tournaments.hub.schedule_match"), class: "btn btn-primary" %>
<% end %>
<% end %>