class Settings::ItemSetsController < ApplicationController
  before_action :set_settings_item_set, only: [:show, :edit, :update, :destroy]
  load_and_authorize_resource except: [:create]
  # GET /settings/item_sets
  # GET /settings/item_sets.json
  def index
    @settings_item_sets = ItemSet.all
  end

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

  # GET /settings/item_sets/new
  def new
    @settings_item_set = ItemSet.new    
  end

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

  # POST /settings/item_sets
  # POST /settings/item_sets.json
  def create
    @settings_item_set = ItemSet.new(settings_item_set_params)

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

  # PATCH/PUT /settings/item_sets/1
  # PATCH/PUT /settings/item_sets/1.json
  def update
    respond_to do |format|
      if @settings_item_set.update(settings_item_set_params)
        format.html { redirect_to settings_item_sets_path, notice: 'Item set was successfully updated.' }
        format.json { render :show, status: :ok, location: @settings_item_set }
      else
        format.html { render :edit }
        format.json { render json: @settings_item_set.errors, status: :unprocessable_entity }
      end
    end
  end

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

    # Never trust parameters from the scary internet, only allow the white list through.
    def settings_item_set_params
      params.require(:item_set).permit(:name, :alt_name, :min_selectable_qty, :max_selectable_qty)
    end
end
