import axios from "axios";
import React from "react";
import { useEffect } from "react";
import { useState } from "react";
import { createContext } from "react";
export const authUser = createContext([]);
function AuthProvider({ children }) {
  const [user, setUer] = useState([]);
  const [warehouseList, setWarehouseList] = useState([]);
  const [permission, setPermission] = useState([]);
  const [category, setCategory] = useState([]);
  const [supplierList, setSupplierList] = useState([]);
  useEffect(() => {
    axios.get(route("auth.checker")).then((res) => {
      setPermission(res.data.permission);
      setUer(res.data.user);
      setWarehouseList(res.data.warehouse);
      setCategory(res.data.category);
      setSupplierList(res.data.supplier);
      window.setting = res.data.setting;
      window.businessFeatures = res.data.businessFeatures;
    });
  }, []);
  const shareData = {
    user,
    permission,
    setPermission,
    setUer,
    warehouseList,
    category,
    supplierList,
  };
  return <authUser.Provider value={shareData}>{children}</authUser.Provider>;
}

export default AuthProvider;
