class Settings::MenusController < ApplicationController
  load_and_authorize_resource except: [:create]
  before_action :set_settings_menu, only: [:show, :edit, :update, :destroy]

  # GET /settings/menus
  # GET /settings/menus.json
  def index
    @settings_menus = Menu.all.page(params[:page]).per(10)
  end

  # GET /settings/menus/1
  # GET /settings/menus/1.json
  def show
    @settings_menu_categories = @settings_menu.menu_categories.page(params[:page]).per(10)
  end

  # GET /settings/menus/new
  def new
    @settings_menu = Menu.new
  end

  # GET /settings/menus/1/edit
  def edit
  end

  # POST /settings/menus
  # POST /settings/menus.json
  def create
    @settings_menu = Menu.new(settings_menu_params)
    @settings_menu.created_by = current_login_employee.name
    respond_to do |format|
      if @settings_menu.save
        format.html { redirect_to settings_menus_path, notice: 'Menu was successfully created.' }
        format.json { render :show, status: :created, location: @settings_menu }
      else
        format.html { render :new }
        format.json { render json: @settings_menu.errors, status: :unprocessable_entity }
      end
    end
  end

  # PATCH/PUT /settings/menus/1
  # PATCH/PUT /settings/menus/1.json
  def update
    respond_to do |format|
      if @settings_menu.update(settings_menu_params)
        format.html { redirect_to settings_menus_path, notice: 'Menu was successfully updated.' }
        format.json { render :show, status: :ok, location: @settings_menu }
      else
        format.html { render :edit }
        format.json { render json: @settings_menu.errors, status: :unprocessable_entity }
      end
    end
  end

  # DELETE /settings/menus/1
  # DELETE /settings/menus/1.json
  def destroy
    # @settings_menu.destroy
    abc = Menu.destroyMenu(@settings_menu)
    respond_to do |format|
      format.html { redirect_to settings_menus_path, notice: 'Menu was successfully destroyed.' }
      format.json { head :no_content }
    end
  end

  private
    # Use callbacks to share common setup or constraints between actions.
    def set_settings_menu
      @settings_menu = Menu.find(params[:id])
    end

    # Never trust parameters from the scary internet, only allow the white list through.
    def settings_menu_params
        params.require(:menu).permit(:name, :is_active, :valid_days, :valid_time_to, :valid_time_from)
    end
end
