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/pisellHierarchicalSummaryList/components/Row.tsx
var Row_exports = {};
__export(Row_exports, {
  Row: () => Row
});
module.exports = __toCommonJS(Row_exports);
var import_react = __toESM(require("react"));
var import_antd = require("antd");
var import_icons = require("@ant-design/icons");
var import_classnames = __toESM(require("classnames"));
function getLevelCfg(levelConfig, level) {
  for (let lv = level; lv >= 1; lv--) {
    const cfg = levelConfig == null ? void 0 : levelConfig[lv];
    if (cfg) return cfg;
  }
  return void 0;
}
function normalizeChildren(children) {
  if (!(children == null ? void 0 : children.length)) return [];
  return children.filter((c) => !c.hidden).slice().sort((a, b) => (a.order ?? 0) - (b.order ?? 0));
}
function defaultGetNumberValue(item) {
  return typeof item.value === "number" ? item.value : null;
}
function aggregateSum(item, getNumberValue) {
  var _a;
  const children = normalizeChildren(item.children);
  if (!children.length) return 0;
  let sum = 0;
  for (const child of children) {
    const self = getNumberValue(child);
    if (typeof self === "number" && !Number.isNaN(self)) {
      sum += self;
    }
    if ((_a = child.children) == null ? void 0 : _a.length) {
      sum += aggregateSum(child, getNumberValue);
    }
  }
  return sum;
}
var Row = import_react.default.memo((props) => {
  var _a, _b, _c;
  const {
    prefixCls,
    item,
    level,
    index,
    parentPathKeys,
    expandedKeySet,
    toggleExpanded,
    getKey,
    levelConfig,
    indent,
    rowGap,
    gaps,
    maxRenderLevel,
    maxExpandLevel,
    aggregate,
    renderLabel,
    renderValue,
    parentHasItemsCount = false
  } = props;
  const key = (0, import_react.useMemo)(
    () => item.key ?? getKey(item, { level, index, parentPathKeys }),
    [getKey, index, item, level, parentPathKeys]
  );
  const pathKeys = (0, import_react.useMemo)(
    () => [...parentPathKeys, key],
    [parentPathKeys, key]
  );
  const children = (0, import_react.useMemo)(
    () => normalizeChildren(item.children),
    [item.children]
  );
  const hasExpandedContent = item.expandedContent != null;
  const canRenderChildren = maxRenderLevel ? level < maxRenderLevel : true;
  const hasChildren = canRenderChildren && children.length > 0 || hasExpandedContent;
  const canExpand = hasChildren && (maxExpandLevel ? level < maxExpandLevel : true);
  const expanded = canExpand && expandedKeySet.has(key);
  const cfg = getLevelCfg(levelConfig, level);
  const nextIndent = (cfg == null ? void 0 : cfg.indent) ?? indent;
  const rowStyleMerged = {
    ...cfg == null ? void 0 : cfg.rowStyle,
    ...item.rowStyle
  };
  if (level === 1) {
    rowStyleMerged.paddingTop = 20;
    rowStyleMerged.paddingBottom = 20;
  }
  if (level === 2) {
    rowStyleMerged.paddingTop = 20;
    rowStyleMerged.paddingBottom = expanded ? 16 : 20;
  }
  const aggregatedValue = (0, import_react.useMemo)(() => {
    if (item.value !== void 0) return void 0;
    if (!aggregate || (aggregate.mode ?? "none") === "none") return void 0;
    if ((aggregate.mode ?? "none") !== "sum") return void 0;
    const sum = aggregateSum(
      item,
      aggregate.getNumberValue ?? defaultGetNumberValue
    );
    return aggregate.format ? aggregate.format(sum, { item, level }) : sum;
  }, [aggregate, item, level]);
  const ctx = (0, import_react.useMemo)(
    () => ({
      level,
      pathKeys,
      expanded,
      hasChildren,
      aggregatedValue
    }),
    [aggregatedValue, expanded, hasChildren, level, pathKeys]
  );
  const siblingKeys = (0, import_react.useMemo)(
    () => hasExpandedContent ? [] : children.map(
      (c, i) => c.key ?? getKey(c, {
        level: level + 1,
        index: i,
        parentPathKeys: pathKeys
      })
    ),
    [children, getKey, hasExpandedContent, level, pathKeys]
  );
  const onToggle = (0, import_react.useCallback)(() => {
    if (!canExpand) return;
    toggleExpanded(key, { siblingKeys });
  }, [canExpand, key, siblingKeys, toggleExpanded]);
  const left = renderLabel ? renderLabel(item, ctx) : item.label;
  const right = renderValue ? renderValue(item, ctx) : aggregatedValue ?? item.value;
  const showDotSeparator = (cfg == null ? void 0 : cfg.showDotSeparator) ?? true;
  const showItemsCount = item.itemsCount !== void 0 && item.itemsCount !== null;
  const showInfo = item.infoTooltip !== void 0 && item.infoTooltip !== null;
  const metaStyle = cfg == null ? void 0 : cfg.metaTextStyle;
  const infoIconStyleObj = (cfg == null ? void 0 : cfg.infoIconStyle) != null ? {
    fontSize: cfg.infoIconStyle.size,
    color: cfg.infoIconStyle.color,
    width: cfg.infoIconStyle.width ?? cfg.infoIconStyle.size ?? 16,
    height: cfg.infoIconStyle.height ?? cfg.infoIconStyle.size ?? 16,
    display: "inline-flex",
    alignItems: "center",
    justifyContent: "center"
  } : showInfo ? {
    fontSize: 16,
    width: 16,
    height: 16,
    display: "inline-flex",
    alignItems: "center",
    justifyContent: "center"
  } : void 0;
  const leftMeta = (showItemsCount || showInfo) && /* @__PURE__ */ import_react.default.createElement(
    "span",
    {
      className: `${prefixCls}-row-meta`,
      style: {
        ...metaStyle,
        ...(gaps == null ? void 0 : gaps.meta) !== void 0 ? { gap: gaps.meta } : void 0
      }
    },
    showItemsCount ? /* @__PURE__ */ import_react.default.createElement("span", { className: `${prefixCls}-row-items-count`, style: metaStyle }, item.itemsCount) : null,
    showInfo ? /* @__PURE__ */ import_react.default.createElement(import_antd.Tooltip, { title: item.infoTooltip }, /* @__PURE__ */ import_react.default.createElement(
      "span",
      {
        className: `${prefixCls}-row-info`,
        "aria-label": "info",
        style: infoIconStyleObj
      },
      /* @__PURE__ */ import_react.default.createElement(import_icons.QuestionCircleOutlined, null)
    )) : null
  );
  const isTitleRow = level <= 2;
  const nodeStyle = {
    ...isTitleRow ? expanded ? { paddingBottom: 20 } : {} : { marginTop: rowGap },
    ...level === 2 ? { paddingLeft: 20, paddingRight: 20 } : {},
    ...level === 2 && ((_a = cfg == null ? void 0 : cfg.divider) == null ? void 0 : _a.show) ? {
      borderTop: `1px ${cfg.divider.style ?? "solid"} ${cfg.divider.color ?? "#D0D5DD"}`
    } : {}
  };
  const isGroupOnly = hasChildren && (item.label === "" || item.label === null || item.label === void 0) && item.value === void 0;
  if (isGroupOnly) {
    return /* @__PURE__ */ import_react.default.createElement(import_react.default.Fragment, null, children.map((child, childIndex) => /* @__PURE__ */ import_react.default.createElement(
      Row,
      {
        key: child.key ?? getKey(child, {
          level,
          index: childIndex,
          parentPathKeys: pathKeys
        }),
        ...props,
        item: child,
        level,
        index: childIndex,
        parentPathKeys: pathKeys
      }
    )));
  }
  return /* @__PURE__ */ import_react.default.createElement("div", { className: `${prefixCls}-node`, style: nodeStyle }, /* @__PURE__ */ import_react.default.createElement(
    "div",
    {
      className: (0, import_classnames.default)(
        `${prefixCls}-row`,
        cfg == null ? void 0 : cfg.rowClassName,
        item.rowClassName,
        {
          [`${prefixCls}-row-expandable`]: canExpand,
          [`${prefixCls}-row-expanded`]: expanded
        }
      ),
      style: {
        ...rowStyleMerged,
        ...(gaps == null ? void 0 : gaps.row) !== void 0 ? { gap: gaps.row } : void 0
      },
      onClick: onToggle,
      role: canExpand ? "button" : void 0,
      tabIndex: canExpand ? 0 : void 0,
      onKeyDown: (e) => {
        if (!canExpand) return;
        if (e.key === "Enter" || e.key === " ") {
          e.preventDefault();
          onToggle();
        }
      }
    },
    /* @__PURE__ */ import_react.default.createElement(
      "div",
      {
        className: `${prefixCls}-row-left`,
        style: (gaps == null ? void 0 : gaps.rowLeft) !== void 0 ? { gap: gaps.rowLeft } : void 0
      },
      parentHasItemsCount && !showItemsCount ? /* @__PURE__ */ import_react.default.createElement(
        "span",
        {
          className: `${prefixCls}-row-bullet`,
          style: { color: "#667085", flexShrink: 0 },
          "aria-hidden": true
        },
        "•"
      ) : null,
      /* @__PURE__ */ import_react.default.createElement(
        "span",
        {
          className: `${prefixCls}-row-label`,
          style: parentHasItemsCount ? { ...cfg == null ? void 0 : cfg.labelTextStyle, color: "#667085", fontWeight: 400 } : cfg == null ? void 0 : cfg.labelTextStyle,
          title: typeof item.label === "string" ? item.label : void 0
        },
        left
      ),
      leftMeta,
      /* @__PURE__ */ import_react.default.createElement("span", { style: { flex: 1, minWidth: 0 }, "aria-hidden": true })
    ),
    /* @__PURE__ */ import_react.default.createElement(
      "div",
      {
        className: `${prefixCls}-row-right`,
        style: (gaps == null ? void 0 : gaps.rowRight) !== void 0 ? { gap: gaps.rowRight } : void 0
      },
      /* @__PURE__ */ import_react.default.createElement(
        "span",
        {
          className: `${prefixCls}-row-value`,
          style: parentHasItemsCount ? { ...cfg == null ? void 0 : cfg.valueTextStyle, color: "#667085", fontWeight: 400 } : cfg == null ? void 0 : cfg.valueTextStyle
        },
        right
      ),
      item.extra ? /* @__PURE__ */ import_react.default.createElement("span", { className: `${prefixCls}-row-extra` }, item.extra) : null,
      canExpand ? /* @__PURE__ */ import_react.default.createElement(
        "span",
        {
          className: `${prefixCls}-row-expand-icon`,
          "aria-label": expanded ? "collapse" : "expand",
          style: (cfg == null ? void 0 : cfg.expandIconStyle) ? {
            width: cfg.expandIconStyle.width ?? cfg.expandIconStyle.size ?? 24,
            height: cfg.expandIconStyle.height ?? cfg.expandIconStyle.size ?? 24
          } : void 0
        },
        /* @__PURE__ */ import_react.default.createElement(
          import_icons.UpOutlined,
          {
            style: {
              transform: expanded ? "rotate(0deg)" : "rotate(180deg)",
              ...((_b = cfg == null ? void 0 : cfg.expandIconStyle) == null ? void 0 : _b.color) ? { color: cfg.expandIconStyle.color } : null,
              ...((_c = cfg == null ? void 0 : cfg.expandIconStyle) == null ? void 0 : _c.size) ? { fontSize: cfg.expandIconStyle.size } : null
            }
          }
        )
      ) : null
    )
  ), hasChildren && expanded ? /* @__PURE__ */ import_react.default.createElement(
    "div",
    {
      className: `${prefixCls}-children`,
      style: { paddingLeft: 0, marginTop: 8 }
    },
    hasExpandedContent ? item.expandedContent : children.map((child, childIndex) => /* @__PURE__ */ import_react.default.createElement(
      Row,
      {
        key: child.key ?? getKey(child, {
          level: level + 1,
          index: childIndex,
          parentPathKeys: pathKeys
        }),
        ...props,
        item: child,
        level: level + 1,
        index: childIndex,
        parentPathKeys: pathKeys,
        parentHasItemsCount: showItemsCount || parentHasItemsCount
      }
    ))
  ) : null);
});
Row.displayName = "PisellHierarchicalSummaryListRow";
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  Row
});
