table.with-selection data-resource=record_class.name.underscore data-record-count=(@records.total_count rescue @records.size) data-preselected=local_assigns[:preselected]
  thead
    tr
      th= sort_link @q, :id
      - if local_assigns[:show_scenario]
        th= at :scenario
      th= at :state
      th= at :plan_date
      th= sort_link @q, :bucket
      th= WorkflowInstanceBatch.model_name.human
      th= t 'workflow_instance.progress_display.title'
      /th.actions
    - unless local_assigns[:filters] == false
      = search_form_for @q do |f|
        = hidden_field_tag :per_page, params[:per_page], id: 'q_per_page'
        = search_row do
          th.column-filter
          - if local_assigns[:show_scenario]
            th.column-filter.scenario= f.select :sti_type_eq, WorkflowInstance.workflow_step_classes.map{|step| [step.model_name.human, step.name]}, include_blank: 'all'
          th.column-filter.state= f.select :state_eq, WorkflowInstance.state_machine.states.map{|state| [state.human_name, state.name]}, include_blank: 'all'
          th.column-filter.plan_date
          th.column-filter.bucket= f.search_field :bucket_cont, placeholder: 'contains', class: 'autocomplete', data: {source: record_class.available_bucket_names}
          th.column-filter.workflow_instance_batch= f.select :workflow_instance_batch_id_eq, record_batch_class.for_select, {include_blank: 'all'}, class: 'search-select'
          th.column-filter.actions
            = f.submit t('dunlop.filter.apply').html_safe, class: 'submit-filters-button'
            = link_to record_class, class: 'clear-filters-button' do
              span== t('dunlop.filter.reset')
  tbody
    - @records.each do |record|
      tr data-record={ id: record.id }.to_json class=(record.archived? ? 'archived' : 'active')
        td= link_to record.presentation_name, record
        - if local_assigns[:show_scenario]
          td.scenario= record.model_name.human
        td.state= state_badge record
        td.plan_date data-date=record.plan_date.try(:iso8601)
        td.bucket= record.bucket
        td.workflow_instance_batch
          - if record.workflow_instance_batch.present?
            = link_to record.workflow_instance_batch.presentation_name, record.workflow_instance_batch
        td.progress-display= show_workflow_progress_of record
        /td.actions= table_show_link record
  - unless local_assigns[:hide_buttons]
    tfoot
      tr
        td colspan=99
          - if can?(:edit, record_class) or can?(:archive, record_class) or can?(:reset, record_class)
            button.collection-edit.workflow_instance-actions data-resource=record_class.name.underscore data-request-params='{"ids": "selected_ids"}' = t 'collection.edit_button', models: record_class.model_name.human_plural
          = workflow_step_buttons_for record_class
          - if can? :download, record_class
            = link_to t('workflow_instance.export_button'), {q: params[:q].try(:permit!), ids: params[:ids], format: :csv}, class: 'export-button'
= render "dunlop/workflow_instance/categorize_as_button"
