table.ui.top.attached.compact.definition.table
  tr
    td= t 'models.workflow_action_definition'
    td= model.workflow_action_definition.title
  tr
    td= t 'attributes.project_instance_action.state'
    td= state-badge model.state
  if model.target_date
    tr
      td= t 'attributes.project_instance_action.target_date'
      td= format-date model.target_date format=globals.date_formatting
  if model.project_instance.project_scenario.name
    tr
      td= t 'models.project_scenario'
      td= model.project_instance.project_scenario.name
  if model.workflow_action_definition.organization.name
    tr
      td= t 'models.organization'
      td
        if model.workflow_action_definition.organization.logo
          img.project-instance-action-modal-organization-image src=model.workflow_action_definition.organization.logo_url.small
        = model.workflow_action_definition.organization.name
  tr
    td= t 'models.project_instance'
    td
      = model.project_instance.client_identifier
      if model.project_instance.reference_date
        '
        span.between-brackets= format-date model.project_instance.reference_date format=globals.date_formatting
        '
      = state-badge model.project_instance.state basic=true
  tr
    td= t 'models.workflow_group'
    td
      = model.workflow_action_definition.workflow_group.name
      '
      = state-badge model.project_instance_group.state basic=true
  if model.notes
    tr
      td= t 'attributes.project_instance_action.notes'
      td= markdown-to-html model.notes
  if model.workflow_action_definition.extra_info
    tr
      td= t 'attributes.workflow_action_definition.extra_info'
      td= markdown-to-html model.workflow_action_definition.extra_info
  if model.overdue_at
    tr
      td= t 'attributes.project_instance_action.overdue_at'
      td= format-date model.overdue_at format=globals.time_formatting
  if model.completed_at
    tr
      td= t 'attributes.project_instance_action.completed_at'
      td= format-date model.completed_at format=globals.time_formatting
  each model.pointing_project_instance_action_connections as |pointing_connection|
    if (eq pointing_connection.connection_type 'constraint')
      tr.pointing-action.constraint class=pointing_connection.project_instance_action.completed:completed:uncompleted
        td= pointing_connection.project_instance_action.workflow_action_definition.title
        td= project/instance-action-value-display project_instance_action=pointing_connection.project_instance_action save=(action 'open_current_modal')
    else
      tr.pointing-action class=pointing_connection.connection_type
        td= pointing_connection.project_instance_action.workflow_action_definition.title
        td= project/instance-action-value-display project_instance_action=pointing_connection.project_instance_action save=(action 'open_current_modal')
if (eq value_type 'text')
  .ui.bottom.attached.segment
    = textarea value=text_value

/each attached_instance_action_connections as |attached_instance_action_connection|
  .ui.horizontal.divider
    span Attached action
    = attached_instance_action_connection.project_instance_action.workflow_action_definition.title
/minimal space for calendar at bottom right
if misc_events.length
  .ui.horizontal.divider events
  table.ui.striped.table
    each misc_events as |event|
      tr
        td
          if event.source
            = event.source
          else
            i.user.secret.icon
        td= event.event_key
        td= event.event_value
        td= format-date event.event_timestamp format=globals.time_formatting

.ui.horizontal.divider notes
table.ui.top.attached.compact.definition.table
  each note_events as |note_event|
    tr
      td.collapsing
        = note_event.source
        br
        = format-date note_event.event_timestamp format=globals.time_formatting
      td: pre= note_event.event_value
.ui.attached.segment= textarea value=new_note_content rows=3
.ui.bottom.attached.segment
  if can_edit_action
    unless (contains model.state globals.project_instance_action.final_states)
      button.ui.pink.button.pull-right click='start_inquiry' disabled=new_note_content_is_blank: span= t 'action_list.start_inquiry'
  button.ui.primary.button click="add_new_note" disabled=new_note_content_is_blank: span= t 'action_list.add_note'

