#= require ./dunlop/base
#= require dunlop/collapsible
#= require dunlop/categorize-as-button
#= require dunlop/collection-button
#= require dunlop/translations
#= require dunlop/display-badges
#= require dunlop/time-display
#= require pickadate/picker
#= require pickadate/picker.date
#= require pickadate/picker.time
#= require inflection
#= require js-routes
#= require moment
#= require moment/nl
#= require record_collection/all
Dunlop.register_setup (target)->
  target.find('input.datepicker').each ->
    options =
      format: 'yyyy-mm-dd'
      editable: true
      selectMonths: true
    if selectYears = $(@).data('selectYears')
      options.selectYears = selectYears
    $(@).pickadate(options)

  ##DEPRICATED use data-bytes instead
  #$('[data-size]').each (i)->
  #  bytes = $(@).data("size")
  #  $(@).text human_size(bytes)


  target.optionals()

$ ->
  try
    HawkEye.add_general_configuration
      facet:
        state:
          colors:
            uncategorized: "#eee"
            unplanned: "#aaa"
            planned: "#99b"
            active: "#55f"
            overdue: "#ffa500"
            any_rejected: "#e44"
            all_completed: "#5b5"
            # workflow_step - duplicates
            pending: "#eee"
            processing: "#55f"
            rejected: "#e44"
            completed: "#5b5"

  selector = $(document).multi_select
    changed: ->
      selection_text = "#{@selected_count()} van de #{@total_count()} orders geselecteerd"
      if totalCount = @get('table').data('recordCount')
        selection_text = "#{selection_text} (#{totalCount} totaal)"
      $('.multi-select-statistics').html selection_text
  return unless selector
  # Find all buttons in the table footer and attach the action given their action data attribute
  return unless table = selector.get('table')
  selector.trigger 'changed'

