class SectionsController < ApplicationController
	layout 'bootstrap'

	before_action :set_section
  before_action :set_survey_run, only: [:edit, :update]

  def edit; end

  def update
  	@section.update(section_params_edit)
    @second_additional_id = @run.sections.where(additional: true).second.id
  end

  def enable
    @section.update(enabled: params[:enabled])
  end

  def cancel; end

  private 

  def set_section
    @section = Answerly::Section.find(params[:id])
  end

  def set_survey_run
    @run = Answerly::SurveyRun.find(params[:survey_run_id])
  end

  def section_params_edit
    params
    .require(:section)
    .permit(:name, questions_attributes: [:id, :_destroy,:id, :title, :description])
  end
end
