App.MenuTimePreviewComponent = Ember.Component.extend
  active: false
  collapsed: true
  preview_day: null
  filter: null
  preview_full_day: true
  preview_minute_of_day: 1340
  classNames: 'menu-time-preview-container'
  classNameBindings: ['active:active']
  actions:
    openTimePreview: -> 
      @set 'collapsed', false
    closeTimePreview: ->
      #@set 'active', false
      @set 'collapsed', true
    activateTimePreview: ->
      @set 'collapsed', true
      @set 'active', true
    deactivateTimePreview: ->
      @set 'preview_day', null
      @set 'preview_full_day', true
      @set 'active', false
      @set 'collapsed', true
  daysContent: (->
    $days.map( (d) -> Ember.Object.create( name: d, text: t("date.day_name.#{d}")) )
  ).property()
  preview_day_text: (->
    return "" unless day = @get('preview_day.text')
    #day_text = tspan("date.day_name.#{day.get('name')}")
    "<h4>#{day}</h4>".htmlSafe()
  ).property('preview_day')

  preview_time_text: (->
    return "" if @get('preview_full_day')
    day_minute = @get('preview_minute_of_day')
    hour = Math.floor(day_minute/60)
    minute = Math.floor(day_minute%60)
    hour = "0#{hour}".substr(-2,2)
    minute = "0#{minute}".substr(-2,2)
    "<span class='time-preview-active-time time'>#{hour}:#{minute}</span>".htmlSafe()
  ).property('preview_full_day', 'preview_minute_of_day')
  hasSelection: (->
    return true if @get('preview_day')
    return true unless @get('preview_full_day')
    false
  ).property('preview_day', 'preview_full_day')

  remoteFilter: (->
    return @set('targetObject.filter', null) unless @get('active')
    filter = Ember.Object.create()
    filter.set 'day', @get('preview_day.name')
    filter.set 'minute_of_day', @get('preview_minute_of_day') unless @get('preview_full_day')
    @set('targetObject.filter', filter)
  ).observes('active', 'preview_day', 'preview_full_day', 'preview_minute_of_day')
