ActiveAdmin.register JamRuby::TestDrivePackage, :as => 'TestDrivePackage' do

  menu :label => 'Test Drive Packages', :parent => 'JamClass'

  config.sort_order = 'created_at desc'
  config.batch_actions = false
  config.per_page = 100
  config.paginate = true
  config.filters = false

  form :partial => 'form'


  controller do
=begin
    def new
      test_drive_package = TestDrivePackage.new
      t = TestDrivePackageTeacher.new
      t.test_drive_package = test_drive_package
      test_drive_package.test_drive_package_teachers << t

      t = TestDrivePackageTeacher.new
      t.test_drive_package = test_drive_package
      test_drive_package.test_drive_package_teachers << t

      @test_drive_package = test_drive_package
      puts "OK #{test_drive_package.test_drive_package_teachers.length}"
      super
    end
=end


    # def create
    #   puts params.inspect
    #  hash = params[:jam_ruby_test_drive_package]
    # package = TestDrivePackage.new
    # package.name = hash[:name]
    # package.package_type = hash[:package_type]
    # package.description = hash[:description]
    # if package.save
    #   redirect_to admin_test_drive_package_path(package.id)
    # else
    #   redirect_to admin_test_drive_packages_path, :notice => "Unable to create package.  Error: #{package.errors.first[1][0]}"
    # end
    #end
  end
  index do

    column "Package ID" do |package|
      link_to package.name, "#{APP_CONFIG.external_root_url}/landing/jamclass/students?utm-teachers=#{package.name}"
    end

    column "Package Type" do |package|
      package.package_type
    end

    column "Teachers" do |package|
      package.test_drive_package_teachers.each do |package_teacher|

        span do
          teacher = package_teacher.user
          link_to "#{teacher.name} (#{teacher.email})", "#{Rails.application.config.external_root_url}/client#/profile/teacher/#{teacher.id}"
        end
        br
      end
    end

    column "Detail" do |package|
      link_to "Detail", admin_test_drive_package_path(package.id)
    end

  end

  show do

    attributes_table do
      row "Package ID" do |package|
        link_to package.name, "#{APP_CONFIG.external_root_url}/landing/jamclass/students?utm-teachers=#{package.name}"
      end

      row "Package Type" do |package|
        package.package_type
      end

      row "Teachers" do |package|
        package.test_drive_package_teachers.each do |package_teacher|

          span do
            teacher = package_teacher.user
            link_to "#{teacher.name} (#{teacher.email})", "#{Rails.application.config.external_root_url}/client#/profile/teacher/#{teacher.id}"
          end
          br
        end
      end

      row "Description" do |package|
        package.description
      end
    end
  end

end