import { _objectSpread2 } from "../../_virtual/_@oxc-project_runtime@0.122.0/helpers/objectSpread2.js";
import React, { useMemo } from "react";
import { Button, Space } from "antd";
import classNames from "classnames";
import "./PisellActionPanel.less";
//#region src/components/pisellActionPanel/PisellActionPanel.tsx
/**
* 单条操作项渲染为 Button（带可选 icon）
* 根据 priority 映射为 antd Button type
*/
function renderActionItem(item, index) {
	var _item$key, _item$priority;
	if (!(item.visible !== false)) return null;
	const key = (_item$key = item.key) !== null && _item$key !== void 0 ? _item$key : `action-${index}`;
	const priority = (_item$priority = item.priority) !== null && _item$priority !== void 0 ? _item$priority : "default";
	const buttonType = priority === "danger" ? "primary" : priority === "primary" ? "primary" : "default";
	const danger = priority === "danger";
	return /* @__PURE__ */ React.createElement(Button, {
		key,
		type: buttonType,
		danger,
		icon: item.icon,
		onClick: item.onClick,
		disabled: item.disabled,
		className: classNames("pisell-action-panel-btn", item.className),
		style: item.style
	}, item.label);
}
/**
* PisellActionPanel 操作面板
* 用于统一承载、编排和呈现一组用户可执行操作（Actions）的 Pro 组件。
* 支持分组、布局、对齐、主/次/危险层级与条件显隐。
*
* 设计文档：Action Panel (pcp_ge_actionPanel_V1.0)
*
* @param props 组件 Props
*/
function PisellActionPanel({ groups, layout = "horizontal", align = "left", overflowStrategy = "wrap", groupGap, itemGap, className, style }) {
	/** 过滤可见分组，并过滤每组内可见项 */
	const effectiveGroups = useMemo(() => {
		return groups.filter((g) => g.visible !== false).map((g) => _objectSpread2(_objectSpread2({}, g), {}, { items: g.items.filter((i) => i.visible !== false) })).filter((g) => g.items.length > 0);
	}, [groups]);
	const rootStyle = useMemo(() => {
		const s = _objectSpread2({}, style);
		if (groupGap !== void 0) s.gap = typeof groupGap === "number" ? `${groupGap}px` : groupGap;
		return s;
	}, [style, groupGap]);
	const itemGapValue = typeof itemGap === "number" ? itemGap : itemGap !== null && itemGap !== void 0 ? itemGap : 8;
	const isVertical = layout === "vertical";
	return /* @__PURE__ */ React.createElement("div", {
		className: classNames("pisell-action-panel-root", `pisell-action-panel-layout-${layout}`, `pisell-action-panel-align-${align}`, overflowStrategy === "scroll" && "pisell-action-panel-overflow-scroll", overflowStrategy === "wrap" && "pisell-action-panel-overflow-wrap", className),
		style: rootStyle
	}, effectiveGroups.map((group, groupIndex) => {
		var _group$key;
		return /* @__PURE__ */ React.createElement("div", {
			key: (_group$key = group.key) !== null && _group$key !== void 0 ? _group$key : `group-${groupIndex}`,
			className: classNames("pisell-action-panel-group", group.className),
			style: group.style
		}, /* @__PURE__ */ React.createElement(Space, {
			size: itemGapValue,
			direction: isVertical ? "vertical" : "horizontal",
			wrap: !isVertical && overflowStrategy === "wrap",
			className: "pisell-action-panel-group-space"
		}, group.items.map((item, itemIndex) => renderActionItem(item, itemIndex))));
	}));
}
//#endregion
export { PisellActionPanel };
