const require_runtime = require("../../../../_virtual/_rolldown/runtime.js");
let react = require("react");
react = require_runtime.__toESM(react);
let classnames = require("classnames");
classnames = require_runtime.__toESM(classnames);
let _ant_design_icons = require("@ant-design/icons");
require("./Collapse.less");
//#region src/plus/pisellFinancialSummary/components/Collapse/Collapse.tsx
const PREFIX_CLS = "pisell-collapse";
/**
* 单条可折叠项，与 Figma 14256:5103 Collapse 设计 1:1 一致。
* 结构：Head（时间/日期/客户/渠道 + 金额 + 展开图标）+ Body（明细行 + Void 等操作）。
*/
const Collapse = react.default.memo(({ headMeta, headAmount, expanded: controlledExpanded, defaultExpanded = false, onExpandChange, children, bodyRows, className, style }) => {
	var _headMeta$segments, _bodyRows$length;
	const [internalExpanded, setInternalExpanded] = (0, react.useState)(defaultExpanded);
	const isControlled = controlledExpanded !== void 0;
	const expanded = isControlled ? controlledExpanded : internalExpanded;
	const toggle = (0, react.useCallback)(() => {
		const next = !expanded;
		if (!isControlled) setInternalExpanded(next);
		onExpandChange === null || onExpandChange === void 0 || onExpandChange(next);
	}, [
		expanded,
		isControlled,
		onExpandChange
	]);
	const segments = (_headMeta$segments = headMeta.segments) !== null && _headMeta$segments !== void 0 ? _headMeta$segments : [];
	if (!segments.length && (headMeta.time != null || headMeta.date != null || headMeta.customer != null || headMeta.channel != null)) {
		if (headMeta.time != null || headMeta.date != null) segments.push(/* @__PURE__ */ react.default.createElement("span", {
			key: "time",
			className: `${PREFIX_CLS}-head-segment`
		}, [headMeta.time, headMeta.date].filter(Boolean).join(" ")));
		if (headMeta.customer != null) segments.push(/* @__PURE__ */ react.default.createElement("span", {
			key: "customer",
			className: `${PREFIX_CLS}-head-segment`
		}, headMeta.customer));
		if (headMeta.channel != null) segments.push(/* @__PURE__ */ react.default.createElement("span", {
			key: "channel",
			className: `${PREFIX_CLS}-head-segment`
		}, headMeta.channel));
	}
	const hasBody = ((_bodyRows$length = bodyRows === null || bodyRows === void 0 ? void 0 : bodyRows.length) !== null && _bodyRows$length !== void 0 ? _bodyRows$length : 0) > 0 || children != null;
	return /* @__PURE__ */ react.default.createElement("div", {
		className: (0, classnames.default)(PREFIX_CLS, className),
		style,
		"data-node-id": "14256:5103"
	}, /* @__PURE__ */ react.default.createElement("div", { className: `${PREFIX_CLS}-item` }, /* @__PURE__ */ react.default.createElement("div", {
		className: `${PREFIX_CLS}-head`,
		onClick: hasBody ? toggle : void 0,
		role: hasBody ? "button" : void 0,
		tabIndex: hasBody ? 0 : void 0,
		onKeyDown: (e) => {
			if (hasBody && (e.key === "Enter" || e.key === " ")) {
				e.preventDefault();
				toggle();
			}
		}
	}, /* @__PURE__ */ react.default.createElement("div", { className: `${PREFIX_CLS}-head-left` }, segments.map((seg, i) => /* @__PURE__ */ react.default.createElement("span", {
		key: i,
		className: `${PREFIX_CLS}-head-segment`
	}, seg))), /* @__PURE__ */ react.default.createElement("div", { className: `${PREFIX_CLS}-head-right` }, /* @__PURE__ */ react.default.createElement("span", { className: `${PREFIX_CLS}-head-amount` }, headAmount), hasBody && /* @__PURE__ */ react.default.createElement("span", {
		className: (0, classnames.default)(`${PREFIX_CLS}-head-chevron`, expanded && `${PREFIX_CLS}-head-chevron-expanded`),
		"aria-label": expanded ? "collapse" : "expand"
	}, /* @__PURE__ */ react.default.createElement(_ant_design_icons.UpOutlined, { style: { fontSize: 12 } })))), hasBody && expanded && /* @__PURE__ */ react.default.createElement("div", { className: `${PREFIX_CLS}-body` }, bodyRows === null || bodyRows === void 0 ? void 0 : bodyRows.map((row, i) => /* @__PURE__ */ react.default.createElement("div", {
		key: i,
		className: `${PREFIX_CLS}-body-row`
	}, /* @__PURE__ */ react.default.createElement("div", { className: `${PREFIX_CLS}-body-left` }, /* @__PURE__ */ react.default.createElement("ul", null, /* @__PURE__ */ react.default.createElement("li", null, row.label))), row.amount != null && /* @__PURE__ */ react.default.createElement("span", { className: `${PREFIX_CLS}-body-amount` }, row.amount), row.action != null && /* @__PURE__ */ react.default.createElement("button", {
		type: "button",
		className: `${PREFIX_CLS}-body-action`,
		onClick: (e) => {
			var _row$action, _row$action$onClick;
			e.stopPropagation();
			(_row$action = row.action) === null || _row$action === void 0 || (_row$action$onClick = _row$action.onClick) === null || _row$action$onClick === void 0 || _row$action$onClick.call(_row$action);
		}
	}, row.action.label))), children)));
});
Collapse.displayName = "Collapse";
//#endregion
exports.Collapse = Collapse;
