class Ppa::AreasTematicasController < ApplicationController
	include ControllerConcern
	include PpaControllersConcern

	before_action :authenticate_usuario!
	before_action :autoriza_usuario!
	before_action :set_ppa_area_tematica, only: [:show, :edit, :update, :destroy]

	# GET /ppa/areas_tematicas
	def index
		@q = Ppa::AreaTematica.where(ppa_id: ppa_atual.id).order(:id).ransack(query_params)
		@ppa_areas_tematicas = @q.result.paginate(page: params[:page], per_page: 10)
	end

	# GET /ppa/areas_tematicas/1
	def show
	end

	# GET /ppa/areas_tematicas/new
	def new
		@ppa_area_tematica = Ppa::AreaTematica.new
	end

	# GET /ppa/areas_tematicas/1/edit
	def edit
	end

	# POST /ppa/areas_tematicas
	def create
		@ppa_area_tematica = Ppa::AreaTematica.new(ppa_area_tematica_params)
		@ppa_area_tematica.ppa_id = ppa_atual.id
		if @ppa_area_tematica.save
			redirect_to @ppa_area_tematica, notice: 'Área Temática foi criada com sucesso.'
		else
			render :new
		end
	end

	# PATCH/PUT /ppa/areas_tematicas/1
	def update
		if @ppa_area_tematica.update(ppa_area_tematica_params)
			redirect_to @ppa_area_tematica, notice: 'Área Temática foi atualizada com sucesso.'
		else
			render :edit
		end
	end

	# DELETE /ppa/areas_tematicas/1
	def destroy
		mensagem = apaga_e_retorna_mensagem(@ppa_area_tematica)
		redirect_to ppa_areas_tematicas_url, mensagem
	end

	private
	# Use callbacks to share common setup or constraints between actions.
	def set_ppa_area_tematica
		@ppa_area_tematica = Ppa::AreaTematica.find(params[:id])
	end

	# Only allow a trusted parameter "white list" through.
	def ppa_area_tematica_params
		params.require(:ppa_area_tematica).permit(:ppa_id, :nome)
	end
end
