module ProductCategoryDecorator

  def products
    #ProductDecorator.decorate_collection(model.products)
    @decorated_products ||= ActiveDecorator::Decorator.instance.decorate(super)
  end

  def visible_on
    sum = week_days.sum
    return content_tag(:span, '', class: 'product-category-visible-never') if sum.zero?
    return content_tag(:span, '', class: 'product-category-visible-always') if sum == 7 && full_day
    day_names = I18n.t('date.day_names')
    days = week_days.map.with_index{|v,i| v == 1 ? day_names[i] : nil}.compact
    days << days.shift if week_days.first == 1 && supplier.week_starts_on_monday?
    days = days.join(', ')
    unless full_day
      from_time = start_from
      from_time -= 1440 if from_time > 1440
      from_hour = from_time / 60.0
      to_time = end_on
      to_time -= 1440 if to_time > 1440
      to_hour = to_time / 60.0
      time_display = "#{from_hour.floor}:#{'%02d' % (from_hour.modulo(1) * 60)} - #{to_hour.floor}:#{'%02d' % (to_hour.modulo(1)*60)}"
      return time_display if sum == 7
      days << " #{time_display}"
    end
    days
  end
end
