ActiveAdmin.register Event do
  permit_params :name, :date

  menu priority: 3, label: "📅 Events"

  scope :all, default: true
  scope("Upcoming") { |scope| scope.where("date >= ?", Time.current) }
  scope("Past") { |scope| scope.where("date < ?", Time.current) }

  index do
    selectable_column
    id_column
    column :name
    column :date do |event|
      if event.date >= Time.current
        status_tag "upcoming", class: "ok"
        text_node " #{l event.date, format: :long}"
      else
        status_tag "past", class: "default"
        text_node " #{l event.date, format: :long}"
      end
    end
    column :created_at
    actions
  end

  filter :name
  filter :date

  show do
    attributes_table do
      row :id
      row :name
      row :date
      row :created_at
      row :updated_at
    end
  end

  form do |f|
    f.inputs do
      f.input :name
      f.input :date, as: :datetime_select
    end
    f.actions
  end
end
