// packages/editor/src/components/editor-interface/index.js
import clsx from "clsx";
import { InterfaceSkeleton, ComplementaryArea } from "@wordpress/interface";
import { useSelect } from "@wordpress/data";
import { __ } from "@wordpress/i18n";
import { store as preferencesStore } from "@wordpress/preferences";
import { BlockBreadcrumb, BlockToolbar } from "@wordpress/block-editor";
import { useViewportMatch } from "@wordpress/compose";
import { useState, useCallback } from "@wordpress/element";
import { decodeEntities } from "@wordpress/html-entities";
import { store as editorStore } from "../../store/index.js";
import { unlock } from "../../lock-unlock.js";
import EditorNotices from "../editor-notices/index.js";
import Header from "../header/index.js";
import InserterSidebar from "../inserter-sidebar/index.js";
import ListViewSidebar from "../list-view-sidebar/index.js";
import SavePublishPanels from "../save-publish-panels/index.js";
import TextEditor from "../text-editor/index.js";
import VisualEditor from "../visual-editor/index.js";
import StylesCanvas from "../styles-canvas/index.js";
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
var interfaceLabels = {
  /* translators: accessibility text for the editor top bar landmark region. */
  header: __("Editor top bar"),
  /* translators: accessibility text for the editor content landmark region. */
  body: __("Editor content"),
  /* translators: accessibility text for the editor settings landmark region. */
  sidebar: __("Editor settings"),
  /* translators: accessibility text for the editor publish landmark region. */
  actions: __("Editor publish"),
  /* translators: accessibility text for the editor footer landmark region. */
  footer: __("Editor footer")
};
function EditorInterface({
  className,
  children,
  forceIsDirty,
  contentRef,
  disableIframe,
  autoFocus,
  customSaveButton,
  customSavePanel,
  forceDisableBlockTools,
  iframeProps
}) {
  const {
    mode,
    isInserterOpened,
    isListViewOpened,
    isDistractionFree,
    isPreviewMode,
    showBlockBreadcrumbs,
    postTypeLabel,
    stylesPath,
    showStylebook
  } = useSelect((select) => {
    const { get } = select(preferencesStore);
    const { getEditorSettings, getPostTypeLabel } = select(editorStore);
    const { getStylesPath, getShowStylebook } = unlock(
      select(editorStore)
    );
    const editorSettings = getEditorSettings();
    let _mode = select(editorStore).getEditorMode();
    if (!editorSettings.richEditingEnabled && _mode === "visual") {
      _mode = "text";
    }
    if (!editorSettings.codeEditingEnabled && _mode === "text") {
      _mode = "visual";
    }
    return {
      mode: _mode,
      isInserterOpened: select(editorStore).isInserterOpened(),
      isListViewOpened: select(editorStore).isListViewOpened(),
      isDistractionFree: get("core", "distractionFree"),
      isPreviewMode: editorSettings.isPreviewMode,
      showBlockBreadcrumbs: get("core", "showBlockBreadcrumbs"),
      postTypeLabel: getPostTypeLabel(),
      stylesPath: getStylesPath(),
      showStylebook: getShowStylebook()
    };
  }, []);
  const isLargeViewport = useViewportMatch("medium");
  const secondarySidebarLabel = isListViewOpened ? __("Document Overview") : __("Block Library");
  const shouldShowStylesCanvas = showStylebook || stylesPath?.startsWith("/revisions");
  const [entitiesSavedStatesCallback, setEntitiesSavedStatesCallback] = useState(false);
  const closeEntitiesSavedStates = useCallback(
    (arg) => {
      if (typeof entitiesSavedStatesCallback === "function") {
        entitiesSavedStatesCallback(arg);
      }
      setEntitiesSavedStatesCallback(false);
    },
    [entitiesSavedStatesCallback]
  );
  return /* @__PURE__ */ jsx(
    InterfaceSkeleton,
    {
      isDistractionFree,
      className: clsx("editor-editor-interface", className, {
        "is-entity-save-view-open": !!entitiesSavedStatesCallback,
        "is-distraction-free": isDistractionFree && !isPreviewMode
      }),
      labels: {
        ...interfaceLabels,
        secondarySidebar: secondarySidebarLabel
      },
      header: !isPreviewMode && /* @__PURE__ */ jsx(
        Header,
        {
          forceIsDirty,
          setEntitiesSavedStatesCallback,
          customSaveButton,
          forceDisableBlockTools
        }
      ),
      editorNotices: /* @__PURE__ */ jsx(EditorNotices, {}),
      secondarySidebar: !isPreviewMode && mode === "visual" && (isInserterOpened && /* @__PURE__ */ jsx(InserterSidebar, {}) || isListViewOpened && /* @__PURE__ */ jsx(ListViewSidebar, {})),
      sidebar: !isPreviewMode && !isDistractionFree && /* @__PURE__ */ jsx(ComplementaryArea.Slot, { scope: "core" }),
      content: /* @__PURE__ */ jsxs(Fragment, { children: [
        !isDistractionFree && !isPreviewMode && /* @__PURE__ */ jsx(EditorNotices, {}),
        shouldShowStylesCanvas ? /* @__PURE__ */ jsx(StylesCanvas, {}) : /* @__PURE__ */ jsxs(Fragment, { children: [
          !isPreviewMode && mode === "text" && /* @__PURE__ */ jsx(
            TextEditor,
            {
              autoFocus
            }
          ),
          !isPreviewMode && !isLargeViewport && mode === "visual" && /* @__PURE__ */ jsx(BlockToolbar, { hideDragHandle: true }),
          (isPreviewMode || mode === "visual") && /* @__PURE__ */ jsx(
            VisualEditor,
            {
              contentRef,
              disableIframe,
              autoFocus,
              iframeProps
            }
          ),
          children
        ] })
      ] }),
      footer: !isPreviewMode && !isDistractionFree && isLargeViewport && showBlockBreadcrumbs && mode === "visual" && /* @__PURE__ */ jsx(
        BlockBreadcrumb,
        {
          rootLabelText: postTypeLabel ? decodeEntities(postTypeLabel) : void 0
        }
      ),
      actions: !isPreviewMode ? customSavePanel || /* @__PURE__ */ jsx(
        SavePublishPanels,
        {
          closeEntitiesSavedStates,
          isEntitiesSavedStatesOpen: entitiesSavedStatesCallback,
          setEntitiesSavedStatesCallback,
          forceIsDirtyPublishPanel: forceIsDirty
        }
      ) : void 0
    }
  );
}
export {
  EditorInterface as default
};
//# sourceMappingURL=index.js.map
