import { useDebounceCallback as i } from "../../../../../node_modules/.pnpm/usehooks-ts@3.1.1_react@18.3.0-canary-3d9b20132-20240124/node_modules/usehooks-ts/dist/index.js";
import { useEditorHelpers as c } from "../../../../../use-editor.js";
import { useDraft as r, usePageInfo as d, useSectionsSubscribe as b, usePageAttributesSubscribe as p, useSiteAttributesSubscribe as S, usePagePathSubscribe as h, useThemeSubscribe as l } from "../../../../../use-page-data.js";
const n = 1e3;
function P() {
  const t = r(), s = d(), { onSavePage: g, onSaveSite: u } = c(), a = i(async (e) => {
    await g?.({
      pageId: s.id,
      pageVersionId: "latest",
      siteId: s.siteId,
      data: e
    }), t.setDirty(!1);
  }, n), o = i(async (e) => {
    await u?.({
      siteId: s.siteId,
      data: e
    }), t.setDirty(!1);
  }, n);
  b((e) => {
    console.debug("Sections have changed, updating page version", e), a({ sections: e });
  }), p((e) => {
    console.debug("Page attributes have changed:", e), a({ attributes: e });
  }), S((e) => {
    console.debug("Site attributes have changed:", e), o({ attributes: e });
  }), h((e) => {
    console.debug("pagePath has changed, updating page version"), a({ path: e });
  }), l((e) => {
    console.debug("theme has changed, updating page version"), o({ theme: e });
  });
}
export {
  P as usePageAutoSave
};
//# sourceMappingURL=use-page-autosave.js.map
