import Ember from 'ember'
export default Ember.Controller.extend
  set_value_on_non_final_till_date_date: moment()
  set_value_on_non_final_till_date_action: null
  operation_running_time: Ember.computed 'globals.operation_running', ->
    return '' unless start_time = @get('globals.operation_running')
    duration = moment.duration(moment().diff(start_time))
    if duration.days()
      "#{duration.days()} days and #{duration.hours()} hours"
    else
      hours = ('0' + duration.hours()).slice(-2)
      minutes = ('0' + duration.minutes()).slice(-2)
      seconds = ('0' + duration.seconds()).slice(-2)
      "#{hours}:#{minutes}:#{seconds}"
  actions:
    set_value_on_non_final_till_date: ->
      return unless date = @get('set_value_on_non_final_till_date_date')
      return unless action = @get('set_value_on_non_final_till_date_action')
      @set 'globals.operation_running', moment()
      action.set_value_on_non_final_till_date(date: date.format('YYYY-MM-DD'), event_value: 't')
