<div class="panel-body">
  <% if exporter.errors.any? %>
    <div id="error_explanation">
      <h2><%= pluralize(exporter.errors.count, "error") %> prohibited this exporter from being saved:</h2>

      <ul>
        <% exporter.errors.full_messages.each do |message| %>
          <li><%= message %></li>
        <% end %>
      </ul>
    </div>
  <% end %>

  <%= form.input :name, label: t('bulkrax.exporter.labels.name') %>

  <%= form.hidden_field :user_id, value: current_user.id %>

  <%= form.input :export_type,
    collection:  form.object.export_type_list,
    label: t('bulkrax.exporter.labels.export_type'),
    required: true,
    prompt: 'Please select an export type' %>

  <%= form.input :export_from,
    collection: form.object.export_from_list,
    label: t('bulkrax.exporter.labels.export_from'),
    required: true,
    prompt: 'Please select an export source' %>

  <%= form.input :export_source_importer,
    label: t('bulkrax.exporter.labels.importer'),
    required: true,
    prompt: 'Select from the list',
    label_html: { class: 'importer export-source-option hidden' },
    input_html: { class: 'importer export-source-option hidden' },
    collection:  form.object.importers_list.sort %>

  <%= form.input :export_source_collection,
    prompt: 'Start typing ...',
    label: t('bulkrax.exporter.labels.collection'),
    required: true,
    placeholder: @collection&.title&.first,
    label_html: { class: 'collection export-source-option hidden' },
    input_html: {
      class: 'collection export-source-option hidden',
      data: {
        'autocomplete-url' => '/authorities/search/collections',
        'autocomplete' => 'collection'
      }
    }
  %>

  <%= form.input :export_source_worktype,
    label: t('bulkrax.exporter.labels.worktype'),
    required: true,
    prompt: 'Select from the list',
    label_html: { class: 'worktype export-source-option hidden' },
    input_html: { class: 'worktype export-source-option hidden' },
    collection: Hyrax.config.curation_concerns.map {|cc| [cc.to_s, cc.to_s] } %>

  <%= form.input :limit,
    as: :integer,
    hint: 'leave blank or 0 for all records',
    label: t('bulkrax.exporter.labels.limit') %>

  <%= form.input :generated_metadata?,
                 as: :boolean,
                 label: t('bulkrax.exporter.labels.generated_metadata'),
                 hint: t('bulkrax.exporter.hints.generated_metadata') %>

  <%= form.input :include_thumbnails?,
                 as: :boolean,
                 label: t('bulkrax.exporter.labels.include_thumbnails'),
                 hint: t('bulkrax.exporter.hints.include_thumbnails') %>

  <%= form.input :date_filter,
                 as: :boolean,
                 label: t('bulkrax.exporter.labels.filter_by_date') %>
  <div id="date_filter_picker" class="hidden">
    <%= form.input :start_date,
                   as: :date,
                   label: t('bulkrax.exporter.labels.start_date') %>

    <%= form.input :finish_date,
                   as: :date,
                   label: t('bulkrax.exporter.labels.finish_date') %>
  </div>
  <%= form.input :work_visibility,
                 collection: form.object.work_visibility_list,
                 label: t('bulkrax.exporter.labels.visibility') %>

  <%= form.input :workflow_status,
                 collection: form.object.workflow_status_list,
                 label: t('bulkrax.exporter.labels.status') %>

  <%= form.input :parser_klass,
    collection: Bulkrax.parsers.map {|p| [p[:name], p[:class_name], {'data-partial' => p[:partial]}] if p[:class_name].constantize.export_supported? }.compact,
    label: t('bulkrax.exporter.labels.export_format') %>
</div>

<%# Find definitions for the functions called in this script in
    app/assets/javascripts/bulkrax/exporters.js %>
<script>
  $(function() {
    // show the selected export_source option
    var selectedVal = $('.exporter_export_from option:selected').val();
    hideUnhide(selectedVal);

    // Select2 dropdowns don't like taking a value param. Thus,
    // if export_source_collection is present, we populate the input.
    var selectedCollectionId = "<%= @collection&.id %>"
    if (selectedCollectionId.length > 0) {
      $('#exporter_export_source_collection').val(selectedCollectionId)
    }

    // get the selected export_from option and show the corresponding export_source
    $('.exporter_export_from').change(function() {
      var selectedVal = $('.exporter_export_from option:selected').val();
      hideUnhide(selectedVal);
    });

    // get the date filter option and show the corresponding date selectors
    $('.exporter_date_filter').change(function() {
        if($('.exporter_date_filter').find(".boolean").is(":checked"))
            $('#date_filter_picker').removeClass('hidden');
        else
            $('#date_filter_picker').addClass('hidden');
    });

    if($('.exporter_date_filter').find(".boolean").is(":checked"))
        $('#date_filter_picker').removeClass('hidden');
  });
</script>