-# haml-lint:disable ViewLength
= form_for(:notification, url: my_notifications_path, method: :get, id: 'content-selector-filters-form') do |form|
  - if params[:page_size]
    = hidden_field_tag 'page_size', params[:page_size]
  .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': '#notification-filter-state' },
                                              aria: { expanded: 'true', controls: 'notification-filter-state' } }
        %b State
      .px-4.pb-2.accordion-collapse.collapse.show#notification-filter-state
        = render partial: 'radio_button', locals: { label: 'All',
                                                    turbo_frame_path: count_for_notification_kinds_my_notifications_path(notification_kind: 'all'),
                                                    key: 'state[all]', name: 'state', value: 'all',
                                                    checked: selected_filter[:state] == 'all' }
        = render partial: 'radio_button', locals: { label: 'Unread',
                                                    turbo_frame_path: count_for_notification_kinds_my_notifications_path(notification_kind: 'unread'),
                                                    key: 'state[unread]', name: 'state', value: 'unread',
                                                    checked: selected_filter[:state] == 'unread' }
        = render partial: 'radio_button', locals: { label: 'Read',
                                                    turbo_frame_path: count_for_notification_kinds_my_notifications_path(notification_kind: 'read'),
                                                    key: 'state[read]', name: 'state', value: 'read',
                                                    checked: selected_filter[:state] == 'read' }
    .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': '#notification-filter-type' },
                                              aria: { expanded: 'true', controls: 'notification-filter-type' } }
        %b Type
        .selected-content.small.ms-1
      .px-4.pb-2.accordion-collapse.collapse.show#notification-filter-type
        = render partial: 'check_box', locals: { label: 'Comments',
                                                 turbo_frame_path: count_for_notification_types_my_notifications_path(notification_type: 'comments'),
                                                 key: 'kind[comments]', name: 'kind[]',
                                                 value: 'comments', label_icon: 'fas fa-comments',
                                                 checked: selected_filter[:kind]&.include?('comments') }
        = render partial: 'check_box', locals: { label: 'Requests',
                                                 turbo_frame_path: count_for_notification_types_my_notifications_path(notification_type: 'requests'),
                                                 key: 'kind[requests]', name: 'kind[]', value: 'requests',
                                                 label_icon: 'fas fa-code-pull-request',
                                                 checked: selected_filter[:kind]&.include?('requests') }
        = render partial: 'check_box', locals: { label: 'Roles Granted',
                                                 turbo_frame_path: count_for_event_types_my_notifications_path(event_type: 'relationships_created'),
                                                 key: 'kind[relationships_created]', name: 'kind[]', value: 'relationships_created',
                                                 label_icon: 'fas fa-user-tag',
                                                 checked: selected_filter[:kind]&.include?('relationships_created') }
        = render partial: 'check_box', locals: { label: 'Roles Revoked',
                                                 turbo_frame_path: count_for_event_types_my_notifications_path(event_type: 'relationships_deleted'),
                                                 key: 'kind[relationships_deleted]', name: 'kind[]', value: 'relationships_deleted',
                                                 label_icon: 'fas fa-user-tag',
                                                 checked: selected_filter[:kind]&.include?('relationships_deleted') }
        = render partial: 'check_box', locals: { label: 'Build Failures',
                                                 turbo_frame_path: count_for_event_types_my_notifications_path(event_type: 'build_failures'),
                                                 key: 'kind[build_failures]', name: 'kind[]', value: 'build_failures',
                                                 label_icon: 'fas fa-xmark text-danger',
                                                 checked: selected_filter[:kind]&.include?('build_failures') }
        - if policy(Report.new).notify?
          = render partial: 'check_box',
                            locals: { label: 'Reports',
                                      turbo_frame_path: count_for_notification_types_my_notifications_path(notification_type: 'reports'),
                                      key: 'kind[reports]', name: 'kind[]', value: 'reports',
                                      label_icon: 'fas fa-flag',
                                      checked: selected_filter[:kind]&.include?('reports') }
        = render partial: 'check_box',
                          locals: { label: 'Workflow Runs',
                                    turbo_frame_path: count_for_notification_types_my_notifications_path(notification_type: 'workflow_runs'),
                                    key: 'kind[workflow_runs]', name: 'kind[]', value: 'workflow_runs',
                                    label_icon: 'fas fa-book-open',
                                    checked: selected_filter[:kind]&.include?('workflow_runs') }
        - if Flipper.enabled?(:content_moderation, User.session)
          = render partial: 'check_box',
                            locals: { label: 'Appealed Decisions',
                                      turbo_frame_path: count_for_notification_types_my_notifications_path(notification_type: 'appealed_decisions'),
                                      key: 'kind[appealed_decisions]', name: 'kind[]', value: 'appealed_decisions',
                                      label_icon: 'fas fa-hand',
                                      checked: selected_filter[:kind]&.include?('appealed_decisions') }
        = render partial: 'check_box',
                          locals: { label: 'Groups Membership',
                                    turbo_frame_path: count_for_notification_types_my_notifications_path(notification_type: 'member_on_groups'),
                                    key: 'kind[member_on_groups]', name: 'kind[]', value: 'member_on_groups',
                                    label_icon: 'fas fa-people-group',
                                    checked: selected_filter[:kind]&.include?('member_on_groups') }
        - if Flipper.enabled?(:package_version_tracking, User.session)
          - updates_frame_path = count_for_event_types_my_notifications_path(event_type: 'upstream_package_version_changed')
          = render partial: 'check_box',
                            locals: { label: 'Version Updates',
                                      turbo_frame_path: updates_frame_path,
                                      key: 'kind[upstream_package_version_changed]', name: 'kind[]', value: 'upstream_package_version_changed',
                                      label_icon: 'fas fa-arrow-up',
                                      checked: selected_filter[:kind]&.include?('upstream_package_version_changed') }

    - if policy(Report.new).notify?
      .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': '#notification-filter-reports' },
                                                aria: { expanded: 'true', controls: 'notification-filter-reports' } }
          %b Reports
          .selected-content.small.ms-1
        .px-4.pb-2.accordion-collapse.collapse.show#notification-filter-reports
          .dropdown-item-text
            = render partial: 'webui/shared/check_box', locals: { label: 'With decision',
                                                                key: 'report[with_decision]', name: 'report[]',
                                                                value: 'with_decision',
                                                                  checked: selected_filter[:report]&.include?('with_decision') }
          .dropdown-item-text
            = render partial: 'webui/shared/check_box', locals: { label: 'Without decision',
                                                                    key: 'report[without_decision]', name: 'report[]',
                                                                    value: 'without_decision',
                                                                    checked: selected_filter[:report]&.include?('without_decision') }
          - Report::REPORTABLE_TYPES.each do |reportable_type|
            .dropdown-item-text
              = render partial: 'webui/shared/check_box', locals: { label: "For #{Report::REPORTABLE_TYPES_STRINGS[reportable_type]}",
                                                                    key: "reportable_type[#{reportable_type}]", name: 'reportable_type[]',
                                                                    value: reportable_type,
                                                                    checked: selected_filter[:reportable_type]&.include?(reportable_type.to_s) }

    .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': '#notification-filter-requests' },
                                              aria: { expanded: 'true', controls: 'notification-filter-requests' } }
        %b Requests
        .selected-content.small.ms-1
      .px-4.pb-2.accordion-collapse.collapse.show#notification-filter-requests
        .dropdown-item-text
          = render partial: 'check_box',
                            locals: { label: 'Incoming',
                                      turbo_frame_path: count_for_notification_kinds_my_notifications_path(notification_kind: 'incoming_requests'),
                                      key: 'kind[incoming_requests]', name: 'kind[]',
                                      value: 'incoming_requests',
                                      checked: selected_filter[:kind]&.include?('incoming_requests') }
        .dropdown-item-text
          = render partial: 'check_box',
                            locals: { label: 'Outgoing',
                                      turbo_frame_path: count_for_notification_kinds_my_notifications_path(notification_kind: 'outgoing_requests'),
                                      key: 'kind[outgoing_requests]', name: 'kind[]', value: 'outgoing_requests',
                                      checked: selected_filter[:kind]&.include?('outgoing_requests') }
        - BsRequest::VALID_REQUEST_STATES.each do |request_state|
          .dropdown-item-text
            = render partial: 'webui/shared/check_box', locals: { label: render(BsRequestStateBadgeComponent.new(state: request_state)),
                                                                  key: "request_state[#{request_state}]", name: 'request_state[]',
                                                                  value: request_state,
                                                                  checked: selected_filter[:request_state]&.include?(request_state.to_s) }

    - unless projects_for_filter.empty?
      .mt-2.mb-2.accordion-item.border-0
        .px-3.py-2.accordion-button.no-style{ data: { 'bs-toggle': 'collapse', 'bs-target': '#notification-filter-projects' },
                                                aria: { expanded: 'true', controls: 'notification-filter-projects' } }
          %b Projects
          .selected-content.small.ms-1
        .px-4.pb-2.accordion-collapse.collapse.show#notification-filter-projects
          #notification-project-name-dropdown
            = render partial: 'webui/shared/search_box', locals: { html_id: 'project_names_search',
                                                                     html_name: 'project[]', required: false,
                                                                     data: { source: notification_autocomplete_projects_path },
                                                                     button: { type: 'submit' } }
            .scroll-list-wrapper.auto-submit-on-change
              - selected_filter[:project].each do |project_name|
                .dropdown-item-text
                  = render partial: 'webui/shared/check_box', locals: { label: project_name,
                                                                        key: "project[#{project_name}]", name: 'project[]',
                                                                        value: project_name,
                                                                        checked: selected_filter[:project]&.include?(project_name) }
      .mt-2.mb-2.accordion-item.border-0
        .px-3.py-2.accordion-button.no-style{ data: { 'bs-toggle': 'collapse', 'bs-target': '#notification-filter-labels' },
                                                aria: { expanded: 'true', controls: 'notification-filter-labels' } }
          %b Labels
          .selected-content.small.ms-1
        .px-4.pb-2.accordion-collapse.collapse.show#notification-filter-labels
          #notification-labels-dropdown
            = render partial: 'webui/shared/search_box', locals: { html_id: 'labels_search',
                                                                     html_name: 'labels[]', required: false,
                                                                     data: { source: autocomplete_labels_path },
                                                                     button: { type: 'submit' } }
            .scroll-list-wrapper.auto-submit-on-change
              - selected_filter[:labels].each do |label|
                .dropdown-item-text
                  = render partial: 'webui/shared/check_box', locals: { label: label,
                                                                        key: "labels[#{label}]", name: 'labels[]',
                                                                        value: label,
                                                                        checked: selected_filter[:labels]&.include?(label) }
    - unless groups_for_filter.empty?
      .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': '#notification-filter-groups' },
                                                aria: { expanded: 'true', controls: 'notification-filter-groups' } }
          %b Groups
          .selected-content.small.ms-1
        .px-4.pb-2.accordion-collapse.collapse.show#notification-filter-groups
          .scroll-list-wrapper
            - groups_for_filter.each do |group_title|
              .dropdown-item-text
                = render partial: 'webui/shared/check_box', locals: { label: group_title,
                                                                      key: "group[#{group_title}]", name: 'group[]', value: group_title,
                                                                      checked: selected_filter[:group]&.include?(group_title) }

  .text-center.mt-4.mb-4
    = link_to('Clear', my_notifications_path, class: 'btn btn-light border')

- content_for(:content_for_head, javascript_include_tag('webui/content-selector-filters'))
-# haml-lint:enable ViewLength
