h1
  = t("scaffold.pagetitle_index", model: Check.model_name.human(count: 2))

/= search_form_for @q do |f|
  = f.search_field :name_cont
  /= f.select :principle_id_in, options_from_collection_for_select(Principle.all.sort_by(&:name_de), :id, :name_de, filter_params[:principle_id_in]), { include_blank: false }, { multiple: true, class: "form-select" }
  = f.label :principle_id_in, "Prinzip"
  .d-flex.flex-row.mb-3
    - Principle.all.sort_by(&:name_de).each do |principle|
      .me-3
        = f.check_box :principle_id_in, checked: @q[:principle_id_in].include?(principle.id), label: principle.name_de, id: "principle_id_in_#{principle.id}"
  = f.submit
- filter_active = filter_params.to_h.any? { |_, v| v.present? }
.card.mb-3 class="#{"border-primary" if filter_active }"
  .card-header.d-flex data-bs-toggle="collapse" href="#filter-form" role="button" aria-expanded="#{filter_active}" aria-controler="filter-form" class="#{"text-bg-primary" if filter_active}"
    span.bi.bi-funnel
    strong.ms-2 Filter
  .card-body.collapse id="filter-form" class="#{"show" if filter_active}"
    = bootstrap_form_with(url: checks_path, method: :get, scope: :filter) do |form|
      = form.hidden_field :page, value: params[:page] if params[:page]
      .row
        .col-lg-12
          = form.text_field(:s, placeholder: "suchen...", class: "highlight-when-nonempty", hide_label: true, value: filter_params[:s] || "")
        .col-lg-2 
          label.fw-bold = Principle.model_name.human(count: 2)
          - Principle.all.sort_by(&:name_de).each do |principle|
            .form-check.ps-0
              = form.check_box :principle_id, { label: principle.t_name, multiple: true, checked: (filter_params[:principle_id] || []).include?(principle.id.to_s) }, principle.id, nil
        .col-lg-2
          label.fw-bold = Standard.model_name.human(count: 2)
          - Standard.all.sort_by{ _1.name_de.downcase }.each do |standard|
            .form-check.ps-0
              = form.check_box :standard_ids, { label: standard.t_name, multiple: true, checked: (filter_params[:standard_ids] || []).include?(standard.id.to_s) }, standard.id, nil
        .col-lg-2
          label.fw-bold = Check.human_attribute_name(:conformity_level)
          - Check.conformity_levels.each do |conformity_level, value|
            .form-check.ps-0
              = form.check_box :conformity_level, { label: conformity_level, multiple: true, checked: (filter_params[:conformity_level] || []).include?(value.to_s) }, value, nil
        .col-lg-2 
          label.fw-bold = Check.human_attribute_name(:priority)
          - Check.priorities.each do |priority, value|
            .form-check.ps-0
              = form.check_box :priority, { label: t("priority.#{priority}"), multiple: true, checked: (filter_params[:priority] || []).include?(value.to_s) }, value, nil
        .col-lg-2
          label.fw-bold = Check.human_attribute_name(:target_disabilities)
          - Check.target_disabilities.map { |d, _v| [I18n.t("disability.#{d}"), d] }.each do |target_disability, value|
            .form-check.ps-0
              = form.check_box :target_disabilities, { label: target_disability, multiple: true, checked: (filter_params[:target_disabilities] || []).include?(value.to_s) }, value, nil
      .row.mt-3
        .col
          = form.submit name: "", value: "Filtern"
          = link_to "Filter löschen", checks_path, class: "btn btn-primary ms-3", data: { turbo_prefetch: false } if filter_params.keys.any?

table.table.table-striped
  thead
    tr
      th
        = Check.human_attribute_name(:external_number)
      th
        = Check.human_attribute_name(:name)
      th
        = Check.human_attribute_name(:standard_ids)
      th
        = Check.human_attribute_name(:target_disabilities).truncate(10)
      th
        = Check.human_attribute_name(:applicability)
      th
        = Check.human_attribute_name(:conformity_level)
  tbody
    - @checks.each do |check|
      tr
        td = check.external_number
        td
          = link_to check.t_name, check
        td
          = check.standards.map(&:t_name).join(", ")
        td
          = check.display_target_disabilities
        td
          = check.display_applicabilities
        td
          = check.conformity_level
.my-3
  == pagy_info(@pagy)
== pagy_bootstrap_nav(@pagy) if @pagy.pages > 1
.action-row
  = link_to t("scaffold.link_new", model: Check.model_name.human), new_check_path
