workflow-action-definition/modal-header model=model
table.ui.compact.definition.table
  tr
    td= t 'attributes.identifier'
    td= model.changeset.identifier
  tr
    td= t 'attributes.workflow_action_definition.title'
    td= validated-input attribute='title' changeset=model.changeset enter=(action 'saveRecord' (hash trigger='title-action'))
  tr
    td= t 'attributes.workflow_action_definition.value_type'
    td
      = ui-dropdown class='selection' selected=model.changeset.value_type onChange=(action (mut model.changeset.value_type)) as |execute mapper|
        .default.text= t 'action.select_model' modelPath='attributes.workflow_action_definition.value_type'
        i.dropdown.icon
        .menu
          each value_type_options as |value_type|
            .item data-value=value_type
              = value-type-display type=value_type
              = t value_type scope='workflow_action_definition.value_type'
  if (eq model.changeset.value_type 'select')
    tr
      td= t 'attributes.workflow_action_definition.value_type_select_options'
      td
        = ui-dropdown class='multiple fluid search selection' selected=model.changeset.value_type_select_options onChange=(action (mut model.changeset.value_type_select_options)) allowAdditions=true
          .default.text options
          i.dropdown.icon
          .menu
            each model.changeset.value_type_select_options as |option|
              .item= option
  tr
    td= t 'attributes.workflow_action_definition.extra_info'
    td= textarea value=model.extra_info
  tr
    td= t 'models.organization'
    td
      = ui-dropdown class='search selection' selected=model.changeset.organization onChange=(action 'selectOrganization') fullTextSearch=true as |execute mapper|
          .default.text= t 'action.select_model' modelPath='models.organization'
          i.dropdown.icon
          .menu
            .item data-value='{{map-value mapper null}}' --
            each possible_organizations as |organization|
              .item data-value='{{map-value mapper organization}}'
                if organization.logo
                  img src=organization.logo_url.small
                = organization.name
  tr
    td= t 'attributes.workflow_action_definition.completes_group'
    td= ui-checkbox checked=model.changeset.completes_group onChange=(action (mut model.changeset.completes_group))
  tr
    td= t 'attributes.workflow_action_definition.confirms_workflow_action_definition'
    td= model.confirms_workflow_action_definition.title
  tr
    td= t 'attributes.workflow_action_definition.confirmed_by_workflow_action_definition'
    td= model.confirmed_by_workflow_action_definition.title
  if model.project_scenarios.length
    tr
      td= t 'models.plural.project_scenario'
      td= join ', ' (map-by 'name' model.project_scenarios)

.ui.dividing.header
  .ui.right.floated.buttons
    .ui.button class=offset_type_none:active click="set_offset_type_none"
      span= t 'workflow_action_definition.edit_workflow_action_definition.no_offset'
    .or
    .ui.button class=offset_type_attached:active click='set_offset_type_attached'
      = t 'workflow_action_definition.edit_workflow_action_definition.attached_offset'
    .or
    .ui.button class=offset_type_configured:active click='set_offset_type_configured'
      = t 'workflow_action_definition.edit_workflow_action_definition.configured_offset'
  .content
    if offset_type_configured
      = t 'models.plural.workflow_action_offset'
      span &nbsp;
      = push-action type='new' action='add_workflow_action_offset'
    else
      = t 'models.workflow_action_offset'
