
class PromosController < ApplicationController
  before_action :user_is_employee?
  before_action :set_promo, only: %i[ show edit update destroy ]
  layout "admin"

  def index
    @promos = Promo.all
  end

  def show
  end

  def new
    @promo = Promo.new
  end

  def edit
  end

  def create
    @promo = Promo.new(promo_params)

    if @promo.save
      redirect_to promos_url, notice: "Promoción creada."
    else
      render :new, status: :unprocessable_entity
    end
  end

  def update
    if @promo.update(promo_params)
      redirect_to promos_url, notice: "Promoción actualizada."
    else
      render :edit, status: :unprocessable_entity
    end
  end

  def destroy
    @promo.destroy
    redirect_to promos_url, notice: "Promoción eliminada."
  end

  private
    def set_promo
      @promo = Promo.find(params[:id])
    end

    def promo_params
      params.require(:promo).permit(:title, :init, :finish, :img, :content, :active)
    end
end
