= page-title 'action_list.title'
  = pagination-progress content=model.project_instance_actions class='between-brackets'
  i.pointable.refresh.icon{action 'reload' model.project_instance_actions}
  .ui.top-right.pagination.menu= page-numbers content=model.project_instance_actions showFL=true
.ui.attached.segment
  if globals.current_user.admin
    .pull-right= user-filters-manager scope_key='panda/action-list' content=model.project_instance_actions
  = ui-dropdown class='violet button pull-right'
    .default.text Export
    i.dropdown.icon
    .menu
      .item
        a href=export_human_url: span Human
      .item
        a href=export_technical_url: span Technical
  /= action-list/project-filter apply_filters=(action 'apply_filters') filters=filters scope_project=scope_project scope_scenario=scope_scenario projects=model.projects
  /= action-list/organization-filter apply_filters=(action 'apply_filters') filters=filters scope_organization=scope_organization organizations=model.organizations
  .clearfix
table.ui.attached.stiped.sortable.table
  thead
    tr
      th= t 'models.organization'
      th= t 'models.project'
      th= t 'models.project_scenario'
      th= t 'models.project_instance_group'
      th= t 'models.workflow_action_definition'
      = sortable-table-header filters=filters key='project_instance_client_identifier' model=model.project_instance_actions defaultDirection='asc'
        = t 'models.project_instance'
      th= t 'attributes.project_instance_action.state'
      th= t 'attributes.project_instance_action.notes'
      = sortable-table-header filters=filters key='target_date' model=model.project_instance_actions defaultDirection='asc'
        = t 'attributes.project_instance_action.target_date'
      if show_completed_at
        = sortable-table-header filters=filters key='completed_at' model=model.project_instance_actions defaultDirection='desc'
          = t 'attributes.project_instance_action.completed_at'
      if show_inquiry_at
        = sortable-table-header filters=filters key='inquiry_at' model=model.project_instance_actions defaultDirection='desc'
          = t 'attributes.project_instance_action.inquiry_at'
      th= t 'attributes.project_instance_action.value'
    table-filters content=model.project_instance_actions apply_filters=(action 'apply_filters') as |filter|
      = filter.dropdown-select-multiple key='workflow_action_definition_organization_id_in' options=model.organizations labelPath='name'
      = filter.dropdown-select-multiple key='project_id_in' options=sorted_projects labelPath='name'
      if (and scope_project scope_project.isLoaded)
        = filter.dropdown-select-multiple key='project_instance_project_scenario_id_in'     options=scope_project.sorted_project_scenarios labelPath='name'
        = filter.dropdown-select-multiple key='project_instance_group_workflow_group_id_in' options=scope_project.sorted_workflow_groups labelPath='name'
        = filter.dropdown-select-multiple key='workflow_action_definition_identifier_in'    options=scope_project.sorted_workflow_action_definitions labelPath='title' valuePath='identifier'
      else
        th
        th
        = filter.input key='workflow_action_definition_title_cont'
      = filter.input key='project_instance_client_identifier_cont'
      = filter.dropdown-select-multiple key='state_in' options=globals.project_instance_action.states translationPath='attributes.state'
      = filter.input key='notes_cont'
      = filter.date-range key='target_date' expandingTime=true weekSelector=true
      if show_completed_at
        = filter.date-range key='completed_at' expandingTime=true weekSelector=true
      if show_inquiry_at
        = filter.date-range key='inquiry_at' expandingTime=true weekSelector=true
      th
  tbody
    if model.project_instance_actions.loading
      tr
        td colspan=99
          .ui.active.inline.centered.loader
    else
      each model.project_instance_actions as |project_instance_action|
        tr.record-with-pointing-records
          td= project_instance_action.workflow_action_definition.organization.name
          td= project_instance_action.project.name
          td= project_instance_action.project_instance.project_scenario.name
          td
            if project_instance_action.project_instance_group.id
              if (can 'read' 'model' 'panda/project-instance')
                = link-to 'project.show.project-instance-group.show' project_instance_action.project_instance.project.id project_instance_action.project_instance_group.id
                  = project_instance_action.project_instance_group.workflow_group.name
              else
                = project_instance_action.project_instance_group.workflow_group.name
          td= project_instance_action.workflow_action_definition.title
          td
            if (can 'read' 'model' 'panda/project-instance')
              = link-to 'project.show.project-instance.show' project_instance_action.project_instance.project.id project_instance_action.project_instance.id
                = project_instance_action.project_instance.client_identifier
              else
                = project_instance_action.project_instance.client_identifier
          td= state-badge project_instance_action.state action=(action 'edit_project_instance_action' project_instance_action)
          td= project-instance-action/compact-notes-display record=project_instance_action
          td= format-date project_instance_action.target_date format=globals.date_formatting
          if show_completed_at
            td= format-date project_instance_action.completed_at format=globals.time_formatting
          if show_inquiry_at
            td= format-date project_instance_action.inquiry_at format=globals.time_formatting
          td= project/instance-action-value-display project_instance_action=project_instance_action
        /each project_instance_action.pointing_project_instance_action_connections as |project_instance_action_connection|
          if (eq project_instance_action_connection.connection_type 'attached')
            tr.pointing-record
              unless scope_project
                td= project_instance_action_connection.project_instance_action.project.name
              unless scope_scenario
                td= project_instance_action_connection.project_instance_action.project_instance.project_scenario.name
              unless scope_organization
                td= project_instance_action_connection.project_instance_action.workflow_action_definition.organization.name
              td
                if project_instance_action_connection.project_instance_action.project_instance_group.id
                  if (can 'read' 'model' 'panda/project-instance')
                    = link-to 'project.show.project-instance-group.show' project_instance_action.project_instance.project.id project_instance_action.project_instance_group.id
                      = project_instance_action.project_instance_group.workflow_group.name
                  else
                    = project_instance_action.project_instance_group.workflow_group.name
              td= project_instance_action_connection.project_instance_action.workflow_action_definition.title
              td
                if (can 'read' 'model' 'panda/project-instance')
                  = link-to 'project.show.project-instance.show' project_instance_action.project_instance.project.id project_instance_action.project_instance.id
                    = project_instance_action.project_instance.client_identifier
                else
                  = project_instance_action.project_instance.client_identifier
              td= state-badge project_instance_action_connection.project_instance_action.state action=(action 'edit_project_instance_action' project_instance_action_connection.project_instance_action)
              td
                if (gt project_instance_action_connection.project_instance_action.notes.length 14)
                  = ui-markdown-popup tagName='i' class='sticky note outline icon' markdown=project_instance_action_connection.project_instance_action.notes
                else if project_instance_action_connection.project_instance_action.notes
                  = project_instance_action_connection.project_instance_action.notes
                if project_instance_action_connection.project_instance_action.workflow_action_definition.extra_info
                  '
                  = ui-markdown-popup tagName='i' class='info circle icon' markdown=project_instance_action_connection.project_instance_action.workflow_action_definition.extra_info
              td= format-date project_instance_action_connection.project_instance_action.target_date
              td= project/instance-action-value-display project_instance_action=project_instance_action_connection.project_instance_action
