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

  # GET /settings/order_queue_stations
  # GET /settings/order_queue_stations.json
  def index
    @settings_order_queue_stations = OrderQueueStation.all
    @settings_order_queue_stations = Kaminari.paginate_array(@settings_order_queue_stations).page(params[:page]).per(50)
  end

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

  # GET /settings/order_queue_stations/new
  def new
    @settings_order_queue_station = OrderQueueStation.new
  end

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

  # POST /settings/order_queue_stations
  # POST /settings/order_queue_stations.json
  def create
    @settings_order_queue_station = OrderQueueStation.new(settings_order_queue_station_params)
    @settings_order_queue_station.created_by = current_login_employee.name
    @settings_order_queue_station.processing_items = "[]"
    respond_to do |format|
      if @settings_order_queue_station.save
        format.html { redirect_to settings_order_queue_stations_path, notice: 'Order queue station was successfully created.' }
        format.json { render :show, status: :created, location: @settings_order_queue_station }
      else
        format.html { render :new }
        format.json { render json: @settings_order_queue_station.errors, status: :unprocessable_entity }
      end
    end
  end

  # PATCH/PUT /settings/order_queue_stations/1
  # PATCH/PUT /settings/order_queue_stations/1.json
  def update
    # params[:order_queue_station][:processing_items] = params[:order_queue_station][:processing_items].split(/,/).inspect
    respond_to do |format|
      if @settings_order_queue_station.update(settings_order_queue_station_params)
        format.html { redirect_to settings_order_queue_station_path(@settings_order_queue_station), notice: 'Order queue station was successfully updated.' }
        format.json { render :show, status: :ok, location: @settings_order_queue_station }
      else
        format.html { render :edit }
        format.json { render json: @settings_order_queue_station.errors, status: :unprocessable_entity }
      end
    end
  end

  # DELETE /settings/order_queue_stations/1
  # DELETE /settings/order_queue_stations/1.json
  def destroy
    @settings_order_queue_station.destroy
    respond_to do |format|
      format.html { redirect_to settings_order_queue_stations_url, notice: 'Order queue station was successfully destroyed.' }
      format.json { head :no_content }
    end
  end

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

    # Never trust parameters from the scary internet, only allow the white list through.
    def settings_order_queue_station_params
# <<<<<<< HEAD
      params.require(:order_queue_station).permit(:station_name, :is_active, :auto_print, :processing_items, :print_copy, :printer_name, :font_size, :cut_per_item, :use_alternate_name, :created_by)
# =======
# Don't Know { zone_ids: [] }
#       params.require(:order_queue_station).permit(:station_name, :is_active, :processing_items, :print_copy, :printer_name, :font_size, :cut_per_item, :use_alternate_name, :created_by,{ zone_ids: [] })
# >>>>>>> b093a993ba002c92659bbb34338c55c031c11d87
    end
end
