- workflow_instances_scope = @record.workflow_instances.scope_for(current_user, archived: session[:archived_mode])
.display-row
  .display-label= page_title :show, workflow_instance_batch_class
  .display-field
    h3
      = @record.presentation_name
      = "(#{workflow_instances_scope.size})"
      - if can? :edit, @record
        = link_to '', [:edit, @record], class: 'edit-icon'
.display-row
  .display-label= workflow_instance_batch_class.human_attribute_name(:plan_date)
  .display-field= @record.plan_date

.workflow-step-workfow-instances-collection-container
  = safe_join workflow_instances_scope.map{|workflow_instance| link_to workflow_instance.presentation_name, workflow_instance, class: workflow_instance.state}, ', '
.batch-states-collection-container
  - workflow_instances_scope.group(:state).count.each do |state, count|
    span.state= state_badge workflow_instance_class.new(state: state), state_append_text: " (#{count})", link_to: polymorphic_path(workflow_instance_class, q: {state_eq: state, workflow_instance_batch_id_eq: @record.id})
.workflow-instance-batch-actions
  - previous_step_unfinished = nil
  - @record.workflow_step_map(current_user).each do |workflow_step, records|
    .row.workflow-step-container
      .small-12.columns
        h4
          = workflow_step.model_name.human
          = workflow_step_button_for workflow_step, request_params: {workflow_instance_batch_id: @record.id}, confirmation: (previous_step_unfinished.present? ? t('workflow_step.previous_step_not_finished_warning', step_name: previous_step_unfinished.model_name.human) : nil)
        - state_counts = records.group("#{workflow_step.table_name}.state").count
        - state_counts.each do |state, count|
          span.state= state_badge workflow_step.new(state: state), state_append_text: " (#{count})", data: {workflow_instance_batch_id: @record.id}
    - previous_step_unfinished = (state_counts.keys - workflow_step.final_states).any? ? workflow_step : nil
.page-actions
  = link_to t('workflow_instance_batch.to_index_button'), workflow_instance_batch_class, class: 'back'
  - if can? :manage, workflow_instance_class
    button.collection-edit data-action="collection_edit" data-resource=workflow_instance_class.name.underscore data-request-params={workflow_instance_batch_id: @record.id}.to_json
      = t 'workflow_instance_batch.edit_dslams_button', models: workflow_instance_class.model_name.human_plural
  = link_to t('workflow_instance_batch.show_dslams_button'), polymorphic_path([:selection, workflow_instance_class], workflow_instance_batch_id: @record.id), class: 'show-workflow_instance_batch-workflow_instances'
  - if can? :download, workflow_instance_class
    = link_to t('workflow_instance.export_button'), {format: :csv}, class: 'export-button'