if offset_type_attached
  span create connection to other action
  table.ui.compact.definition.table
    tr
      td= t 'models.workflow_action_definition'
      td
        = ui-dropdown class='search selection' selected=attached_to_workflow_action_workflow_group onChange=(action 'set_attached_to_workflow_action_workflow_group') fullTextSearch=true as |execute mapper|
          .default.text= t 'action.select_model' modelPath='models.workflow_group'
          i.dropdown.icon
          .menu
            each model.project.sorted_workflow_groups as |workflow_group|
              .item data-value='{{map-value mapper workflow_group}}'
                = workflow_group.name
        = ui-dropdown class='search selection' selected=attached_to_workflow_action onChange=(action 'set_attached_to_workflow_action') fullTextSearch=true as |execute mapper|
          .default.text= t 'action.select_model' modelPath='models.workflow_action_definition'
          i.dropdown.icon
          .menu
            .item data-value='{{map-value mapper null}}' --
            each possible_attached_to_workflow_action_workflow_action_definitions as |workflow_action_definition|
              .item data-value='{{map-value mapper workflow_action_definition}}'
                = workflow_action_definition.title
        if attached_to_connection_warning
          .ui.negative.message= attached_to_connection_warning
    tr
      td= t 'attributes.workflow_action_connection.conditional_base_value'
      td
        if (eq attached_to_workflow_action.value_type 'boolean')
          = ui-dropdown selected=attached_to_connection_conditional_base_value onChange=(action (mut attached_to_connection_conditional_base_value))
            span.default.text --
            i.dropdown.icon
            .menu
              .item data-value=''
                i.square.outline.icon
              .item data-value='true'
                i.check.square.outline.icon
        else if (eq attached_to_workflow_action.value_type 'select')
          = ui-dropdown selected=attached_to_connection_conditional_base_value onChange=(action (mut attached_to_connection_conditional_base_value))
            span.default.text -
            i.dropdown.icon
            .menu
              .item data-value=''
                span -
              each attached_to_workflow_action.value_type_select_options as |option|
                .item data-value=option
                  = option
        else
          = input value=attached_to_connection_conditional_base_value

if offset_type_configured
  if new_workflow_action_offset_warning
    .ui.visible.negative.message= new_workflow_action_offset_warning
  each non_deleted_working_workflow_action_offsets as |offset|
    table.ui.compact.definition.table
      tr
        td= t 'attributes.workflow_action_offset.base_workflow_action_definition'
        td
          unless offset.x_based
            = push-action type='destroy' action=(action 'destroyWorkflowActionOffset' offset) class='pull-right'
            = ui-dropdown class='search selection' selected=offset.selector_workflow_group onChange=(action 'set_selector_workflow_group' offset) fullTextSearch=true as |execute mapper|
              .default.text= t 'action.select_model' modelPath='models.workflow_group'
              i.dropdown.icon
              .menu
                each model.project.sorted_workflow_groups as |workflow_group|
                  .item data-value='{{map-value mapper workflow_group}}'
                    = workflow_group.name
            = ui-dropdown class='search selection' selected=offset.base_workflow_action_definition onChange=(action 'set_base_workflow_action_definition' offset) fullTextSearch=true as |execute mapper|
              .default.text= t 'action.select_model' modelPath='models.workflow_action_definition'
              i.dropdown.icon
              .menu
                .item data-value='{{map-value mapper null}}' --
                each offset.filtered_workflow_action_definitions as |workflow_action_definition|
                  .item data-value='{{map-value mapper workflow_action_definition}}'
                    = workflow_action_definition.title
          ui-checkbox class='toggle' label='X-based' checked=offset.x_based onChange=(action 'toggle_offset_x_based' offset)
          if offset.base_workflow_action_definition_warning
            .ui.negative.message= offset.base_workflow_action_definition_warning
      tr
        td= t 'attributes.workflow_action_definition.offset_value'
        td= select-duration value=offset.offset_value unit=offset.offset_unit week_days=offset.offset_business_days
      if model.project.instance_scope_batch
        tr
          td= t 'attributes.workflow_action_definition.batch_element_threshold'
          td= select-duration value=offset.batch_element_threshold_value unit=offset.batch_element_threshold_unit week_days=offset.batch_element_threshold_business_days threshold=true
      if model.project.project_scenarios.length
        tr
          td= t 'models.project_scenario'
          td
            = ui-dropdown class='search selection' selected=offset.project_scenario onChange=(action (mut offset.project_scenario)) as |execute mapper|
                .default.text= t 'action.select_model' modelPath='models.project_scenario'
                i.dropdown.icon
                .menu
                  .item data-value='{{map-value mapper null}}' --
                  each model.project.project_scenarios as |project_scenario|
                    .item data-value='{{map-value mapper project_scenario}}'
                      = project_scenario.name
  else
    .ui.visible.warning.message= t 'workflow_action_definition.edit_workflow_action_definition.no_workflow_action_offsets_present'

