import Ember from 'ember'
{get} = Ember

export default Ember.Component.extend
  tagName: 'span'
  scope_project: null
  scope_scenario: null
  projects: []
  actions:
    apply_filters: ->
      @get('apply_filters')?()

    edit_project_instance_action: (project_instance_action) ->
      @modal 'project/edit-instance-action', model: project_instance_action
    set_scope_project: (project) ->
      if project?
        project.reload().then =>
          project_id = project?.get('id') || ''
          @set 'scope_project', project
          @set 'filters.workflow_action_definition_title_cont', ''
          @set 'filters.project_id', project_id
          @$('.select-project .dropdown.button').addClass('orange')
          @send 'apply_filters'
      else
        @setProperties
          scope_project: null
          scope_scenario: null
          'filters.project_id': ''
          'filters.project_instance_project_scenario_id': ''
          @$('.select-project .dropdown.button').removeClass('orange')
        @send 'apply_filters'

    set_scope_scenario: (project_scenario) ->
      if project_scenario
        scenario_id = get(project_scenario, 'id')
        @$('.select-project-scenario .dropdown.button').addClass('orange')
      else
        @$('.select-project-scenario .dropdown.button').removeClass('orange')
        scenario_id = ''
      @set 'filters.project_instance_project_scenario_id',  scenario_id
      @set 'scope_scenario', project_scenario
      @send 'apply_filters'
