<div class="header">
  <div class="header-inner">
    <h5 class="header-name">Import issues</h5>
    <div class="options">
      <%= link_to '#import-box', 
        class: 'import-toggle', 
        data: { bs_toggle: 'collapse', behavior: 'collapse-collection import-box-header' } do %>
        <i class="fa-solid fa-chevron-up" data-behavior="toggle-chevron"></i><span class="visually-hidden">Toggle import box</span>
      <% end %>
    </div>
  </div>
</div>

<%= content_tag :div, class: 'import-box collapse show', id: 'import-box', data: { behavior: 'import-box' } do %>
  <% if Dradis::Plugins::with_feature(:import).empty? %>
    <p>
      Connect Dradis to a library of issue descriptions so you don't have to
      copy & paste findings from an old report.
    </p>
    <p class="mb-2">Libraries:</p>
    <ul class="fa-ul">
      <li><i class="fa-solid fa-li fa-chevron-right"></i>
        <a href="https://dradis.com/integrations/mediawiki.html?utm_source=ce&utm_medium=app" target="_blank">
          MediaWiki
        </a>
      </li>
      <li><i class="fa-solid fa-li fa-chevron-right"></i>
        <%= link_to main_app.static_issuelib_path do %>
          <i class="fa-solid fa-book"></i> Built-in Issue Library
        <% end %>
      </li>
    </ul>
    <form action="<%=  main_app.static_issuelib_import_path %>" class="form-inline mb-4" method="get">
      <div class="inset-button-wrapper">
        <input type="text" class="form-control search-query", placeholder="Search Issue Library" />
        <button type="submit" class="btn btn-primary">Search</button>
      </div>
    </form>
  <% else %>
    <% Dradis::Plugins::with_feature(:import).each do |plugin| %>
      <div>
        <p class="mb-2"><%= plugin.plugin_description %></p>

        <% if Dradis::Plugins::Import::Filters[plugin.plugin_name] %>
          <% Dradis::Plugins::Import::Filters[plugin.plugin_name].each do |label, klass| %>
            <% next if label == :find_one_by_field %>

            <%= form_tag main_app.import_project_issues_path, class: 'mb-4' do %>
              <%= hidden_field_tag :scope, plugin.plugin_name, id: "scope_#{plugin.plugin_name}" %>
              <%= hidden_field_tag :filter, label, id: "filter_#{plugin.plugin_name}" %>
              <% query = @query if (@plugin == plugin.plugin_name) && (@filter == klass) %>
              <div class="inset-button-wrapper">
                <%= label_tag "query_#{plugin.plugin_name}", "Search #{plugin.plugin_name}", class: 'visually-hidden' %>
                <%= search_field_tag :query, query, id: "query_#{plugin.plugin_name}", class: 'form-control search-query', placeholder: "Search #{plugin.plugin_name}" %>
                <button type="submit" class="btn btn-primary">Search</button>
              </div>
            <% end %>
          <% end %>
        <% else %>
          <p class="small">This plugin doesn't define any import filters. Contact the plugin author.</p>
        <% end %>
      </div>
    <% end %>
  <% end %>
<% end %>
