"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-list-item/index.js
var inserter_list_item_exports = {};
__export(inserter_list_item_exports, {
  default: () => inserter_list_item_default
});
module.exports = __toCommonJS(inserter_list_item_exports);
var import_clsx = __toESM(require("clsx"));
var import_element = require("@wordpress/element");
var import_blocks = require("@wordpress/blocks");
var import_components = require("@wordpress/components");
var import_keycodes = require("@wordpress/keycodes");
var import_block_icon = __toESM(require("../block-icon"));
var import_inserter_listbox = require("../inserter-listbox");
var import_inserter_draggable_blocks = __toESM(require("../inserter-draggable-blocks"));
var import_jsx_runtime = require("react/jsx-runtime");
function InserterListItem({
  className,
  isFirst,
  item,
  onSelect,
  onHover,
  isDraggable,
  ...props
}) {
  const isDraggingRef = (0, import_element.useRef)(false);
  const itemIconStyle = item.icon ? {
    backgroundColor: item.icon.background,
    color: item.icon.foreground
  } : {};
  const blocks = (0, import_element.useMemo)(
    () => [
      (0, import_blocks.createBlock)(
        item.name,
        item.initialAttributes,
        (0, import_blocks.createBlocksFromInnerBlocksTemplate)(item.innerBlocks)
      )
    ],
    [item.name, item.initialAttributes, item.innerBlocks]
  );
  const isSynced = (0, import_blocks.isReusableBlock)(item) && item.syncStatus !== "unsynced" || (0, import_blocks.isTemplatePart)(item);
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
    import_inserter_draggable_blocks.default,
    {
      isEnabled: isDraggable && !item.isDisabled,
      blocks,
      icon: item.icon,
      children: ({ draggable, onDragStart, onDragEnd }) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
        "div",
        {
          className: (0, import_clsx.default)(
            "block-editor-block-types-list__list-item",
            {
              "is-synced": isSynced
            }
          ),
          draggable,
          onDragStart: (event) => {
            isDraggingRef.current = true;
            if (onDragStart) {
              onHover(null);
              onDragStart(event);
            }
          },
          onDragEnd: (event) => {
            isDraggingRef.current = false;
            if (onDragEnd) {
              onDragEnd(event);
            }
          },
          children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
            import_inserter_listbox.InserterListboxItem,
            {
              isFirst,
              className: (0, import_clsx.default)(
                "block-editor-block-types-list__item",
                className
              ),
              disabled: item.isDisabled,
              onClick: (event) => {
                event.preventDefault();
                onSelect(
                  item,
                  (0, import_keycodes.isAppleOS)() ? event.metaKey : event.ctrlKey
                );
                onHover(null);
              },
              onKeyDown: (event) => {
                const { keyCode } = event;
                if (keyCode === import_keycodes.ENTER) {
                  event.preventDefault();
                  onSelect(
                    item,
                    (0, import_keycodes.isAppleOS)() ? event.metaKey : event.ctrlKey
                  );
                  onHover(null);
                }
              },
              onMouseEnter: () => {
                if (isDraggingRef.current) {
                  return;
                }
                onHover(item);
              },
              onMouseLeave: () => onHover(null),
              ...props,
              children: [
                /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
                  "span",
                  {
                    className: "block-editor-block-types-list__item-icon",
                    style: itemIconStyle,
                    children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_block_icon.default, { icon: item.icon, showColors: true })
                  }
                ),
                /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "block-editor-block-types-list__item-title", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_components.__experimentalTruncate, { numberOfLines: 3, children: item.title }) })
              ]
            }
          )
        }
      )
    }
  );
}
var inserter_list_item_default = (0, import_element.memo)(InserterListItem);
//# sourceMappingURL=index.js.map
