class Panel::Ask::FrontEnd::AskQuestionsController < OrbitWidgetController

  layout false

  def initialize
    super
    @app_title = 'ask'
  end

  def index
    @ask_question = AskQuestion.new
    @categories = @module_app.categories.enabled
  end

  def create
    @ask_question = AskQuestion.new(params[:ask_question])
    if gotcha_valid? && @ask_question.save
      @acknowledgement = AskAcknowledgement.last
      @ask_acknowledgement = AskAcknowledgement.first || AskAcknowlegement.new

      AskAdmin.all.each do |ask_admin|
        AskMailer.notice(ask_admin, @ask_question).deliver
        Resque.enqueue(SendAskNoticeMail, ask_admin.id, @ask_question.id)
      end

      # Render to create.js.erb
      respond_to do |format|
        format.js
      end
    else
      # Render to index.js.erb
      respond_to do |format| 
        format.js { render :index }
      end
    end
  end


  def thank_you
    @acknowledgement = AskAcknowledgement.last
    @item = Page.find(params[:page_id]) rescue nil
    if @item
      if @item.frontend_data_count
        @page_num = @item.frontend_data_count
      else
        @page_num = 15
      end
      @frontend_style = @item.frontend_style
    end
    @item = Page.find(params[:page_id]) rescue nil
  end
end
