import { toThousand as x, toFixed as b, addNumber as C } from "@aplus-frontend/utils";
import { flatten as f, uniqBy as L, isNil as N, get as s, set as T } from "lodash-unified";
const m = (t) => t?.children && t?.children?.length > 0 ? f(t.children?.map((e) => m(e))) : [t], j = (t) => f(
  t?.map((e) => m(e))
), l = (t) => Object.prototype.toString.call(t) === "[object Array]" ? t.map((e) => String(e)).join(".") : t ?? "", S = (t, e, u) => u ? x(t, e) : b(t, e);
function q(t) {
  const { records: e, columns: u, configList: c, exclude: a, valueTypeExtension: y } = t;
  if (!e || e?.length === 0)
    return {};
  let r = j(u)?.filter(
    (n) => n.valueType === "number" || // 兼容自定义valueType的情况
    y?.includes(n.valueType)
  )?.map((n) => ({
    key: n.key || "",
    dataIndex: n.dataIndex
  }));
  c && c?.length > 0 && (r = L(r?.concat(c), "key")), a && a.length > 0 && (r = r.filter(
    (n) => !a.includes(n.key)
  ));
  const p = {};
  return e?.reduce((n, d) => (r.forEach((o) => {
    if (!N(s(d, l(o.dataIndex || o.key)))) {
      const i = o.dataIndex || o.key, g = s(n, l(i)) || 0, h = s(d, l(i)) || 0, k = C(g, h)?.toNumber();
      T(n, i, +k);
    }
  }), n), p);
}
export {
  q as computedRecords,
  j as flattenColumns,
  l as formatDataIndex,
  S as formatNumber
};
