-# haml-lint:disable ViewLength
:ruby
  status_info_text = '<p>Filter your workflow runs by the current state</p>
                      <p><b>Succeeded: </b>Workflow run execution was successful</p>
                      <p><b>Running: </b>Workflow run is still in progress</p>
                      <p><b>Failed: </b>Workflow run failed at some point</p>'
  event_type_info_text = '<p>Filter your workflow runs by the event reported by the SCM,
                          which triggered the execution in the Open Build Service</p>
                          <p><b>Pull/Merge request: </b>
                          A pull/merge request got opened against a selected branch</p>
                          <p><b>Push: </b>A push event occured on a selected branch</p>'
  pr_mr_request_info_text = '<p>Filter your workflow runs by the action type: be aware <b>only Pull/Merge Request</b>
                             Event Type has an action parameter value</p>'
  event_source_info_text = '<p>Filter your workflow runs by the event source. The event source
                            is what triggered this workflow on the SCM.</p>
                            <p> A pull/merge request number like <em>12345</em></p>
                            <p>or a git commit hash like
                            <em>97561db8664eaf86a1e4c7b77d5fb5d5bff6681e</em></p>'

= form_for(:token, url: token_workflow_runs_path(@token), method: :get, id: 'content-selector-filters-form') do |form|
  .accordion.accordion-flush
    .mt-2.mb-2.accordion-item.border-0.auto-submit-on-change
      .px-3.py-2.accordion-button.no-style{ data: { 'bs-toggle': 'collapse', 'bs-target': '#workflow-filter-status' },
                                              aria: { expanded: 'true', controls: 'workflow-filter-status' } }
        %b Status
        %span.ms-1
          = render partial: 'webui/shared/info_popover', locals: { position: 'bottom', text: status_info_text }
        .selected-content.small.ms-1
      .px-4.pb-2.accordion-collapse.collapse.show#workflow-filter-status
        = render partial: 'webui/shared/check_box', locals: { label: 'Succeeded', amount: @count['success'] || 0,
                                                              key: 'success', label_icon: 'fas fa-check text-primary',
                                                              checked: @selected_filter[:status]&.include?('success')}
        = render partial: 'webui/shared/check_box', locals: { label: 'Running', amount: @count['running'] || 0,
                                                              key: 'running', label_icon: 'fas fa-running',
                                                              checked: @selected_filter[:status]&.include?('running')}
        = render partial: 'webui/shared/check_box', locals: { label: 'Failed', amount: @count['fail'] || 0,
                                                              key: 'fail', label_icon: 'fas fa-exclamation-triangle text-danger',
                                                              checked: @selected_filter[:status]&.include?('fail')}
    .mt-4.mb-2.accordion-item.border-0.auto-submit-on-change
      .px-3.py-2.accordion-button.no-style{ data: { 'bs-toggle': 'collapse', 'bs-target': '#workflow-filter-event-type' },
                                              aria: { expanded: 'true', controls: 'workflow-filter-event-type' } }
        %b Event Type
        %span.ms-1
          = render partial: 'webui/shared/info_popover', locals: { position: 'bottom', text: event_type_info_text }
        .selected-content.small.ms-1
      .px-4.pb-2.accordion-collapse.collapse.show#workflow-filter-event-type
        = render partial: 'webui/shared/check_box', locals: { label: 'Pull/Merge Request', amount: @count['pull_request'] || 0,
                                                              key: 'pull_request', checked: @selected_filter[:event_type]&.include?('pull_request')}
        = render partial: 'webui/shared/check_box', locals: { label: 'Push', amount: @count['push'] || 0,
                                                              key: 'push', checked: @selected_filter[:event_type]&.include?('push')}
        = render partial: 'webui/shared/check_box', locals: { label: 'Tag Push', amount: @count['tag_push'] || 0,
                                                              key: 'tag_push', checked: @selected_filter[:event_type]&.include?('tag_push')}

    .mt-4.mb-2.accordion-item.border-0.auto-submit-on-change
      .px-3.py-2.accordion-button.no-style{ data: { 'bs-toggle': 'collapse', 'bs-target': '#workflow-filter-event-action' },
                                              aria: { expanded: 'true', controls: 'workflow-filter-event-action' } }
        %b Event Action
        %span.ms-1
          = render partial: 'webui/shared/info_popover', locals: { position: 'bottom', text: pr_mr_request_info_text }
        .selected-content.small.ms-1
      .px-4.pb-2.accordion-collapse.collapse.show#workflow-filter-event-action
        = render partial: 'webui/shared/select', locals: { filter_item: 'request_action',
                                                          selected_value: @selected_filter[:request_action],
                                                          filter_options: WorkflowRun::ALL_POSSIBLE_REQUEST_ACTIONS,
                                                          label: 'Action', visible_inner_label: true }
    .mt-4.mb-2.accordion-item.border-0.auto-submit-on-change
      .px-3.py-2.accordion-button.no-style{ data: { 'bs-toggle': 'collapse', 'bs-target': '#workflow-filter-event-source' },
                                              aria: { expanded: 'true', controls: 'workflow-filter-event-source' } }
        %b Event Source
        %span.ms-1
          = render partial: 'webui/shared/info_popover', locals: { position: 'bottom', text: event_source_info_text }
        .selected-content.small.ms-1
      .px-4.pb-2.accordion-collapse.collapse.show#workflow-filter-event-source
        = render partial: 'webui/shared/input', locals: { html_id: 'pr_mr',
                                                          class: 'auto-submit-on-change',
                                                          placeholder: 'eg. 12345',
                                                          label: 'PR/MR',
                                                          value: @selected_filter[:pr_mr] }
        .mt-1
          = render partial: 'webui/shared/input', locals: { html_id: 'commit_sha',
                                                            class: 'auto-submit-on-change',
                                                            placeholder: 'eg. 97561db8664eaf86a1e4c7b77d5fb5d5bff6681e',
                                                            label: 'Commit',
                                                            value: @selected_filter[:commit_sha] }
  .text-center.mt-4.mb-4
    = link_to('Clear', token_workflow_runs_path(@token, []), class: 'btn btn-light border')

- content_for(:content_for_head, javascript_include_tag('webui/content-selector-filters'))
