<% coverage = tournament_streaming_coverage(@matches) %> <% live_counts = tournament_streaming_live_counts(@matches) %>

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

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

<% if @writable && @matches.any? %> <%= t("tournaments.hub.stream_plan_invite_title") %> <% end %>
<% if @matches.any? %>
<% %i[live waiting_time waiting_operator ended uncovered].each do |state| %> <% count = live_counts[state].to_i %> <% next if count.zero? %> <%= t("tournaments.hub.stream_plan_live_count.#{state}", count: count) %> <% end %> <% if @writable && coverage[:open].positive? %> <% end %>
<% tournament_matches_grouped_by_date(@matches).each do |date, matches| %>

<%= date ? l(date, format: :long) : t("tournaments.hub.stream_plan_unscheduled") %>

<% if @writable %><% end %> <% matches.each do |match| %> <% state = tournament_broadcast_live_state(match) %> <% uncovered = state == :uncovered %> <% if @writable %> <% end %> <%= render "public/tournaments/match_streaming", match: match, writable: @writable, allow_invite: false, return_tab: "dirette" %> <% end %>
<%= t("tournaments.hub.datetime") %> <%= t("tournaments.hub.court") %> <%= t("tournaments.hub.stream_plan_match") %> <%= t("tournaments.hub.stream_plan_live_col") %> <%= t("tournaments.hub.stream_plan_operator") %>
<% if uncovered %> <% end %> <%= match.scheduled_at ? match.scheduled_at.in_time_zone.strftime("%H:%M") : "—" %> <%= match.court.presence || "—" %>
<%= tournament_team_chip(match.home_participant, name: match.home_display_name) %> <%= tournament_team_chip(match.away_participant, name: match.away_display_name) %>
<%= t("tournaments.hub.stream_plan_live.#{state}") %>
<% end %> <% else %>

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

<% end %>
<% if @writable %>

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

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

<%= form_with url: public_tournament_invitations_path(@tournament), method: :post, html: { id: "tournament-stream-invite", class: "tournament-form tournament-invite-form tournament-stream-plan__invite" } do %> <%= hidden_field_tag :tab, "dirette" %>
<%= label_tag :email, t("tournaments.hub.invite_email") %> <%= email_field_tag :email, @tournament.invite_draft_email, required: true, autocomplete: "email" %>
<%= label_tag :note, t("tournaments.hub.invite_note") %> <%= text_area_tag :note, @tournament.invite_draft_note, rows: 2, maxlength: 2000, data: { invite_note: true }, placeholder: t("tournaments.hub.invite_note_placeholder") %>
<%= label_tag :court, t("tournaments.hub.court") %> <%= select_tag :court, options_for_select(@tournament.court_list) %>
<%= label_tag :on_date, t("tournaments.hub.datetime") %> <%= date_field_tag :on_date, @tournament.starts_on %>

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

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

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

<% if @tournament.invite_draft_saved_at.present? %>

<%= t("tournaments.hub.invite_draft_hint", time: l(@tournament.invite_draft_saved_at, format: :short)) %>

<% end %>
" data-msg-size="<%= t("tournaments.hub.invite_image_too_big") %>" data-msg-uploading="<%= t("tournaments.hub.invite_image_uploading") %>" data-msg-failed="<%= t("tournaments.hub.invite_image_failed") %>" data-msg-link="<%= t("tournaments.hub.invite_editor_link_prompt") %>">
<%= raw tournament_invite_editor_html(@tournament, current_user) %>
<%= hidden_field_tag :email_html, "", id: "invite-email-html", data: { invite_html: true } %>
<%= button_tag t("tournaments.hub.invite_save"), type: "submit", name: "intent", value: "save", formnovalidate: true, class: "btn btn-secondary" %> <%= submit_tag t("tournaments.hub.stream_plan_invite_selected"), class: "btn btn-primary" %> <%= button_tag t("tournaments.hub.stream_plan_invite_court"), type: "submit", name: "whole_court", value: "1", class: "btn btn-secondary" %>
<% end %> <% if flash[:invite_url].present? %> <% end %>
<% end %>