// packages/editor/src/components/post-revisions-preview/revisions-header.js
import { useSelect, useDispatch } from "@wordpress/data";
import { useViewportMatch } from "@wordpress/compose";
import { Button } from "@wordpress/components";
import { store as preferencesStore } from "@wordpress/preferences";
import { PinnedItems } from "@wordpress/interface";
import { __, _x } from "@wordpress/i18n";
import { seen } from "@wordpress/icons";
import HeaderSkeleton from "../header/header-skeleton.mjs";
import MoreMenu from "../more-menu/index.mjs";
import PostPreviewButton from "../post-preview-button/index.mjs";
import PreviewDropdown from "../preview-dropdown/index.mjs";
import RevisionsSlider from "./revisions-slider.mjs";
import { store as editorStore } from "../../store/index.mjs";
import {
  TEMPLATE_PART_POST_TYPE,
  PATTERN_POST_TYPE,
  NAVIGATION_POST_TYPE
} from "../../store/constants.mjs";
import { unlock } from "../../lock-unlock.mjs";
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
function RevisionsHeader({ showDiff, onToggleDiff }) {
  const isWideViewport = useViewportMatch("large");
  const { postType, showIconLabels, currentRevisionId } = useSelect(
    (select) => {
      const { get: getPreference } = select(preferencesStore);
      const { getCurrentPostType } = select(editorStore);
      return {
        postType: getCurrentPostType(),
        showIconLabels: getPreference("core", "showIconLabels"),
        currentRevisionId: unlock(
          select(editorStore)
        ).getCurrentRevisionId()
      };
    },
    []
  );
  const { setCurrentRevisionId, restoreRevision } = unlock(
    useDispatch(editorStore)
  );
  const disablePreviewOption = [
    NAVIGATION_POST_TYPE,
    TEMPLATE_PART_POST_TYPE,
    PATTERN_POST_TYPE
  ].includes(postType);
  const canRestore = !!currentRevisionId;
  const handleRestore = () => {
    if (currentRevisionId) {
      restoreRevision(currentRevisionId);
    }
  };
  return /* @__PURE__ */ jsx(
    HeaderSkeleton,
    {
      className: "editor-revisions-header",
      toolbar: /* @__PURE__ */ jsx(
        Button,
        {
          __next40pxDefaultSize: true,
          size: "compact",
          icon: seen,
          label: _x("Show changes", "revisions"),
          isPressed: showDiff,
          onClick: onToggleDiff
        }
      ),
      center: /* @__PURE__ */ jsx(RevisionsSlider, {}),
      settings: /* @__PURE__ */ jsxs(Fragment, { children: [
        /* @__PURE__ */ jsx(PreviewDropdown, { disabled: disablePreviewOption }),
        /* @__PURE__ */ jsx(PostPreviewButton, { className: "editor-header__post-preview-button" }),
        (isWideViewport || !showIconLabels) && /* @__PURE__ */ jsx(PinnedItems.Slot, { scope: "core" }),
        /* @__PURE__ */ jsx(
          Button,
          {
            __next40pxDefaultSize: true,
            variant: "secondary",
            size: "compact",
            onClick: () => setCurrentRevisionId(null),
            children: __("Exit")
          }
        ),
        /* @__PURE__ */ jsx(
          Button,
          {
            __next40pxDefaultSize: true,
            accessibleWhenDisabled: true,
            variant: "primary",
            size: "compact",
            className: "editor-revisions-header__restore-button",
            disabled: !canRestore,
            onClick: handleRestore,
            children: __("Restore")
          }
        ),
        /* @__PURE__ */ jsx(MoreMenu, { disabled: true })
      ] })
    }
  );
}
var revisions_header_default = RevisionsHeader;
export {
  revisions_header_default as default
};
//# sourceMappingURL=revisions-header.mjs.map
