import Ember from 'ember'

export default Ember.Component.extend
  tagName: 'span'
  classNames: ['project-instance-action-value-display']
  eventIO: null
  project_instance_action: null
  value_type: Ember.computed.alias 'project_instance_action.workflow_action_definition.value_type'
  save: ->

  # https://stackoverflow.com/questions/26967855/handling-click-and-doubleclick-on-same-view-in-emberjs
  doubleClick: ->
    eventIO = @get 'eventIO'
    if eventIO?
      Ember.run.cancel eventIO
      @set 'eventIO', null

    if @get('value_type') is 'boolean'
      #@toggleProperty 'project_instance_action.boolean_value'
      #@get('project_instance_action').save()

      # always modal, otherwise implement authorizations overhere
      @modal 'project/edit-instance-action',
        model: @get('project_instance_action')
        save: @save
        close: @save
    else
      # fallback to single click behaviour
      @modal 'project/edit-instance-action',
        model: @get('project_instance_action')
        save: @save
        close: @save


  click: ->
    if @get('eventIO') is null
      eventIO = Ember.run.later @, ->
        @modal 'project/edit-instance-action',
          model: @get('project_instance_action')
          save: @save
          close: @save
        if @get('eventIO') isnt null
          Ember.run.cancel @get('eventIO')
          @set 'eventIO', null
      , 500
      @set 'eventIO', eventIO

  actions:
    right_click: ->
      false
    #edit_record: ->
    #  @modal 'project/edit-instance-action', model: @get('project_instance_action')
    #  false
