% content_for :title, "What client group is this scheme intended for?" %>
<% if request.referer&.include?("new") || request.referer&.include?("details") %>
<% back_button_path = scheme_details_path(@scheme) %>
<% elsif request.query_parameters["check_answers"] %>
<% back_button_path = scheme_check_answers_path(@scheme) %>
<% end %>
<% content_for :before_content do %>
<%= govuk_back_link(href: back_button_path) %>
<% end %>
<%= form_for(@scheme, method: :patch) do |f| %>
<%= f.govuk_error_summary %>
<%= render partial: "organisations/headings", locals: { main: "What client group is this scheme intended for?", sub: @scheme.service_name } %>
<%= govuk_inset_text(text: "Only update a scheme if you’re fixing an error. If the scheme is changing, create a new scheme.") if @scheme.confirmed? %>
<% primary_client_group_selection = Scheme.primary_client_groups.keys.excluding("Missing").map { |key, _| OpenStruct.new(id: key, name: key) } %>
<%= f.govuk_collection_radio_buttons :primary_client_group,
primary_client_group_selection,
:id,
:name,
legend: nil %>
<%= f.hidden_field :page, value: "primary-client-group" %>
<% if request.query_parameters["select_managing_org"] == "true" %>
<%= f.hidden_field :check_answers, value: "true" %>
<% end %>
<% if request.query_parameters["check_answers"] == "true" %>
<%= f.hidden_field :check_answers, value: "true" %>
<%= f.govuk_submit "Save changes" %>
<% else %>
<%= f.govuk_submit "Save and continue" %>
<% end %>
<% end %>