ActiveAdmin.register Channel do
  menu :priority => 5 #,:parent => "Bots"

  index do
    column :id
    column :name
    column :bot, :sortable => :bot_id do |c|
      link_to "ID:" +  c.bot_id.to_s + " N:" + Bot.find(c.bot_id).botnick, "bots/" + c.bot_id.to_s
    end
    column :activate
    column :created_at
    column :updated_at
    default_actions
  end

  show :title => :name do
    attributes_table do
      row :id
      row :name
      row :bot do |c|
          span(link_to("ID:" +  c.bot_id.to_s + " N:" + Bot.find(c.bot_id).botnick.to_s, "../bots/" + c.bot_id.to_s).to_s + " | " +
                   link_to("add a channel to this bot", "/admin/channels/new?bot_id=" + c.bot_id.to_s + "&botnick=" + Bot.find(c.bot_id).botnick.to_s))
      end

      row :activate
      row :created_at
      row :updated_at

    end
    active_admin_comments
  end

  filter :id
  filter :name
  filter :bot, :as => :select, :member_label => :botnick
  filter :activate, :as => :select
  filter :created_at
  filter :updated_at

  form do |f|

    #@user = User.new(:email => params[:email])


    f.inputs "Details" do
      f.input :name, :label => "Channelname"
      if params[:bot_id] && params[:botnick] then
        f.input :bot_id, :as => :string,  :member_label => :botnick, :input_html => { :readonly => true, :size => 10, :value => params[:botnick] }
        f.input :bot_id, :as => :hidden,  :value => params[:bot_id], :member_label => :botnick, :input_html => { :readonly => true, :size => 10, :value => params[:bot_id] }
        #f.input :bot, :as => :select, :member_label => :botnick  # https://github.com/justinfrench/formtastic/blob/master/lib/formtastic/inputs/select_input.rb
      else
        f.input :bot, :as => :select, :member_label => :botnick  # https://github.com/justinfrench/formtastic/blob/master/lib/formtastic/inputs/select_input.rb
      end


      f.input :activate
    end
    f.buttons
  end

end
