ActiveAdmin.register Cohort, :as => 'Cohorts' do

  menu :label => 'Cohorts All-time', :parent => 'Reports'

  config.sort_order = 'group_start_desc'
  config.batch_actions = false
  config.clear_action_items!
  config.filters = false
  config.per_page = 50

  controller do

    def scoped_collection
      objs = super
      Cohort.alltime_cohorts!
      objs.where(all_time: true).order('group_start DESC')
    end

  end

  index :title => "All-Time Cohorts" do
    column 'Cohort' do |cc| 
      div(class: :cohort_col) { cc.group_start_str } 
    end

    column Cohort::ALLTIME_LABELS[:registered_users] do |cc| 
      div(class: :cohort_col) { cc.data_val(:registered_users) } 
    end

    column Cohort::ALLTIME_LABELS[:first_downloaded_client_at] do |cc| 
      div(class: :cohort_col) { cc.data_val(:first_downloaded_client_at) }
    end
    column '%' do |cc| div(class: :cohort_col) { cc.data_val(:first_downloaded_client_at, true) } end

    column Cohort::ALLTIME_LABELS[:first_certified_gear_at] do |cc| 
      div(class: :cohort_col) { cc.data_val(:first_certified_gear_at) }
    end
    column '%' do |cc| div(class: :cohort_col) { cc.data_val(:first_certified_gear_at, true) } end

    column Cohort::ALLTIME_LABELS[:music_sessions_user_history] do |cc| 
      div(class: :cohort_col) { cc.data_val(:music_sessions_user_history) }
    end
    column '%' do |cc| div(class: :cohort_col) { cc.data_val(:music_sessions_user_history, true) } end

    column Cohort::ALLTIME_LABELS[:jam_tracks_played] do |cc| 
      div(class: :cohort_col) { cc.data_val(:jam_tracks_played) }
    end
    column '%' do |cc| div(class: :cohort_col) { cc.data_val(:jam_tracks_played, true) } end

    column Cohort::ALLTIME_LABELS[:jam_track_rights] do |cc| 
      div(class: :cohort_col) { cc.data_val(:jam_track_rights) }
    end
    column '%' do |cc| div(class: :cohort_col) { cc.data_val(:jam_track_rights, true) } end

    column Cohort::ALLTIME_LABELS[:recorded_tracks] do |cc| 
      div(class: :cohort_col) { cc.data_val(:recorded_tracks) }
    end
    column '%' do |cc| div(class: :cohort_col) { cc.data_val(:recorded_tracks, true) } end

    column Cohort::ALLTIME_LABELS[:friendships] do |cc| 
      div(class: :cohort_col) { cc.data_val(:friendships) }
    end
    column '%' do |cc| div(class: :cohort_col) { cc.data_val(:friendships, true) } end

    column Cohort::ALLTIME_LABELS[:invited_users] do |cc| 
      div(class: :cohort_col) { cc.data_val(:invited_users) }
    end
    column '%' do |cc| div(class: :cohort_col) { cc.data_val(:invited_users, true) } end
  end

end
