ActiveAdmin.register JamRuby::Charge, :as => 'Charges' do

  menu :label => 'Charge', :parent => 'JamClass'

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

  controller do
    active_admin_config.includes.push :user
  end

  filter :user_email_cont, label: 'Name', as: :string

  index do
    column "Actions" do |charge|
      links = ''.html_safe
      links << link_to("View", resource_path(charge), :class => "member_link view_link")
      links << link_to("Edit", edit_resource_path(charge), :class => "member_link edit_link")
      links
    end
    column "User" do |charge|
      link_to charge.user.name, charge.user.admin_url
    end
    column :billed
    column :billing_error_reason
    column :billing_attempts
    column :amount_in_cents
    column :fee_in_cents
    column :created_at
    column :updated_at
    column "Stripe" do |charge|
      link_to "Link", "https://dashboard.stripe.com/payments/#{charge.stripe_charge_id}" if charge.stripe_charge_id
    end
  end

  show do
    attributes_table do
      row "User" do |charge|
        link_to charge.user.name, charge.user.admin_url
      end
      row :amount_in_cents
      row :fee_in_cents
      row :billed
      row :billed_at
      row :post_processed
      row :post_processed_at
      row :billing_error_reason
      row :billing_error_detail
      row :billing_should_retry
      row :billing_attempts
      row :stripe_charge_id
      row :created_at
      row :updated_at
      row "Stripe" do |charge|
        link_to "Link", "https://dashboard.stripe.com/payments/#{charge.stripe_charge_id}" if charge.stripe_charge_id
      end
    end
  end

end