"use client";
import AppContext from "@ctx/AppContext";
import Chapar from "@plug/Chapar";
import Goftino from "@plug/Goftino/page";
import React, { useEffect, useState } from "react";
import { toast } from "react-toastify";

const RootData = ({ children }) => {
  const [navData, setNavData] = useState([]);

  const fetchNavData = async () => {
    try {
      const data = await Chapar.get(
        `${process.env.NEXT_PUBLIC_API_URL}/website/navbar`
      );

      setNavData(data);

      console.log(data);
    } catch ({ error, status }) {
      console.log(error);
    }
  };

  useEffect(() => {
    fetchNavData();
  }, []);

  return (
    <AppContext.Provider
      value={{
        state: {
          navData,
        },
        setNavData,
        fetchNavData,
      }}
    >
      {children}
      <Goftino />
    </AppContext.Provider>
  );
};

export default RootData;
