"use client";
import { useDispatch } from "react-redux";
import { AppDispatch } from "@/store/store";
import { useEffect } from "react";
import { fetchAddressData, UpdateProfile } from "@/utils/helpers";
import { getAllCartItems } from "@/store/cart.slice";
import { getAllSettings } from "@/store/settings.slice";
import { setIsLoading } from "@/store/auth.slice";
import Cookies from "js-cookie";
import { getAllCategories } from "@/store/categories.slice";
const ApisCaller = () => {
  const dispatch = useDispatch<AppDispatch>();
  const token = Cookies.get("token");
  useEffect(() => {
    if (token) {
      UpdateProfile({ dispatch });
      fetchAddressData({ dispatch });
      // dispatch(getAllAddressesItems());
      // dispatch(getAllNotifications({ page: 1 }));
      dispatch(getAllCartItems());
    } else {
      dispatch(setIsLoading(false));
    }
  }, [token]);
  useEffect(() => {
    dispatch(getAllSettings());
    dispatch(getAllCategories());
  }, []);
  return null;
};

export default ApisCaller;
