import { useContext, useMemo } from "react";
import { DevContext } from "./../../../ricos-context/dev-context.js";
import { useRequestService } from "./../../request-service-provider/request-service-provider.js";
const pageTypePaths = {
  blogPost: "blog-posts",
  staticPage: "static-pages",
  dynamicPage: "dynamic-all-pages",
  dynamicItemPage: "dynamic-item-pages",
  storeProduct: "stores-products",
  storeCatalog: "stores-catalogs"
};
const useFetchSitePages = () => {
  const { makeRequest } = useRequestService();
  const fetchSitePages = useMemo(
    () => (pageType, params) => (async (makeRequest2, pageType2, params2) => {
      const response = await makeRequest2(`/_api/ricos-site-pages/${pageTypePaths[pageType2]}`, {
        body: JSON.stringify(params2),
        headers: {
          "Content-Type": "application/json"
        },
        method: "POST"
      });
      const result = await response.json();
      return {
        ...result,
        items: result.items.map((item) => ({
          ...item,
          updatedDate: item.updatedDate ? new Date(item.updatedDate) : void 0
        })) || []
      };
    })(makeRequest, pageType, params),
    [makeRequest]
  );
  return useContext(DevContext)?.fetchSitePages || fetchSitePages;
};
export {
  useFetchSitePages
};
//# sourceMappingURL=use-fetch-site-pages.js.map
