#
class LeadsController < ApplicationController
  before_action :init_form
  #
  def new
    @lead = Lead.new
  end

  def create
    @lead = Lead.new(item_params)
    if @lead.save
      redirect_to thanks_leads_url
    else
      render action: :new
    end
  end

  def thanks; end

  private

  def item_params
    params
      .require(:lead)
      .permit(:name, :whatsapp, :gender, :region, :state_id, :city, :notify,
              :terms, interest_ids: [])
  end

  def init_form
    @interests = Interest.all
    @states    = State.order :name
  end
end