.modal-actions.sticky
  /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'
  if (and can_edit_action model.pointing_project_instance_action_connections.isFulfilled)
    if (eq model.state 'inquiry')
      button.ui.pink.button.pull-right{action 'continue_from_inquiry'}= t 'action_list.continue_from_inquiry'
    else
      if has_uncompleted_constraints
        .pull-right.ui.negative.message= t 'project_instance_action.has_uncompleted_constraints_message'
      else
        if (eq value_type 'boolean')
          if attached_conditions_not_met_warning
            .ui.visible.warning.message.pull-right= attached_conditions_not_met_warning
          else
            if model.boolean_value
              button.ui.yellow.button.pull-right{action 'set_value' 'boolean_value' false}= t 'project_instance_action.revoke'
            else
              button.ui.primary.button.pull-right{action 'set_value' 'boolean_value' true}= t 'project_instance_action.done'
        else if (eq value_type 'date')
          if attached_conditions_not_met_warning
            .ui.visible.warning.message.pull-right= attached_conditions_not_met_warning
          else
            .pull-right: .ui.revoke.action.input
              = ui-calendar-moment type='date' momentValue=model.date_value onChange=(action 'set_value' 'date_value') placeholder="Select date" popupOptions=(hash position='top right' maxSearchDepth=0)
              if model.date_value
                button.ui.yellow.button.pull-right{action 'set_value' 'date_value' null}= t 'project_instance_action.revoke'
        else if (eq value_type 'timestamp')
          if attached_conditions_not_met_warning
            .ui.visible.warning.message.pull-right= attached_conditions_not_met_warning
          else
            if has_changed_timestamp_value
              button.ui.primary.icon.button.pull-right{action 'set_timestamp_value'}: i.save.icon
            if model.timestamp_value
              button.ui.yellow.button.pull-right{action 'set_value' 'timestamp_value' null}= t 'project_instance_action.revoke'
            .pull-right: .ui.revoke.action.input
              = ui-calendar-moment type='datetime' ampm=false momentValue=timestamp_value onChange=(action (mut timestamp_value)) placeholder="Select timestamp" popupOptions=(hash position='top right' maxSearchDepth=0)
        else if (eq value_type 'string')
          if attached_conditions_not_met_warning
            .ui.visible.warning.message.pull-right= attached_conditions_not_met_warning
          else
            .pull-right: .ui.revoke.action.input
              = input value=string_value enter='set_string_value'
              if (not-eq string_value model.string_value)
                button.ui.primary.icon.button{action 'set_string_value'}: i.save.icon
              if model.string_value
                button.ui.yellow.button{action 'set_value' 'string_value' ''}= t 'project_instance_action.revoke'
        else if (eq value_type 'number')
          if attached_conditions_not_met_warning
            .ui.visible.warning.message.pull-right= attached_conditions_not_met_warning
          else
            .pull-right: .ui.revoke.action.input
              = number-input numericValue=number_value step=1 enter='set_number_value'
              if (not-eq number_value model.number_value)
                button.ui.primary.icon.button{action 'set_number_value'}: i.save.icon
              if model.number_value
                button.ui.yellow.button.pull-right{action 'set_value' 'number_value' ''}= t 'project_instance_action.revoke'
        else if (eq value_type 'select')
          if model.workflow_action_definition.value_type_select_options.length
            .ui.buttons.pull-right
              = ui-dropdown class='button' selected=string_value onChange=(action 'set_value' 'string_value') direction='upward'
                .default.text select&hellip;
                i.dropdown.icon
                .upward.menu
                  each model.workflow_action_definition.value_type_select_options as |option|
                    .item data-value=option
                      = option
              if model.string_value
                if attached_conditions_not_met_warning
                  button.ui.negative.icon.button
                    = ui-popup tagName='i' class='close icon' content=attached_conditions_not_met_warning
                else
                  button.ui.primary.icon.button{action 'set_string_value'}: i.save.icon
                button.ui.yellow.button{action 'set_value' 'string_value' ''}= t 'project_instance_action.revoke'

          else
            .pull-right: .ui.revoke.action.input
              = input value=string_value enter='set_string_value'
              if model.string_value
                if attached_conditions_not_met_warning
                  button.ui.negative.icon.button
                    = ui-popup tagName='i' class='close icon' content=attached_conditions_not_met_warning
                else
                  button.ui.primary.icon.button{action 'set_string_value'}: i.save.icon
                button.ui.yellow.button{action 'set_value' 'string_value' ''}= t 'project_instance_action.revoke'
        else if (eq value_type 'text')
          if attached_conditions_not_met_warning
            .ui.visible.warning.message.pull-right= attached_conditions_not_met_warning
          else
            .ui.buttons.pull-right
              if (not-eq text_value model.text_value)
                button.ui.primary.button{action 'set_text_value'}= t 'project_instance_action.done'
              if model.text_value
                button.ui.yellow.button{action 'set_value' 'text_value' ''}= t 'project_instance_action.revoke'

  button.ui.basic.button.modal-rollback{action "close"}= t 'general.close'
