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);

// src/components/pisellNavigationMenu/PisellNavigationMenu.tsx
var PisellNavigationMenu_exports = {};
__export(PisellNavigationMenu_exports, {
  default: () => PisellNavigationMenu_default
});
module.exports = __toCommonJS(PisellNavigationMenu_exports);
var import_react = __toESM(require("react"));
var import_pisellDropSort = __toESM(require("../pisellDropSort"));
var import_pisellTags = __toESM(require("../pisellTags"));
var import_icon = __toESM(require("../icon"));
var import_button = __toESM(require("../button"));
var import_locales = require("../../locales");
var import_antd = require("antd");
var import_pisellEmpty = __toESM(require("../pisellEmpty"));
var import_utils = require("./utils");
var import_PisellNavigationMenu = require("./PisellNavigationMenu.less");
var PisellNavigationMenu = ({
  value = [],
  allowDrag = true,
  allowDelete = true,
  allowAddChild = true,
  allowAddRoot = true,
  disabled = false,
  spacing = 8,
  maxLevel = 3,
  style,
  className,
  onChange,
  onAddSubMenu,
  onAddPage,
  onEdit,
  onDelete,
  __designMode,
  title
}) => {
  const convertToNavigationItems = (items2) => {
    return items2.map((item) => ({
      id: String(item.id),
      title: String(item.title || ""),
      path: String(item.path || "/"),
      children: item.children ? convertToNavigationItems(item.children) : []
    }));
  };
  const items = (0, import_react.useMemo)(() => {
    return [
      {
        label: (0, import_locales.getText)("pisell-lowcode-navigation-menu-add-sub-menu"),
        key: "add-child"
      },
      {
        label: (0, import_locales.getText)("pisell-lowcode-navigation-menu-add-page"),
        key: "add-page"
      }
    ];
  }, []);
  const handleClick = (0, import_react.useCallback)((key, item) => {
    if (key === "add-child") {
      onAddSubMenu == null ? void 0 : onAddSubMenu(item);
    } else if (key === "add-page") {
      onAddPage == null ? void 0 : onAddPage(item);
    }
  }, []);
  const renderMenuItem = (0, import_react.useCallback)(
    (itemProps) => {
      const { item } = itemProps;
      const { allowEdit = true, allowDelete: allowDelete2 = true, allowAddChild: allowAddChild2 = true, allowAddSubmenu = true, allowAddPage = true } = item;
      const isShowAddButton = item.isGroup && allowAddChild2 && (allowAddSubmenu || allowAddPage);
      return /* @__PURE__ */ import_react.default.createElement("div", { className: "pisell-lowcode-navigation-menu-item" }, /* @__PURE__ */ import_react.default.createElement("div", { className: "pisell-lowcode-navigation-menu-item-content" }, /* @__PURE__ */ import_react.default.createElement("div", { className: "pisell-lowcode-navigation-menu-item-content-icon" }, /* @__PURE__ */ import_react.default.createElement(import_icon.default, { type: item.icon })), /* @__PURE__ */ import_react.default.createElement("div", { className: "pisell-lowcode-navigation-menu-item-content-text" }, /* @__PURE__ */ import_react.default.createElement("div", { className: "pisell-lowcode-navigation-menu-item-title" }, item.title), /* @__PURE__ */ import_react.default.createElement("div", { className: "pisell-lowcode-navigation-menu-item-description" }, item.description, !item.isGroup && item.version && /* @__PURE__ */ import_react.default.createElement(import_pisellTags.default, { type: "pill_color", color: "success" }, item.version)))), /* @__PURE__ */ import_react.default.createElement("div", { className: "pisell-lowcode-navigation-menu-item-action-wrap" }, allowEdit && /* @__PURE__ */ import_react.default.createElement(
        import_button.default,
        {
          type: "text",
          onClick: () => onEdit == null ? void 0 : onEdit(item),
          className: "pisell-lowcode-navigation-menu-item-action-button",
          icon: /* @__PURE__ */ import_react.default.createElement(
            import_icon.default,
            {
              type: "pisell2-edit-05",
              className: "pisell-lowcode-navigation-menu-item-action-button-icon"
            }
          )
        }
      ), isShowAddButton && /* @__PURE__ */ import_react.default.createElement(
        import_antd.Dropdown,
        {
          menu: {
            items: [
              allowAddSubmenu && {
                key: "add-child",
                label: (0, import_locales.getText)("pisell-lowcode-navigation-menu-add-sub-menu"),
                onClick: () => handleClick("add-child", item)
              },
              allowAddPage && {
                key: "add-page",
                label: (0, import_locales.getText)("pisell-lowcode-navigation-menu-add-page"),
                onClick: () => handleClick("add-page", item)
              }
            ].filter(Boolean)
          }
        },
        /* @__PURE__ */ import_react.default.createElement(
          import_button.default,
          {
            type: "text",
            className: "pisell-lowcode-navigation-menu-item-action-button",
            icon: /* @__PURE__ */ import_react.default.createElement(
              import_icon.default,
              {
                type: "pisell2-plus",
                className: "pisell-lowcode-navigation-menu-item-action-button-icon"
              }
            )
          }
        )
      ), allowDelete2 && /* @__PURE__ */ import_react.default.createElement(
        import_button.default,
        {
          type: "text",
          onClick: () => onDelete == null ? void 0 : onDelete(item),
          className: "pisell-lowcode-navigation-menu-item-action-button",
          icon: /* @__PURE__ */ import_react.default.createElement(
            import_icon.default,
            {
              type: "pisell2-trash-01",
              className: "pisell-lowcode-navigation-menu-item-action-button-icon"
            }
          )
        }
      )));
    },
    [value, onChange]
  );
  const handleChange = (0, import_react.useCallback)(
    (items2) => {
      onChange == null ? void 0 : onChange(convertToNavigationItems(items2));
    },
    [onChange]
  );
  const leftContent = (0, import_react.useMemo)(() => {
    return /* @__PURE__ */ import_react.default.createElement("div", { className: "pisell-lowcode-navigation-menu-left-content" }, title);
  }, [title]);
  const rightContent = (0, import_react.useMemo)(() => {
    return /* @__PURE__ */ import_react.default.createElement("div", { className: "pisell-lowcode-navigation-menu-right-content" }, /* @__PURE__ */ import_react.default.createElement(
      import_button.default,
      {
        size: "large",
        type: "primary",
        icon: /* @__PURE__ */ import_react.default.createElement(import_icon.default, { type: "pisell2-plus" }),
        onClick: () => onAddSubMenu == null ? void 0 : onAddSubMenu()
      },
      (0, import_locales.getText)("pisell-lowcode-navigation-menu-add-sub-menu")
    ), /* @__PURE__ */ import_react.default.createElement(
      import_button.default,
      {
        size: "large",
        icon: /* @__PURE__ */ import_react.default.createElement(import_icon.default, { type: "pisell2-plus" }),
        onClick: () => onAddPage == null ? void 0 : onAddPage()
      },
      (0, import_locales.getText)("pisell-lowcode-navigation-menu-add-page")
    ));
  }, [title]);
  const formatValue = (0, import_react.useMemo)(() => {
    return (0, import_utils.formatTree)(value, (item) => ({
      ...item,
      disabledDrop: !item.isGroup
    }));
  }, [value]);
  const getItemStyle = (0, import_react.useCallback)((itemProps) => {
    const { item } = itemProps;
    return {
      backgroundColor: item.isGroup ? "#fff" : "var(--Gray-50, #F9FAFB)"
    };
  }, []);
  return /* @__PURE__ */ import_react.default.createElement(
    import_pisellDropSort.default,
    {
      value: formatValue,
      allowDrag,
      allowDelete,
      allowAddChild,
      allowAddRoot,
      disabled,
      spacing,
      maxLevel,
      style,
      className,
      onChange: handleChange,
      renderItem: renderMenuItem,
      isCustomAction: true,
      __designMode,
      leftContent,
      rightContent,
      getItemStyle,
      emptyContent: /* @__PURE__ */ import_react.default.createElement(
        import_pisellEmpty.default,
        {
          maxWidth: 400,
          description: (0, import_locales.getText)("pisell-lowcode-navigation-menu-add-page-tip")
        }
      )
    }
  );
};
var PisellNavigationMenu_default = PisellNavigationMenu;