unless offset_type_none
  .ui.divider
h3.ui.dividing.header: .content
  = t 'workflow_action_definition.pointing_connections_title'
  '
  = push-action type='new' action='add_workflow_action_connection'
each non_deleted_working_pointing_workflow_action_connections as |pointing_connection|
  unless (eq pointing_connection.connection_type 'attached')
    .ui.segment
      = pointing_connection.workflow_action_definition.title
      = push-action type='destroy' action=(action 'destroyWorkflowActionConnection' pointing_connection) class='pull-right'
      = ui-dropdown class='search selection' selected=pointing_connection.selector_workflow_group onChange=(action 'set_connection_selector_workflow_group' pointing_connection) fullTextSearch=true as |execute mapper|
        .default.text= t 'action.select_model' modelPath='models.workflow_group'
        i.dropdown.icon
        .menu
          each model.project.sorted_workflow_groups as |workflow_group|
            .item data-value='{{map-value mapper workflow_group}}'
              = workflow_group.name
      = ui-dropdown class='search selection' selected=pointing_connection.workflow_action_definition onChange=(action 'set_connection_workflow_action_definition' pointing_connection) fullTextSearch=true as |execute mapper|
        .default.text= t 'action.select_model' modelPath='models.workflow_action_definition'
        i.dropdown.icon
        .menu
          .item data-value='{{map-value mapper null}}' --
          each pointing_connection.filtered_workflow_action_definitions as |workflow_action_definition|
            .item data-value='{{map-value mapper workflow_action_definition}}'
              = workflow_action_definition.title
      '
      = ui-dropdown selected=pointing_connection.connection_type onChange=(action (mut pointing_connection.connection_type))
        .default.text connection type
        i.dropdown.icon
        .menu
          each connection_types as |connection_type|
            .item data-value=connection_type
              = t connection_type scope='workflow_action_definition.connection_type'
      if pointing_connection.workflow_action_definition_warning
        .ui.negative.message= pointing_connection.workflow_action_definition_warning
/ CONSTRAINTS
/.ui.dividing.header: .content= t 'models.plural.workflow_action_constraint'
/if new_workflow_action_constraint_warning
  .ui.visible.warning.message= new_workflow_action_constraint_warning
/.ui.grid
  .three.wide.column
    x-select value=selectedConstraintType on-change=(action (mut selectedConstraintType)) as |xs|
      each constraint_types as |constraint_type|
        xs.option value=constraint_type
          = constraint_type
  .six.wide.column
    x-select value=lastSelectedWorkflowGroup on-change=(action 'workflow_group_change') as |xs|
      each model.project.sorted_workflow_groups as |workflow_group|
        xs.option value=workflow_group
          = workflow_group.name
  .seven.wide.column
    x-select value=lastSelectedWorkflowActionDefinition on-change=(action 'newWorkflowActionConstraint') as |xs|
      option --
      each lastSelectedWorkflowGroup.sorted_workflow_action_definitions as |workflow_action_definition|
        unless (eq workflow_action_definition model)
          xs.option value=workflow_action_definition
            = workflow_action_definition.title
/.ui.grid
  each (reject-by 'isDeleted' working_workflow_action_constraints) as |constraint|
    .five.wide.column= constraint.constraint_workflow_action_definition.workflow_group.name
    .three.wide.column: .ui.right.pointing.label class=constraint.restrict:red:grey
      = constraint.type
    .six.wide.column= constraint.constraint_workflow_action_definition.title
    .two.wide.column= push-action type='destroy' action=(action 'destroyWorkflowActionConstraint' constraint)

.modal-actions.sticky
  button.ui.basic.button.modal-rollback{ action 'rollback_and_close'}= t 'general.rollback'
  push-action type='position' action='positionInProject'
  button.ui.primary.button.modal-save.pull-right{action 'saveRecord'}= t 'general.save'
  button.ui.negative.button.modal-destroy.pull-right{ action 'destroyRecord'}= t 'general.destroy.button'
