"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var use_fetch_site_pages_exports = {};
__export(use_fetch_site_pages_exports, {
  useFetchSitePages: () => useFetchSitePages
});
module.exports = __toCommonJS(use_fetch_site_pages_exports);
var import_react = require("react");
var import_dev_context = require("./../../../ricos-context/dev-context.js");
var import_request_service_provider2 = require("./../../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 } = (0, import_request_service_provider2.useRequestService)();
  const fetchSitePages = (0, import_react.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 (0, import_react.useContext)(import_dev_context.DevContext)?.fetchSitePages || fetchSitePages;
};
//# sourceMappingURL=use-fetch-site-pages.js.map
