ActiveAdmin.register JamRuby::LessonBooking, :as => 'LessonBookings' do

  menu :label => 'Lesson Booking', :parent => 'JamClass'

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

  scope("All", default: true) { |scope| scope.unscoped.order('created_at desc') }
  scope("Requested") { |scope| scope.unscoped.where(status: LessonBooking::STATUS_REQUESTED).order('created_at desc') }
  scope("Approved") { |scope| scope.unscoped.approved.order('created_at desc') }
  scope("Suspended") { |scope| scope.unscoped.suspended.order('created_at desc') }
  scope("Canceled") { |scope| scope.unscoped.canceled.order('created_at desc') }

  index do
    column "User Link" do |lesson_booking|
      span do
        link_to "Lesson Session URL", "#{lesson_booking.next_lesson.admin_url}"
      end
    end
    column "Type" do |lesson_booking|
      lesson_booking.display_type
    end
    column "Status" do |lesson_booking|
      lesson_booking.status
    end
    column "Teacher" do |lesson_booking|
      teacher = lesson_booking.teacher
      span do
        link_to "#{teacher.name} (#{teacher.email})", "#{Rails.application.config.external_root_url}/client#/profile/teacher/#{teacher.id}"
      end
    end
    column "Student" do |lesson_booking|
      student = lesson_booking.student
      span do
        link_to "#{student.name} (#{student.email})", "#{Rails.application.config.external_root_url}/client#/profile/#{student.id}"
      end
    end
  end

  show do
    attributes_table do
      row "User Link" do |lesson_booking|
        span do
          link_to "Web URL", "#{Rails.application.config.external_root_url}/client#/jamclass/lesson-booking/#{lesson_booking.id}"
        end
      end
      row "Type" do |lesson_booking|
        lesson_booking.display_type
      end
      row "Status" do |lesson_booking|
        lesson_booking.status
      end
      row "Teacher" do |lesson_booking|
        teacher = lesson_booking.teacher
        span do
          link_to "#{teacher.name} (#{teacher.email})", "#{Rails.application.config.external_root_url}/client#/profile/teacher/#{teacher.id}"
        end
      end
      row "Student" do |lesson_booking|
        student = lesson_booking.student
        span do
          link_to "#{student.name} (#{student.email})", "#{Rails.application.config.external_root_url}/client#/profile/#{student.id}"
        end
      end
      row "Created At" do |lesson_booking|
        lesson_booking.created_at
      end
      row "Booked Price" do |lesson_booking|
        lesson_booking.booked_price
      end
    end

  end

end