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/plus/pisellFinancialSummary/components/Collapse/Collapse.tsx
var Collapse_exports = {};
__export(Collapse_exports, {
  Collapse: () => Collapse
});
module.exports = __toCommonJS(Collapse_exports);
var import_react = __toESM(require("react"));
var import_classnames = __toESM(require("classnames"));
var import_icons = require("@ant-design/icons");
var import_Collapse = require("./Collapse.less");
var PREFIX_CLS = "pisell-collapse";
var Collapse = import_react.default.memo(
  ({
    headMeta,
    headAmount,
    expanded: controlledExpanded,
    defaultExpanded = false,
    onExpandChange,
    children,
    bodyRows,
    className,
    style
  }) => {
    const [internalExpanded, setInternalExpanded] = (0, import_react.useState)(defaultExpanded);
    const isControlled = controlledExpanded !== void 0;
    const expanded = isControlled ? controlledExpanded : internalExpanded;
    const toggle = (0, import_react.useCallback)(() => {
      const next = !expanded;
      if (!isControlled) setInternalExpanded(next);
      onExpandChange == null ? void 0 : onExpandChange(next);
    }, [expanded, isControlled, onExpandChange]);
    const segments = 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__ */ import_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__ */ import_react.default.createElement("span", { key: "customer", className: `${PREFIX_CLS}-head-segment` }, headMeta.customer)
        );
      }
      if (headMeta.channel != null) {
        segments.push(
          /* @__PURE__ */ import_react.default.createElement("span", { key: "channel", className: `${PREFIX_CLS}-head-segment` }, headMeta.channel)
        );
      }
    }
    const hasBody = ((bodyRows == null ? void 0 : bodyRows.length) ?? 0) > 0 || children != null;
    return /* @__PURE__ */ import_react.default.createElement(
      "div",
      {
        className: (0, import_classnames.default)(PREFIX_CLS, className),
        style,
        "data-node-id": "14256:5103"
      },
      /* @__PURE__ */ import_react.default.createElement("div", { className: `${PREFIX_CLS}-item` }, /* @__PURE__ */ import_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__ */ import_react.default.createElement("div", { className: `${PREFIX_CLS}-head-left` }, segments.map((seg, i) => /* @__PURE__ */ import_react.default.createElement("span", { key: i, className: `${PREFIX_CLS}-head-segment` }, seg))),
        /* @__PURE__ */ import_react.default.createElement("div", { className: `${PREFIX_CLS}-head-right` }, /* @__PURE__ */ import_react.default.createElement("span", { className: `${PREFIX_CLS}-head-amount` }, headAmount), hasBody && /* @__PURE__ */ import_react.default.createElement(
          "span",
          {
            className: (0, import_classnames.default)(
              `${PREFIX_CLS}-head-chevron`,
              expanded && `${PREFIX_CLS}-head-chevron-expanded`
            ),
            "aria-label": expanded ? "collapse" : "expand"
          },
          /* @__PURE__ */ import_react.default.createElement(import_icons.UpOutlined, { style: { fontSize: 12 } })
        ))
      ), hasBody && expanded && /* @__PURE__ */ import_react.default.createElement("div", { className: `${PREFIX_CLS}-body` }, bodyRows == null ? void 0 : bodyRows.map((row, i) => /* @__PURE__ */ import_react.default.createElement("div", { key: i, className: `${PREFIX_CLS}-body-row` }, /* @__PURE__ */ import_react.default.createElement("div", { className: `${PREFIX_CLS}-body-left` }, /* @__PURE__ */ import_react.default.createElement("ul", null, /* @__PURE__ */ import_react.default.createElement("li", null, row.label))), row.amount != null && /* @__PURE__ */ import_react.default.createElement("span", { className: `${PREFIX_CLS}-body-amount` }, row.amount), row.action != null && /* @__PURE__ */ import_react.default.createElement(
        "button",
        {
          type: "button",
          className: `${PREFIX_CLS}-body-action`,
          onClick: (e) => {
            var _a, _b;
            e.stopPropagation();
            (_b = (_a = row.action) == null ? void 0 : _a.onClick) == null ? void 0 : _b.call(_a);
          }
        },
        row.action.label
      ))), children))
    );
  }
);
Collapse.displayName = "Collapse";
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  Collapse
});
