- content_for(:title, "#{@procedure.libelle}")

#procedure-show
  .sub-header
    .container.flex

      .procedure-logo{ style: @procedure.logo.present? ? "background-image: url(#{@procedure.logo.url})" : nil,
        role: 'img', 'aria-label': "logo de la procédure #{@procedure.libelle}" }

      .procedure-header
        %h1= procedure_libelle @procedure

        %ul.tabs
          = tab_item('à suivre',
            gestionnaire_procedure_path(@procedure, statut: 'a-suivre'),
            active: @statut == 'a-suivre',
            badge: @a_suivre_dossiers.count)

          = tab_item(t('pluralize.followed', count: @followed_dossiers.count),
            gestionnaire_procedure_path(@procedure, statut: 'suivis'),
            active: @statut == 'suivis',
            badge: @followed_dossiers.count,
            notification: current_gestionnaire.notifications_for_procedure(@procedure).present?)

          = tab_item(t('pluralize.processed', count: @termines_dossiers.count),
            gestionnaire_procedure_path(@procedure, statut: 'traites'),
            active: @statut == 'traites',
            badge: @termines_dossiers.count,
            notification: current_gestionnaire.notifications_for_procedure(@procedure, :termine).present?)

          = tab_item('tous les dossiers',
            gestionnaire_procedure_path(@procedure, statut: 'tous'),
            active: @statut == 'tous',
            badge: @all_state_dossiers.count)

          = tab_item(t('pluralize.archived', count: @archived_dossiers.count),
            gestionnaire_procedure_path(@procedure, statut: 'archives'),
            active: @statut == 'archives',
            badge: @archived_dossiers.count)

      .procedure-actions
        = render partial: "download_dossiers", locals: { procedure: @procedure }

  .container
    - if @dossiers.present? || @current_filters.count > 0
      %span.button.dropdown
        Filtrer
        .dropdown-content.left-aligned.fade-in-down
          = form_tag add_filter_gestionnaire_procedure_path(@procedure), method: :post, class: 'dropdown-form large' do
            = label_tag :field,  "Colonne"
            = select_tag :field, options_for_select(@available_fields_to_filters)
            %br
            = label_tag :value, "Valeur"
            = text_field_tag :value
            = hidden_field_tag :statut, @statut
            %br
            = submit_tag "Ajouter le filtre", class: 'button'

      - @current_filters.each do |filter|
        %span.filter
          = "#{filter['label']} : #{filter['value']}"
          = link_to remove_filter_gestionnaire_procedure_path(@procedure, statut: @statut, table: filter['table'], column: filter['column']) do
            %img.close-icon{ src: image_url("close.svg") }

      %table.table.dossiers-table.hoverable
        %thead
          %tr
            - if @statut == 'suivis' || @statut == 'tous'
              = render partial: "header_field", locals: { field: { "label" => "●", "table" => "notifications", "column" => "notifications" }, classname: "notification-col" }
            - else
              %th.notification-col

            = render partial: "header_field", locals: { field: { "label" => "Nº dossier", "table" => "self", "column" => "id" }, classname: "number-col" }

            - @displayed_fields.each do |field|
              = render partial: "header_field", locals: { field: field, classname: "" }

            = render partial: "header_field", locals: { field: { "label" => "Statut", "table" => "self", "column" => "state" },  classname: "status-col" }

            %th.follow-col
              %span.button.dropdown
                Personnaliser
                .dropdown-content.fade-in-down
                  = form_tag update_displayed_fields_gestionnaire_procedure_path(@procedure), method: :patch, class: 'dropdown-form' do
                    = select_tag :values,
                      options_for_select(@procedure.fields_for_select,
                        selected: @displayed_fields_values),
                      multiple: true,
                      class: 'select2-limited'
                    = submit_tag "Enregistrer", class: 'button'

        %tbody
          - @dossiers.each do |dossier|
            %tr
              %td.folder-col
                = link_to(gestionnaire_dossier_path(@procedure, dossier), class: 'cell-link') do
                  %span.icon.folder
                    - if current_gestionnaire.notifications_for_procedure(@procedure, :not_archived).include?(dossier.id)
                      %span.notifications{ 'aria-label': 'notifications' }

              %td.number-col
                = link_to(gestionnaire_dossier_path(@procedure, dossier), class: 'cell-link') do
                  = dossier.id

              - @displayed_fields.each do |field|
                %td
                  = link_to(gestionnaire_dossier_path(@procedure, dossier), class: 'cell-link') do
                    = dossier.get_value(field['table'], field['column'])

              %td.status-col
                = link_to(gestionnaire_dossier_path(@procedure, dossier), class: 'cell-link') do
                  = render partial: 'shared/dossiers/status', locals: { dossier: dossier }
              %td.follow-col= render partial: 'dossier_actions', locals: { procedure: @procedure, dossier: dossier, dossier_is_followed: @followed_dossiers_id.include?(dossier.id) }
      = paginate @dossiers
    - else
      %h2.empty-text Aucun dossier
