"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/inserter/preview-panel.js
var preview_panel_exports = {};
__export(preview_panel_exports, {
  default: () => preview_panel_default
});
module.exports = __toCommonJS(preview_panel_exports);
var import_blocks = require("@wordpress/blocks");
var import_element = require("@wordpress/element");
var import_i18n = require("@wordpress/i18n");
var import_block_card = __toESM(require("../block-card"));
var import_block_preview = __toESM(require("../block-preview"));
var import_jsx_runtime = require("react/jsx-runtime");
function InserterPreviewPanel({ item }) {
  const { name, title, icon, description, initialAttributes, example } = item;
  const isReusable = (0, import_blocks.isReusableBlock)(item);
  const blocks = (0, import_element.useMemo)(() => {
    if (!example) {
      return (0, import_blocks.createBlock)(name, initialAttributes);
    }
    return (0, import_blocks.getBlockFromExample)(name, {
      attributes: {
        ...example.attributes,
        ...initialAttributes
      },
      innerBlocks: example.innerBlocks
    });
  }, [name, example, initialAttributes]);
  const previewHeight = 144;
  const sidebarWidth = 280;
  const viewportWidth = example?.viewportWidth ?? 500;
  const scale = sidebarWidth / viewportWidth;
  const minHeight = scale !== 0 && scale < 1 && previewHeight ? previewHeight / scale : previewHeight;
  return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "block-editor-inserter__preview-container", children: [
    /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "block-editor-inserter__preview", children: isReusable || example ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "block-editor-inserter__preview-content", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
      import_block_preview.default,
      {
        blocks,
        viewportWidth,
        minHeight: previewHeight,
        additionalStyles: (
          //We want this CSS to be in sync with the one in BlockPreviewPanel.
          [
            {
              css: `
										body { 
											padding: 24px;
											min-height:${Math.round(minHeight)}px;
											display:flex;
											align-items:center;
										}
										.is-root-container { width: 100%; }
									`
            }
          ]
        )
      }
    ) }) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "block-editor-inserter__preview-content-missing", children: (0, import_i18n.__)("No preview available.") }) }),
    !isReusable && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
      import_block_card.default,
      {
        title,
        icon,
        description
      }
    )
  ] });
}
var preview_panel_default = InserterPreviewPanel;
//# sourceMappingURL=preview-panel.js.map
