<%= form_tag(plan_export_path(@plan), method: :get, target: '_blank', id: 'download_form') do |f| %>
  <h2><%= _("Download settings") %></h2>
  <%= hidden_field_tag 'export[form]', true %>
  <% if @research_outputs.length > 1 %>
    <div class="form-group research-outputs-selection">
      <strong><%= d_("dmpopidor", "Select research outputs to download") %></strong>
      <ul>
      <%= check_box_tag("select-all-research-outputs", "none", true, { id: "select-all-research-outputs" }) %>
      <%= label_tag("select-all-research-outputs", d_('dmpopidor', 'All')) %>
      <% @research_outputs.each do |research_output| %>
        <li class="checkbox">
          <%= label_tag "selected_research_outputs[]" do %>
            <span class="sublist">└─ </span>
            <%= check_box_tag("selected_research_outputs[]", research_output.id, true, { class: "research-output-checkbox" }) %>
            <%= research_output.abbreviation %>
          <% end %>
        </li>
      <% end %>
      </ul>
    </div>
    <strong><%= d_("dmpopidor", "Research output export mode") %></strong>
      <ul>
        <li class="checkbox">
          <%= label_tag 'export[research_output_mode]' do %>
            <%= radio_button_tag("export[research_output_mode]", "by_section", true) %>
            <%= d_("dmpopidor", 'Research outputs by section') %>
          <% end %>
        </li>
        <li class="checkbox">
          <%= label_tag 'export[research_output_mode]' do %>
            <%= radio_button_tag("export[research_output_mode]", "by_question", false) %>
            <%= d_("dmpopidor", 'Research outputs by question') %>
          <% end %>
        </li>
      </ul>
  <% else %>
    <%= hidden_field_tag(:research_output_id, @research_outputs[0].id) %>
  <% end %>
  <% if @phase_options.length > 1 %>
    <div class="form-group phase-selection">
      <strong><%= _("Select phase to download") %></strong>
      <ul>
      <%= check_box_tag("select-all-phases", "none", true, { id: "select-all-phases" }) %>
      <%= label_tag("select-all-phases", d_('dmpopidor', 'All')) %>
      <% @phase_options.each do |phase| %>
        <li class="checkbox">
          <%= label_tag "selected_phases[]" do %>
            <span class="sublist">└─ </span>
            <%= check_box_tag("selected_phases[]", phase[1], true, { class: "phase-checkbox" }) %>
            <%= phase[0] %>
          <% end %>
        </li>
      <% end %>
      </ul>
    </div>
  <% else %>
    <%= hidden_field_tag(:phase_id, @phase_options[0][1]) %>
  <% end %>
  <fieldset>
    <legend><%= _("Optional plan components") %></legend>
    <div class="checkbox">
      <%= label_tag 'export[project_details]' do %>
        <%= check_box_tag 'export[project_details]', true, true %>
        <%= _('project details coversheet') %>
      <% end %>
    </div>
    <div class="checkbox">
      <%= label_tag 'export[question_headings]' do %>
        <%= check_box_tag 'export[question_headings]', true, true %>
        <%= _('question text and section headings') %>
      <% end %>
    </div>
    <div class="checkbox">
      <%= label_tag 'export[unanswered_questions]' do %>
        <%= check_box_tag 'export[unanswered_questions]', true, true %>
        <%= _('unanswered questions') %>
      <% end %>
    </div>
    <% if @plan.template.customization_of.present? %>
      <div class="checkbox">
        <%= label_tag 'export[custom_sections]' do %>
          <%= check_box_tag 'export[custom_sections]', true, false %>
          <%= _('supplementary section(s) not requested by funding organisation') %>
        <% end %>
      </div>
    <% end %>
  </fieldset>

  <h2><%= _('Format') %></h2>
  <div class="row">
    <div class="form-group col-xs-2">
      <%= select_tag :format, options_for_select(Settings::Template::VALID_FORMATS, :pdf),
                     class: 'form-control', "aria-labelledby": "format" %>
    </div>
  </div>

  <div id="pdf-formatting">
    <h2><%= _('PDF formatting') %></h2>
    <div class="row">
      <div class="col-xs-6">
        <h3><%= _('Font') %></h3>
      </div>
      <div class="col-xs-6">
        <h3><%= _('Margin (mm)') %></h3>
      </div>
    </div>
    <div class="row">
      <div class="form-group col-xs-4">
        <%= label_tag "export[formatting][font_face]", _('Face'), class: 'control-label' %>
        <%= select_tag "export[formatting][font_face]",
            options_for_select(Settings::Template::VALID_FONT_FACES,
                               @export_settings.formatting[:font_face]),
            class: 'form-control',
            "data-default": @plan.template.settings(:export).formatting[:font_face] %>
      </div>
      <div class="form-group col-xs-2">
        <%= label_tag "export[formatting][font_size]", _('Size') + " (pt)", class: 'control-label' %>
        <%= select_tag "export[formatting][font_size]",
            options_for_select(Settings::Template::VALID_FONT_SIZE_RANGE.to_a, @export_settings.formatting[:font_size]),
            class: 'form-control',
            "data-default": @plan.template.settings(:export).formatting[:font_size] %>
      </div>

      <div class="form-group col-xs-1">
        <%= label_tag "export[formatting][margin][top]", _('Top'),
                      class: 'control-label' %>
        <%= select_tag "export[formatting][margin][top]",
            options_for_select(Settings::Template::VALID_MARGIN_RANGE.to_a,
                               @export_settings.formatting[:margin][:top]),
            class: 'form-control',
            "data-default": @plan.template.settings(:export).formatting[:margin][:top] %>
      </div>
      <div class="form-group col-xs-1">
        <%= label_tag "export[formatting][margin][bottom]", _('Bottom'),
                      class: 'control-label' %>
        <%= select_tag "export[formatting][margin][bottom]",
            options_for_select(Settings::Template::VALID_MARGIN_RANGE.to_a,
                               @export_settings.formatting[:margin][:bottom]),
            class: 'form-control',
            "data-default": @plan.template.settings(:export).formatting[:margin][:bottom] %>
      </div>
      <div class="form-group col-xs-1">
        <%= label_tag "export[formatting][margin][left]", _('Left'),
                      class: 'control-label' %>
        <%= select_tag "export[formatting][margin][left]",
            options_for_select(Settings::Template::VALID_MARGIN_RANGE.to_a,
                               @export_settings.formatting[:margin][:left]),
            class: 'form-control',
            "data-default": @plan.template.settings(:export).formatting[:margin][:left] %>
      </div>
      <div class="form-group col-xs-1">
        <%= label_tag "export[formatting][margin][right]", _('Right'),
                      class: 'control-label' %>
        <%= select_tag "export[formatting][margin][right]",
            options_for_select(Settings::Template::VALID_MARGIN_RANGE.to_a,
                               @export_settings.formatting[:margin][:right]),
            class: 'form-control',
            "data-default": @plan.template.settings(:export).formatting[:margin][:rigth] %>
      </div>
    </div>
  </div>

  <%= button_tag(sanitize(_('Download Plan <em class="sr-only">(new window)</em>')), class: "btn btn-primary", type: "submit") %>
<% end %>
