import { Fragment, jsx, jsxs } from "react/jsx-runtime";
import { useSelect } from "@wordpress/data";
import { store as coreStore } from "@wordpress/core-data";
import { Notice } from "@wordpress/components";
import { __ } from "@wordpress/i18n";
import { TEMPLATE_POST_TYPE } from "../../store/constants";
import EditorInterface from "../editor-interface";
import { ExperimentalEditorProvider } from "../provider";
import Sidebar from "../sidebar";
function Editor({
  postType,
  postId,
  templateId,
  settings,
  children,
  initialEdits,
  // This could be part of the settings.
  onActionPerformed,
  // The following abstractions are not ideal but necessary
  // to account for site editor and post editor differences for now.
  extraContent,
  extraSidebarPanels,
  ...props
}) {
  const { post, template, hasLoadedPost, error } = useSelect(
    (select) => {
      const {
        getEntityRecord,
        getResolutionError,
        hasFinishedResolution
      } = select(coreStore);
      const postArgs = ["postType", postType, postId];
      return {
        post: getEntityRecord(...postArgs),
        template: templateId ? getEntityRecord(
          "postType",
          TEMPLATE_POST_TYPE,
          templateId
        ) : void 0,
        hasLoadedPost: hasFinishedResolution(
          "getEntityRecord",
          postArgs
        ),
        error: getResolutionError("getEntityRecord", postArgs)?.message
      };
    },
    [postType, postId, templateId]
  );
  return /* @__PURE__ */ jsxs(Fragment, { children: [
    hasLoadedPost && !post && /* @__PURE__ */ jsx(
      Notice,
      {
        status: !!error ? "error" : "warning",
        isDismissible: false,
        children: !error ? __(
          "You attempted to edit an item that doesn't exist. Perhaps it was deleted?"
        ) : error
      }
    ),
    !!post && /* @__PURE__ */ jsxs(
      ExperimentalEditorProvider,
      {
        post,
        __unstableTemplate: template,
        settings,
        initialEdits,
        useSubRegistry: false,
        children: [
          /* @__PURE__ */ jsx(EditorInterface, { ...props, children: extraContent }),
          children,
          /* @__PURE__ */ jsx(
            Sidebar,
            {
              onActionPerformed,
              extraPanels: extraSidebarPanels
            }
          )
        ]
      }
    )
  ] });
}
var editor_default = Editor;
export {
  editor_default as default
};
//# sourceMappingURL=index.js.map
