"use strict";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
  // If the importer is in node compatibility mode or this is not an ESM
  // file that has been converted to a CommonJS file using a Babel-
  // compatible transform (i.e. "__esModule" has not been set), then set
  // "default" to the CommonJS "module.exports" for node compatibility.
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
  mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);

// packages/block-editor/src/components/block-preview/index.js
var block_preview_exports = {};
__export(block_preview_exports, {
  BlockPreview: () => BlockPreview,
  default: () => block_preview_default,
  useBlockPreview: () => useBlockPreview
});
module.exports = __toCommonJS(block_preview_exports);
var import_clsx = __toESM(require("clsx"));
var import_compose = require("@wordpress/compose");
var import_data = require("@wordpress/data");
var import_element = require("@wordpress/element");
var import_deprecated = __toESM(require("@wordpress/deprecated"));
var import_provider = require("../provider");
var import_auto = __toESM(require("./auto"));
var import_editor_styles = __toESM(require("../editor-styles"));
var import_store = require("../../store");
var import_block_list = require("../block-list");
var import_async = require("./async");
var import_jsx_runtime = require("react/jsx-runtime");
var EMPTY_ADDITIONAL_STYLES = [];
function BlockPreview({
  blocks,
  viewportWidth = 1200,
  minHeight,
  additionalStyles = EMPTY_ADDITIONAL_STYLES,
  // Deprecated props:
  __experimentalMinHeight,
  __experimentalPadding
}) {
  if (__experimentalMinHeight) {
    minHeight = __experimentalMinHeight;
    (0, import_deprecated.default)("The __experimentalMinHeight prop", {
      since: "6.2",
      version: "6.4",
      alternative: "minHeight"
    });
  }
  if (__experimentalPadding) {
    additionalStyles = [
      ...additionalStyles,
      { css: `body { padding: ${__experimentalPadding}px; }` }
    ];
    (0, import_deprecated.default)("The __experimentalPadding prop of BlockPreview", {
      since: "6.2",
      version: "6.4",
      alternative: "additionalStyles"
    });
  }
  const originalSettings = (0, import_data.useSelect)(
    (select) => select(import_store.store).getSettings(),
    []
  );
  const settings = (0, import_element.useMemo)(
    () => ({
      ...originalSettings,
      focusMode: false,
      // Disable "Spotlight mode".
      isPreviewMode: true
    }),
    [originalSettings]
  );
  const renderedBlocks = (0, import_element.useMemo)(
    () => Array.isArray(blocks) ? blocks : [blocks],
    [blocks]
  );
  if (!blocks || blocks.length === 0) {
    return null;
  }
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
    import_provider.ExperimentalBlockEditorProvider,
    {
      value: renderedBlocks,
      settings,
      children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
        import_auto.default,
        {
          viewportWidth,
          minHeight,
          additionalStyles
        }
      )
    }
  );
}
var MemoizedBlockPreview = (0, import_element.memo)(BlockPreview);
MemoizedBlockPreview.Async = import_async.Async;
var block_preview_default = MemoizedBlockPreview;
function useBlockPreview({ blocks, props = {}, layout }) {
  const originalSettings = (0, import_data.useSelect)(
    (select) => select(import_store.store).getSettings(),
    []
  );
  const settings = (0, import_element.useMemo)(
    () => ({
      ...originalSettings,
      styles: void 0,
      // Clear styles included by the parent settings, as they are already output by the parent's EditorStyles.
      focusMode: false,
      // Disable "Spotlight mode".
      isPreviewMode: true
    }),
    [originalSettings]
  );
  const disabledRef = (0, import_compose.useDisabled)();
  const ref = (0, import_compose.useMergeRefs)([props.ref, disabledRef]);
  const renderedBlocks = (0, import_element.useMemo)(
    () => Array.isArray(blocks) ? blocks : [blocks],
    [blocks]
  );
  const children = /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
    import_provider.ExperimentalBlockEditorProvider,
    {
      value: renderedBlocks,
      settings,
      children: [
        /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_editor_styles.default, {}),
        /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_block_list.BlockListItems, { renderAppender: false, layout })
      ]
    }
  );
  return {
    ...props,
    ref,
    className: (0, import_clsx.default)(
      props.className,
      "block-editor-block-preview__live-content",
      "components-disabled"
    ),
    children: blocks?.length ? children : null
  };
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  BlockPreview,
  useBlockPreview
});
//# sourceMappingURL=index.js.map
