"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-switcher/pattern-transformations-menu.js
var pattern_transformations_menu_exports = {};
__export(pattern_transformations_menu_exports, {
  default: () => pattern_transformations_menu_default
});
module.exports = __toCommonJS(pattern_transformations_menu_exports);
var import_i18n = require("@wordpress/i18n");
var import_element = require("@wordpress/element");
var import_compose = require("@wordpress/compose");
var import_icons = require("@wordpress/icons");
var import_components = require("@wordpress/components");
var import_block_preview = __toESM(require("../block-preview"));
var import_use_transformed_patterns = __toESM(require("./use-transformed-patterns"));
var import_jsx_runtime = require("react/jsx-runtime");
function PatternTransformationsMenu({
  blocks,
  patterns: statePatterns,
  onSelect
}) {
  const [showTransforms, setShowTransforms] = (0, import_element.useState)(false);
  const patterns = (0, import_use_transformed_patterns.default)(statePatterns, blocks);
  if (!patterns.length) {
    return null;
  }
  return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_components.MenuGroup, { className: "block-editor-block-switcher__pattern__transforms__menugroup", children: [
    showTransforms && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
      PreviewPatternsPopover,
      {
        patterns,
        onSelect
      }
    ),
    /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
      import_components.MenuItem,
      {
        onClick: (event) => {
          event.preventDefault();
          setShowTransforms(!showTransforms);
        },
        icon: import_icons.chevronRight,
        children: (0, import_i18n.__)("Patterns")
      }
    )
  ] });
}
function PreviewPatternsPopover({ patterns, onSelect }) {
  const isMobile = (0, import_compose.useViewportMatch)("medium", "<");
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "block-editor-block-switcher__popover-preview-container", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
    import_components.Popover,
    {
      className: "block-editor-block-switcher__popover-preview",
      placement: isMobile ? "bottom" : "right-start",
      offset: 16,
      children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "block-editor-block-switcher__preview is-pattern-list-preview", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
        BlockPatternsList,
        {
          patterns,
          onSelect
        }
      ) })
    }
  ) });
}
function BlockPatternsList({ patterns, onSelect }) {
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
    import_components.Composite,
    {
      role: "listbox",
      className: "block-editor-block-switcher__preview-patterns-container",
      "aria-label": (0, import_i18n.__)("Patterns list"),
      children: patterns.map((pattern) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
        BlockPattern,
        {
          pattern,
          onSelect
        },
        pattern.name
      ))
    }
  );
}
function BlockPattern({ pattern, onSelect }) {
  const baseClassName = "block-editor-block-switcher__preview-patterns-container";
  const descriptionId = (0, import_compose.useInstanceId)(
    BlockPattern,
    `${baseClassName}-list__item-description`
  );
  return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: `${baseClassName}-list__list-item`, children: [
    /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
      import_components.Composite.Item,
      {
        render: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
          "div",
          {
            role: "option",
            "aria-label": pattern.title,
            "aria-describedby": pattern.description ? descriptionId : void 0,
            className: `${baseClassName}-list__item`
          }
        ),
        onClick: () => onSelect(pattern.transformedBlocks),
        children: [
          /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
            import_block_preview.default,
            {
              blocks: pattern.transformedBlocks,
              viewportWidth: pattern.viewportWidth || 500
            }
          ),
          /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: `${baseClassName}-list__item-title`, children: pattern.title })
        ]
      }
    ),
    !!pattern.description && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_components.VisuallyHidden, { id: descriptionId, children: pattern.description })
  ] });
}
var pattern_transformations_menu_default = PatternTransformationsMenu;
//# sourceMappingURL=pattern-transformations-menu.js.map
