import Ember from 'ember'

export default Ember.Component.extend
  classNames: ['select-duration']
  value: 0
  unit: 'day'
  week_days: (-> [1,2,3,4,5]).property()
  unit_businessday: Ember.computed.equal 'unit', 'businessday'
  week_days_index_sum: Ember.computed.sum 'week_days'
  value_date_scope: Ember.computed 'value', ->
    if Math.round(Math.abs(@get('value'))) is 1 then 'date.unit' else 'date.unit.plural'
  has_default_business_days: Ember.computed 'week_days.length', 'week_days_index_sum', ->
    @get("week_days.length") is 5 and @get("week_days_index_sum") is 15
  actions:
    toggle_week_day_presence: (target, week_day, selected) ->
      #target = target.get('batch_element_threshold_business_days') unless Ember.isArray(target)
      if selected
        target.addObject week_day.index
      else
        target.removeObject week_day.index
