import React, { useMemo } from "react";
import { observer } from "mobx-react-lite";
import { toJS } from "mobx";
import {
type ContentClient,
type Document,
LayoutContentArea,
type PreviewPage,
withGlobalElementDefaults
} from "@webiny/website-builder-sdk";
import { ElementRenderer } from "~/components/ElementRenderer.js";
import { ElementSlot } from "~/components/ElementSlot.js";
import type { ComponentProps } from "~/types.js";
import { DocumentStoreScope, useDocumentStore } from "~/components/DocumentStoreProvider.js";
import { useSeededDocumentStore } from "~/components/useSeededDocumentStore.js";
import { PageScope, ReadOnlyScope, usePageLayout } from "~/components/PageLayout.js";
import { SlotLabel } from "~/components/SlotLabel.js";
import {
getLayoutAreaContent,
LayoutAreasProvider,
useLayoutAreas
} from "~/components/LayoutAreas.js";
import { getContentAreaLabel } from "./LayoutContentLabel.js";
import { useContentClient } from "~/components/useContentClient.js";
const toPreviewDocument = (page: PreviewPage, client: ContentClient): Document => {
const document: Document = {
id: page.id,
version: 1,
state: {},
extensions: {},
metadata: {},
properties: page.properties ?? { id: page.id },
elements: page.elements ?? {},
bindings: page.bindings ?? {}
};
// Globals the page has no stored instance of render from their manifest defaults, as on the live site.
const withDefaults = withGlobalElementDefaults(document, client.getComponentManifests());
return { ...document, elements: withDefaults.elements, bindings: withDefaults.bindings };
};
/**
* The page's content of one area. The main area is the page root, as on a page without a layout; the
* others are slots of the page root. In the page editor, each is a place to drop content.
*/
const PageArea = observer(({ area }: { area: LayoutContentArea }) => {
const documentStore = useDocumentStore();
const slot = area.slot();
// While an area is empty, its drop area in the page editor says which one it is.
if (area.isMain()) {
return (