class Settings::MenuItemSetsController < ApplicationController
  before_action :set_settings_menu_item_set, only: [:show, :edit, :update, :destroy]
  load_and_authorize_resource except: [:create]
  # GET /settings/menu_item_sets
  # GET /settings/menu_item_sets.json
  def index
    @settings_menu_item_sets = MenuItemSet.all
  end

  # GET /settings/menu_item_sets/1
  # GET /settings/menu_item_sets/1.json
  def show
  end

  # GET /settings/menu_item_sets/new
  def new
    @settings_menu_item_set = MenuItemSet.new
  end

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

  # POST /settings/menu_item_sets
  # POST /settings/menu_item_sets.json
  def create
    @settings_menu_item_set = MenuItemSet.new(settings_menu_item_set_params)

    respond_to do |format|
      if @settings_menu_item_set.save
        format.html { redirect_to settings_menu_item_sets_path, notice: 'Menu item set was successfully created.' }
        format.json { render :show, status: :created, location: @settings_menu_item_set }
      else
        format.html { render :new }
        format.json { render json: @settings_menu_item_set.errors, status: :unprocessable_entity }
      end
    end
  end

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

  # DELETE /settings/menu_item_sets/1
  # DELETE /settings/menu_item_sets/1.json
  def destroy
    @settings_menu_item_set.destroy
    flash[:notice] = 'Menu item set was successfully destroyed.'
    render :json => {:status=> "Success", :url => settings_menu_item_sets_url }.to_json
    # respond_to do |format|
    #   format.html { redirect_to settings_menu_item_sets_url, notice: 'Menu item set 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_item_set
      @settings_menu_item_set = MenuItemSet.find(params[:id])
    end

    # Never trust parameters from the scary internet, only allow the white list through.
    def settings_menu_item_set_params
      params.require(:menu_item_set).permit(:item_set_id, :menu_item_id)
    end
end
