class WaiterController < ApplicationController
  layout 'waiter'
  def index

  end

  def sections
    json = '{"tables":[{"id":"0903d04a003991835f9f32d1821ee05c","number":102,"width":2.0,"height":2.0,"position_x":14.242294520547945,"position_y":3.1862955032119915,"section_id":"1a9d4cc551dac96f87a21c97ba1e710b","occupied":true,"active_list_id":"1cef487ec268169687f481cb828924c2"},{"id":"0903d04a003991835f9f32d1821efb50","number":100,"width":2.0,"height":2.0,"position_x":6.5,"position_y":6.5,"section_id":"1a9d4cc551dac96f87a21c97ba1e710b","occupied":false,"active_list_id":null},{"id":"1a9d4cc551dac96f87a21c97ba3d15fa","number":11,"width":2.0,"height":2.0,"position_x":6.5,"position_y":1.5,"section_id":"1a9d4cc551dac96f87a21c97ba1e710b","occupied":false,"active_list_id":null},{"id":"0903d04a003991835f9f32d1821ededd","number":103,"width":2.0,"height":2.0,"position_x":9.0,"position_y":6.5,"section_id":"222fcd43b55e397d11d92ccb601e70dc","occupied":false,"active_list_id":null},{"id":"0903d04a003991835f9f32d1821eee07","number":101,"width":2.0,"height":2.0,"position_x":2.3333333333333335,"position_y":6.5,"section_id":"222fcd43b55e397d11d92ccb601e70dc","occupied":false,"active_list_id":null},{"id":"1a9d4cc551dac96f87a21c97ba3d0dbd","number":12,"width":2.0,"height":2.0,"position_x":9.854452054794521,"position_y":2.7054794520547945,"section_id":"222fcd43b55e397d11d92ccb601e70dc","occupied":false,"active_list_id":null},{"id":"1a9d4cc551dac96f87a21c97ba3d2221","number":10,"width":2.0,"height":2.0,"position_x":6.4811643835616435,"position_y":2.0034246575342465,"section_id":"222fcd43b55e397d11d92ccb601e70dc","occupied":false,"active_list_id":null},{"id":"1a9d4cc551dac96f87a21c97ba3d2cf7","number":1,"width":2.0,"height":2.0,"position_x":2.3333333333333335,"position_y":1.5,"section_id":"222fcd43b55e397d11d92ccb601e70dc","occupied":false,"active_list_id":null}],"lists":[{"id":"1cef487ec268169687f481cb828924c2","state":"active","needs_help":true,"needs_payment":false,"is_paid":false,"price":46.8,"table_id":"0903d04a003991835f9f32d1821ee05c","table_number":102,"section_id":"1a9d4cc551dac96f87a21c97ba1e710b","has_active_orders":true,"user_ids":["8afe7cccf1c690e60aa2ace1bf1d8a71"]}],"sections":[{"id":"1a9d4cc551dac96f87a21c97ba1e710b","title":"Ruimte2","path":[[0.0,0.0],[30.0,12.0],[30.0,12.0],[0.0,12.0]],"width":30.0,"height":12.0,"table_ids":["0903d04a003991835f9f32d1821ee05c","0903d04a003991835f9f32d1821efb50","1a9d4cc551dac96f87a21c97ba3d15fa"]},{"id":"222fcd43b55e397d11d92ccb601e70dc","title":"Buiten","path":[[0.0,0.0],[20.0,20.0],[20.0,20.0],[0.0,20.0]],"width":20.0,"height":20.0,"table_ids":["0903d04a003991835f9f32d1821ededd","0903d04a003991835f9f32d1821eee07","1a9d4cc551dac96f87a21c97ba3d0dbd","1a9d4cc551dac96f87a21c97ba3d2221","1a9d4cc551dac96f87a21c97ba3d2cf7"]}]}'
    respond_to do |format|
      format.html { redirect_to '/waiter'}
      format.json { render json: json }
    end
  end

  def product_categories
    respond_to do |format|
      format.html { redirect_to '/waiter'}
      format.json { render json: ProductCategory.all.include_relation(:product), root: 'product_categories', each_serializer: ProductCategorySerializer }
    end
  end

  def order_products
    @table= Table.find_by_supplier_id_and_id!(current_supplier.id, params[:table_id])
    @list = List.from_table_by_employee(@table, current_employee)
    @list.place_order products: params[:order], employee: current_employee
    render nothing: true
  end

  def current_supplier
    @current_supplier ||= Supplier.first
  end

  def current_employee
    @current_employee ||= current_supplier.employees.first
  end
end
