const require_runtime = require("../../_virtual/_rolldown/runtime.js");
const require_index = require("../../locales/index.js");
const require_objectSpread2 = require("../../_virtual/_@oxc-project_runtime@0.122.0/helpers/objectSpread2.js");
const require_index$1 = require("../button/index.js");
const require_index$2 = require("../icon/index.js");
const require_index$3 = require("../pisellTags/index.js");
const require_index$4 = require("../pisellEmpty/index.js");
const require_index$5 = require("../pisellDropSort/index.js");
const require_utils = require("./utils.js");
let react = require("react");
react = require_runtime.__toESM(react);
let _pisell_utils = require("@pisell/utils");
let antd = require("antd");
let classnames = require("classnames");
classnames = require_runtime.__toESM(classnames);
require("./PisellNavigationMenu.less");
//#region src/components/pisellNavigationMenu/PisellNavigationMenu.tsx
const PisellNavigationMenu = ({ value = [], allowDrag = true, allowDelete = true, allowAddChild = true, allowAddRoot = true, allowIsShow = true, disabled = false, spacing = 8, maxLevel = 3, style, className, onChange, onAddSubMenu, onAddPage, onEdit, onDelete, onIsShow, __designMode, title, rightContent: propsRightContent, getItemStyle: propsGetItemStyle, canDrop, indentationWidth = 24, hideDescription, showActionOnHover, showTitleTags }) => {
	const convertToNavigationItems = (items) => {
		return items.map((item) => ({
			id: String(item.id),
			title: String(item.title || ""),
			path: String(item.path || "/"),
			collapsed: item.collapsed,
			children: item.children ? convertToNavigationItems(item.children) : []
		}));
	};
	(0, react.useMemo)(() => {
		return [{
			label: require_index.getText("pisell-lowcode-navigation-menu-add-sub-menu"),
			key: "add-child"
		}, {
			label: require_index.getText("pisell-lowcode-navigation-menu-add-page"),
			key: "add-page"
		}];
	}, []);
	const handleClick = (0, react.useCallback)((key, item) => {
		if (key === "add-child") onAddSubMenu === null || onAddSubMenu === void 0 || onAddSubMenu(item);
		else if (key === "add-page") onAddPage === null || onAddPage === void 0 || onAddPage(item);
	}, []);
	const tagTextMap = (0, react.useMemo)(() => {
		return {
			base: {
				text: require_index.getText("pisell-lowcode-navigation-menu-tag-base"),
				color: "#7f56d9"
			},
			proCode: {
				text: require_index.getText("pisell-lowcode-navigation-menu-tag-proCode"),
				color: "#1677ff"
			},
			pisellV1: {
				text: require_index.getText("pisell-lowcode-navigation-menu-tag-pisell1"),
				color: "#ee837a"
			},
			dynamicRoute: {
				text: require_index.getText("pisell-lowcode-navigation-menu-tag-dynamic-route"),
				color: "#ffc53d"
			},
			group: {
				text: require_index.getText("pisell-lowcode-navigation-menu-tag-group"),
				color: "#7f56d9"
			},
			subMenu: {
				text: require_index.getText("pisell-lowcode-navigation-menu-tag-sub-menu"),
				color: "#067647"
			},
			custom: {
				text: require_index.getText("pisell-lowcode-navigation-menu-tag-custom"),
				color: "#B54708"
			}
		};
	}, []);
	const renderMenuItem = (0, react.useCallback)((itemProps) => {
		var _tagTextMap$group, _tagTextMap$group2, _tagTextMap$subMenu, _tagTextMap$subMenu2, _tagTextMap$custom, _tagTextMap$custom2, _tagTextMap$item$sour, _tagTextMap$item$sour2;
		const { item } = itemProps;
		const { allowEdit = true, allowDelete = true, allowAddChild = true, allowAddSubmenu = true, allowAddPage = true, allowIsShow = true } = item;
		const isShowAddButton = item.isGroup && allowAddChild && (allowAddSubmenu || allowAddPage);
		return /* @__PURE__ */ react.default.createElement("div", { className: "pisell-lowcode-navigation-menu-item" }, /* @__PURE__ */ react.default.createElement("div", { className: "pisell-lowcode-navigation-menu-item-content" }, item.icon && /* @__PURE__ */ react.default.createElement("div", { className: "pisell-lowcode-navigation-menu-item-content-icon" }, /* @__PURE__ */ react.default.createElement(require_index$2.default, { type: item.icon })), /* @__PURE__ */ react.default.createElement("div", { className: "pisell-lowcode-navigation-menu-item-content-text" }, /* @__PURE__ */ react.default.createElement("div", { className: "pisell-lowcode-navigation-menu-item-title" }, item.title, showTitleTags && /* @__PURE__ */ react.default.createElement(react.default.Fragment, null, item.isGroup && item.is_top && /* @__PURE__ */ react.default.createElement(require_index$3.default, {
			type: "pill_color",
			color: (_tagTextMap$group = tagTextMap["group"]) === null || _tagTextMap$group === void 0 ? void 0 : _tagTextMap$group.color
		}, ((_tagTextMap$group2 = tagTextMap["group"]) === null || _tagTextMap$group2 === void 0 ? void 0 : _tagTextMap$group2.text) || ""), item.isGroup && !item.is_top && /* @__PURE__ */ react.default.createElement(require_index$3.default, {
			type: "pill_color",
			color: (_tagTextMap$subMenu = tagTextMap["subMenu"]) === null || _tagTextMap$subMenu === void 0 ? void 0 : _tagTextMap$subMenu.color
		}, ((_tagTextMap$subMenu2 = tagTextMap["subMenu"]) === null || _tagTextMap$subMenu2 === void 0 ? void 0 : _tagTextMap$subMenu2.text) || ""), item.isCustom && /* @__PURE__ */ react.default.createElement(require_index$3.default, {
			type: "pill_color",
			color: (_tagTextMap$custom = tagTextMap["custom"]) === null || _tagTextMap$custom === void 0 ? void 0 : _tagTextMap$custom.color
		}, ((_tagTextMap$custom2 = tagTextMap["custom"]) === null || _tagTextMap$custom2 === void 0 ? void 0 : _tagTextMap$custom2.text) || ""))), hideDescription ? null : /* @__PURE__ */ react.default.createElement("div", {
			className: "pisell-lowcode-navigation-menu-item-description",
			style: { display: hideDescription ? "none" : "flex" }
		}, item.description, item.source && /* @__PURE__ */ react.default.createElement(require_index$3.default, {
			type: "pill_color",
			color: (_tagTextMap$item$sour = tagTextMap[item.source]) === null || _tagTextMap$item$sour === void 0 ? void 0 : _tagTextMap$item$sour.color
		}, ((_tagTextMap$item$sour2 = tagTextMap[item.source]) === null || _tagTextMap$item$sour2 === void 0 ? void 0 : _tagTextMap$item$sour2.text) || ""), !item.isGroup && item.version && /* @__PURE__ */ react.default.createElement(require_index$3.default, {
			type: "pill_color",
			color: "success"
		}, "v", item.version)))), /* @__PURE__ */ react.default.createElement("div", { className: (0, classnames.default)("pisell-lowcode-navigation-menu-item-action-wrap", { "pisell-lowcode-navigation-menu-item-action-wrap-hover": showActionOnHover }) }, allowIsShow && /* @__PURE__ */ react.default.createElement(require_index$1.default, {
			type: "text",
			onClick: () => onIsShow === null || onIsShow === void 0 ? void 0 : onIsShow(item),
			className: "pisell-lowcode-navigation-menu-item-action-button",
			icon: /* @__PURE__ */ react.default.createElement(require_index$2.default, {
				type: item.is_show === false ? "pisell2-eye-off" : "pisell2-eye",
				className: "pisell-lowcode-navigation-menu-item-action-button-icon"
			})
		}), allowEdit && /* @__PURE__ */ react.default.createElement(require_index$1.default, {
			type: "text",
			onClick: () => onEdit === null || onEdit === void 0 ? void 0 : onEdit(item),
			className: "pisell-lowcode-navigation-menu-item-action-button",
			icon: /* @__PURE__ */ react.default.createElement(require_index$2.default, {
				type: "pisell2-edit-05",
				className: "pisell-lowcode-navigation-menu-item-action-button-icon"
			})
		}), isShowAddButton && /* @__PURE__ */ react.default.createElement(antd.Dropdown, {
			getPopupContainer: (triggerNode) => triggerNode,
			menu: { items: [allowAddSubmenu && {
				key: "add-child",
				label: require_index.getText("pisell-lowcode-navigation-menu-add-sub-menu"),
				onClick: () => handleClick("add-child", item)
			}, allowAddPage && {
				key: "add-page",
				label: require_index.getText("pisell-lowcode-navigation-menu-add-page"),
				onClick: () => handleClick("add-page", item)
			}].filter(Boolean) }
		}, /* @__PURE__ */ react.default.createElement(require_index$1.default, {
			type: "text",
			className: "pisell-lowcode-navigation-menu-item-action-button",
			icon: /* @__PURE__ */ react.default.createElement(require_index$2.default, {
				type: "pisell2-plus",
				className: "pisell-lowcode-navigation-menu-item-action-button-icon"
			})
		})), allowDelete && /* @__PURE__ */ react.default.createElement(require_index$1.default, {
			type: "text",
			onClick: () => onDelete === null || onDelete === void 0 ? void 0 : onDelete(item),
			className: "pisell-lowcode-navigation-menu-item-action-button",
			icon: /* @__PURE__ */ react.default.createElement(require_index$2.default, {
				type: "pisell2-trash-01",
				className: "pisell-lowcode-navigation-menu-item-action-button-icon"
			})
		})));
	}, [value, onChange]);
	const handleChange = (0, react.useCallback)((items) => {
		onChange === null || onChange === void 0 || onChange(convertToNavigationItems(items));
	}, [onChange]);
	const leftContent = (0, react.useMemo)(() => {
		return /* @__PURE__ */ react.default.createElement("div", { className: "pisell-lowcode-navigation-menu-left-content" }, title);
	}, [title]);
	const rightContent = (0, react.useMemo)(() => {
		if (propsRightContent) return propsRightContent;
		return /* @__PURE__ */ react.default.createElement("div", { className: "pisell-lowcode-navigation-menu-right-content" }, /* @__PURE__ */ react.default.createElement(require_index$1.default, {
			size: "large",
			type: "primary",
			icon: /* @__PURE__ */ react.default.createElement(require_index$2.default, { type: "pisell2-plus" }),
			onClick: () => onAddSubMenu === null || onAddSubMenu === void 0 ? void 0 : onAddSubMenu()
		}, require_index.getText("pisell-lowcode-navigation-menu-add-sub-menu")), /* @__PURE__ */ react.default.createElement(require_index$1.default, {
			size: "large",
			icon: /* @__PURE__ */ react.default.createElement(require_index$2.default, { type: "pisell2-plus" }),
			onClick: () => onAddPage === null || onAddPage === void 0 ? void 0 : onAddPage()
		}, require_index.getText("pisell-lowcode-navigation-menu-add-page")));
	}, [propsRightContent]);
	const formatValue = (0, react.useMemo)(() => {
		return require_utils.formatTree(value, (item) => require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, item), {}, { disabledDrop: !item.isGroup }));
	}, [value]);
	const getItemStyle = (0, react.useCallback)((itemProps) => {
		const { item } = itemProps;
		if ((0, _pisell_utils.isFunction)(propsGetItemStyle)) return (propsGetItemStyle === null || propsGetItemStyle === void 0 ? void 0 : propsGetItemStyle(item)) || {};
		return { backgroundColor: item.isGroup ? "#fff" : "var(--Gray-50, #F9FAFB)" };
	}, [propsGetItemStyle]);
	return /* @__PURE__ */ react.default.createElement(require_index$5.default, {
		indentationWidth,
		value: formatValue,
		allowDrag,
		allowDelete,
		allowAddChild,
		allowAddRoot,
		allowIsShow,
		disabled,
		spacing,
		maxLevel,
		style,
		className,
		onChange: handleChange,
		renderItem: renderMenuItem,
		isCustomAction: true,
		__designMode,
		leftContent,
		rightContent,
		getItemStyle,
		emptyContent: /* @__PURE__ */ react.default.createElement(require_index$4.default, {
			maxWidth: 400,
			description: require_index.getText("pisell-lowcode-navigation-menu-add-page-tip")
		}),
		canDrop
	});
};
//#endregion
exports.default = PisellNavigationMenu;
