<div class="row">
    <div class="col-md-8">
    <%= form_for plan, html: {method: :put, class: 'form-horizontal edit_plan' } do |f| %>
      <div class="form-group"><!-- title -->
        <div class="col-md-12">
          <%= f.label(:title, _('Project title'), class: 'control-label') %>
        </div>
        <div class="col-md-8">
          <%= f.text_field(:title, class: "form-control", "aria-required": true, 'data-toggle': 'tooltip',
            title: _('If applying for funding, state the name exactly as in the grant proposal.')) %>
      <div class="checkbox">
        <%= f.hidden_field :visibility %>
        <%= f.label(:is_test, class: 'control-label') do %>
          <%= check_box_tag(:is_test, 1, @plan.is_test?, "aria-label": "is_test") %>
          <%= _('mock project for testing, practice, or educational purposes') %>
        <% end %>
      </div>
        </div>
      </div>
      <div class="form-group"><!-- funder_name -->
        <div class="col-md-12">
          <%= f.label(:funder_name, _('Funder'), class: 'control-label') %>
        </div>
        <div class="col-md-8">
          <%= f.text_field(
            :funder_name,
            class: "form-control",
            "aria-required": false) %>
        </div>
      </div>
      <div class="form-group"><!-- grant_number -->
        <div class="col-md-12">
          <%= label_tag(:plan_grant_number_name, _('Grant number'), class: 'control-label') %>
        </div>

        <div class="col-md-8">
          <%= text_field_tag(:plan_grant_number_name, '',
              class: "grant-id-typeahead form-control",
              autocomplete: "off",
              aria: { required: false }) %>
          <%= f.hidden_field(:grant_number) %>
          <span class="text-muted" id="grant_number_info">Grant number: <%= @plan.grant_number %></span>
        </div>
      </div>
      <div class="form-group"><!-- description -->
        <div class="col-md-12">
          <%= f.label(:description, _('Project abstract'), class: 'control-label') %>
        </div>
        <div class="col-md-8" data-toggle="tooltip" title="<%= _("Briefly summarise your research project to help others understand the purposes for which the data are being collected or created.") %>">
          <%= f.text_area(
            :description, rows: 6,
            class: 'form-control tinymce',
            "aria-required": false) %>
        </div>
      </div>
      <div class="form-group"><!-- identifier -->
        <div class="col-md-12">
          <%= f.label(:identifier, _('ID'), class: 'control-label') %>
        </div>
        <div class="col-md-8">
          <%= f.text_field(:identifier, class: "form-control", "aria-required": false, 'data-toggle': "tooltip",
                           title: _('A pertinent ID as determined by the funder and/or organisation.')) %>
        </div>
      </div>
      <fieldset class="project-details">
        <legend class="project-details"><%= _("Principal Investigator") %></legend>
        <div class="form-group"><!-- principal_investigator -->
          <div class="col-md-12">
            <%= f.label(:principal_investigator, _('Name'), class: 'control-label') %>
          </div>
          <div class="col-md-12">
            <%= f.text_field(
              :principal_investigator,
              class: "form-control",
              "aria-required": false) %>
          </div>
        </div>
        <div class="form-group"><!-- principal_investigator_identifier -->
          <div class="col-md-12">
            <%= f.label(:principal_investigator_identifier, _('ORCID iD'), class: 'control-label') %>
          </div>
          <div class="col-md-12">
            <%= f.text_field(
              :principal_investigator_identifier,
              class: "form-control",
              "aria-required": false) %>
          </div>
        </div>
        <div class="form-group"><!-- principal_investigator_email -->
          <div class="col-md-12">
            <%= f.label(:principal_investigator_email, _('Email'), class: 'control-label') %>
          </div>
          <div class="col-md-12">
            <%= f.email_field(
              :principal_investigator_email,
              class: "form-control",
              "aria-required": false) %>
          </div>
        </div>
        <div class="form-group"><!-- principal_invesigator_phone -->
          <div class="col-md-12">
            <%= f.label(:principal_investigator_phone, _('Phone'), class: 'control-label') %>
          </div>
          <div class="col-md-12">
            <%= f.phone_field(
              :principal_investigator_phone,
              class: "form-control",
              "aria-required": false) %>
          </div>
        </div>
      </fieldset>
      <fieldset class="project-details">
        <legend class="project-details"><%= _('Data contact person') %></legend>
        <div class="checkbox">
          <% checked = ((@plan.data_contact.present? || @plan.data_contact_phone.present? || @plan.data_contact_email.present?) ? 1 : 0) %>
          <%= label_tag(:show_data_contact, class: 'control-label') do %>
            <%= check_box_tag(:show_data_contact, checked, checked == 0) %>
            <%= _('Same as Principal Investigator') %>
          <% end %>
        </div>
        <div class="form-group data-contact"><!-- data_contact -->
          <div class="col-md-12">
            <%= f.label(:data_contact, _('Name'), class: 'control-label') %>
          </div>
          <div class="col-md-12">
            <%= f.text_field(
              :data_contact,
              class: "form-control",
              "aria-required": false) %>
          </div>
        </div>
        <div class="form-group data-contact"><!-- data_contact_email -->
          <div class="col-md-12">
            <%= f.label(:data_contact_email, _('Email'), class: 'control-label') %>
          </div>
          <div class="col-md-12">
            <%= f.email_field(
              :data_contact_email,
              class: "form-control",
              "aria-required": false) %>
          </div>
        </div>
        <div class="form-group data-contact"><!-- data_contact_phone -->
          <div class="col-md-12">
            <%= f.label(:data_contact_phone, _('Phone'), class: 'control-label') %>
          </div>
          <div class="col-md-12">
            <%= f.phone_field(
              :data_contact_phone,
              class: "form-control",
              "aria-required": false) %>
          </div>
        </div>
      </fieldset>
      <%= f.button(_('Save'), class: "btn btn-default", type: "submit") %>
    </div>
    <div class="col-md-4">
      <h2><%= _('Select Guidance') %></h2>

      <% if @all_guidance_groups.length > 0 %>
        <p><%= _('To help you write your plan, %{application_name} can show you guidance from a variety of organisations.') %
            {application_name: Rails.configuration.branding[:application][:name]} %>
            </p>
        <fieldset>
          <p><%= _('Select up to 6 organisations to see their guidance.') %></p>
          <ul id="priority-guidance-orgs">
            <%= render partial: "guidance_choices",
                          locals: {choices: @important_ggs, form: f,
                                   current_selections: @selected_guidance_groups} %>
          </ul>
        </fieldset>

        <% if @all_guidance_groups.length > @important_ggs.length %>
          <p><%= _('Find guidance from additional organisations below') %></p>
          <%= link_to _('See the full list'), '#', 'data-toggle' =>  'modal', 'data-target' => '#modal-full-guidances', class: 'modal-guidances-window' %>
        <% end %>
        <br>
        <%= f.button(_('Save'), class: "btn btn-default", type: "submit") %>

      <% else %>
        <p><%= _("There is no additional guidance for this template.") %></p>
      <% end %>
    </div>

    <% if @all_guidance_groups.length > @important_ggs.length %>
      <div id="modal-full-guidances" class="modal fade" tabindex="-1" role="dialog">
        <div class="modal-dialog" role="document">
          <div class="modal-content">
            <div class="sign-in">
              <div class="modal-body">
                <button type="button" class="close pull-right" data-dismiss="modal" aria-label="<%= _('Cancel') %>">
                  <span class="fa fa-times" aria-hidden="true">&nbsp;</span>
                </button>
                <h2><%= _('Select Guidance') %></h2>
                <p>
                  <%= _('To help you write your plan, %{application_name} can show you guidance from a variety of organisations. Please choose up to 6 organisations of the following organisations who offer guidance relevant to your plan.') %
                  {application_name: Rails.configuration.branding[:application][:name]} %>
                </p>
                <p><strong><%= _("Don't forget to save your changes after making your selections.") %></strong></p>
                <ul id="other-guidance-orgs">
                  <%= render partial: "guidance_choices",
                             locals: {choices: @all_ggs_grouped_by_org, form: f,
                                       current_selections: @selected_guidance_groups} %>
                </ul>
              </div>
            </div>
          </div>
        </div>
      </div>
    <% end %>

  <% end %>
</div>
