ActiveAdmin.register Episode do
  permit_params :show_id, :title, :episode_n, :synopsis, :date_aired,
                :created_at, :updated_at, :preview

  index do
    selectable_column

    column :title
    column :show do |episode|
      episode.season.show.title
    end
    column :number do |episode|
      "S#{episode.season.season_n}E#{episode.episode_n}"
    end
    column :date_aired
    actions
  end

  show do |episode|
    attributes_table do
      row :show_id
      row :title
      row :episode_n
      row :season
      row :synopsis
      row :date_aired
      row :created_at
      row :updated_at
      row :preview do
        image_tag(episode.preview.medium.url) if episode.preview.present?
      end
    end
  end

  form html: { multipart: true } do |f|
    f.inputs 'Episode' do
      f.input :title
      f.input :episode_n
      f.input :season
      f.input :synopsis
      f.input :date_aired
      f.input :preview, as: :file, hint:
              image_tag(f.object.preview.medium.url)
    end
    f.actions
  end

  filter :show
  filter :title
  filter :episode_n
  filter :season
  filter :date_aired
  filter :created_at
  filter :updated_at
end
