- @pagetitle = 'Search Owners'

.card.mb-3
  = render partial: 'tabs'
  .card-body
    %h3 Search for people responsible for package:
    .d-flex.justify-content-center
      = form_tag(search_owner_path, method: :get, class: 'my-3 w-75') do
        %input{ name: 'owner', type: 'hidden', value: '1' }
        .mb-3
          = render partial: 'webui/shared/search_box', locals: { html_id: 'search_input',
                                                                value: params[:search_text],
                                                                html_name: 'search_text',
                                                                required: true,
                                                                autofocus: true,
                                                                button: { type: 'submit', class: 'btn-primary' } }
        .row
          .d-flex.flex-wrap.flex-column.flex-sm-row
            .mb-3.row.row-cols-auto
              .form-check.form-switch.ms-1.me-4
                = hidden_field_tag('devel', 'off', id: 'nodevel')
                = check_box_tag('devel', 'on', @owner_devel.nil? || @owner_devel == '1', id: 'devel', class: 'form-check-input')
                %label.form-check-label{ for: 'devel' } Follow Devel Projects

            .mb-3.row.row-cols-auto
              - limit_options = options_for_select([['Newest', '1'], ['Oldest', '-1'], ['All', '0']], @owner_limit)
              = select_tag('limit', limit_options, class: 'form-select border-0 ps-0 w-auto')
              %label#limit-label{ for: 'limit' }
                = 'package'.pluralize(@owner_limit.abs)
    -# TODO: Ajaxify this section, so whenever changing the filters above, it fetches and refreshes the results
    - if @results.present?
      = render partial: 'results_owner', locals: { results: @results }

      - if User.session
        %ul.nav
          %li.nav-item
            = link_to('#', class: 'nav-link', data: { 'bs-toggle': 'modal', 'bs-target': '#request-bugowner-change-modal' }) do
              %i.fas.fa-exchange-alt.text-primary
              Request bugowner change
        - projects_and_packages = @results.map { |result| { project: result.project, package: result.package } }
        = render partial: 'request_bugowner_change_dialog', locals: { projects_and_packages: projects_and_packages }

- content_for :ready_function do
  :plain
    $('#limit').change(function() {
      if ($(this).val() === '0') {
        $('#limit-label').text('packages');
      }
      else {
        $('#limit-label').text('package');
      }
    });
