<% content_for :before_content do %>
  <% title = "Tell us if your organisation is merging" %>
  <% content_for :title, title %>
  <%= govuk_back_link href: absorbing_organisation_merge_request_path(id: @merge_request) %>
<% end %>

<%= form_with model: @merge_request, url: merge_request_path, method: :patch do |f| %>
  <%= f.govuk_error_summary %>

  <h2 class="govuk-heading-l">What is <%= @merge_request.absorbing_organisation.name %>'s telephone number?</h2>

  <div class="govuk-grid-row">
    <div class="govuk-grid-column-two-thirds-from-desktop">
      <% if @merge_request.absorbing_organisation.phone.present? %>
        <p class="govuk-body">Confirm the telephone number on file, or enter a new one.</p>
        <div class="govuk-inset-text">
          <%= @merge_request.absorbing_organisation.phone %>
        </div>
      <% end %>

      <% if @merge_request.absorbing_organisation.phone.present? %>
        <%= f.govuk_radio_buttons_fieldset(:telephone_number_correct, legend: nil) do %>
          <%= f.govuk_radio_button :telephone_number_correct, true, checked: @merge_request.telephone_number_correct?, label: { text: "This telephone number is correct" }, link_errors: true %>
          <%= f.govuk_radio_button(
            :telephone_number_correct,
            false,
            checked: (@merge_request.new_telephone_number.present? || @merge_request.errors.key?(:new_telephone_number)),
            label: { text: "Enter a new phone number" },
          ) do %>
            <%= f.govuk_text_field :new_telephone_number, label: { text: "Telephone number" }, width: "two-thirds" %>
          <% end %>
          <%= f.hidden_field :page, value: "confirm_telephone_number" %>
        <% end %>
      <% else %>
        <%= f.govuk_text_field :new_telephone_number, label: nil, width: "two-thirds" %>
        <%= f.hidden_field :page, value: "confirm_telephone_number" %>
      <% end %>
      <%= f.govuk_submit %>
    <% end %>
  </div>
</div>