ActiveAdmin.register JamRuby::GiftCard, :as => 'GiftCards' do

  menu :label => 'Gift Cards', :parent => 'JamTracks'

  config.batch_actions = false
  config.filters = true
  config.per_page = 50

  scope("Redeemed Most Recently", default: true) { |scope| scope.where('user_id IS NOT NULL').order('updated_at DESC') }
  scope("Available") { |scope| scope.where('user_id is NULL')  }

  filter :card_type
  filter :origin
  filter :code

  index do
    column 'User' do |oo| oo.user ? link_to(oo.user.email, oo.user.admin_url, {:title => oo.user.email}) : '' end
    column 'Code' do |oo| oo.code end
    column 'Card Type' do |oo| oo.card_type end
    column 'Origin' do |oo| oo.origin end
    column 'Created' do |oo| oo.created_at end
  end

end
