"use client";
import d from "../../../../_virtual/sortBy.js";
import b from "../../../../_virtual/get.js";
import { isNullish as l, isNumOrStr as P, isNumber as p, isNan as y } from "./DataUtils.js";
import { getSliced as w } from "./getSliced.js";
import M from "../../../d3-shape/src/stack.js";
import S from "../../../d3-shape/src/order/none.js";
import E from "../../../d3-shape/src/offset/wiggle.js";
import D from "../../../d3-shape/src/offset/silhouette.js";
import _ from "../../../d3-shape/src/offset/none.js";
import k from "../../../d3-shape/src/offset/expand.js";
function g(r, t) {
  var n = Object.keys(r);
  if (Object.getOwnPropertySymbols) {
    var a = Object.getOwnPropertySymbols(r);
    t && (a = a.filter(function(f) {
      return Object.getOwnPropertyDescriptor(r, f).enumerable;
    })), n.push.apply(n, a);
  }
  return n;
}
function u(r) {
  for (var t = 1; t < arguments.length; t++) {
    var n = arguments[t] != null ? arguments[t] : {};
    t % 2 ? g(Object(n), !0).forEach(function(a) {
      x(r, a, n[a]);
    }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(r, Object.getOwnPropertyDescriptors(n)) : g(Object(n)).forEach(function(a) {
      Object.defineProperty(r, a, Object.getOwnPropertyDescriptor(n, a));
    });
  }
  return r;
}
function x(r, t, n) {
  return (t = I(t)) in r ? Object.defineProperty(r, t, { value: n, enumerable: !0, configurable: !0, writable: !0 }) : r[t] = n, r;
}
function I(r) {
  var t = A(r, "string");
  return typeof t == "symbol" ? t : t + "";
}
function A(r, t) {
  if (typeof r != "object" || !r) return r;
  var n = r[Symbol.toPrimitive];
  if (n !== void 0) {
    var a = n.call(r, t);
    if (typeof a != "object") return a;
    throw new TypeError("@@toPrimitive must return a primitive value.");
  }
  return (t === "string" ? String : Number)(r);
}
function N(r, t, n) {
  return l(r) || l(t) ? n : P(t) ? b(r, t, n) : typeof t == "function" ? t(r) : n;
}
var H = (r, t, n) => {
  if (t && n) {
    var {
      width: a,
      height: f
    } = n, {
      align: e,
      verticalAlign: o,
      layout: i
    } = t;
    if ((i === "vertical" || i === "horizontal" && o === "middle") && e !== "center" && p(r[e]))
      return u(u({}, r), {}, {
        [e]: r[e] + (a || 0)
      });
    if ((i === "horizontal" || i === "vertical" && e === "center") && o !== "middle" && p(r[o]))
      return u(u({}, r), {}, {
        [o]: r[o] + (f || 0)
      });
  }
  return r;
}, J = (r, t) => r === "horizontal" && t === "xAxis" || r === "vertical" && t === "yAxis" || r === "centric" && t === "angleAxis" || r === "radial" && t === "radiusAxis", O = 1e-4, Q = (r) => {
  var t = r.domain();
  if (!(!t || t.length <= 2)) {
    var n = t.length, a = r.range(), f = Math.min(a[0], a[1]) - O, e = Math.max(a[0], a[1]) + O, o = r(t[0]), i = r(t[n - 1]);
    (o < f || o > e || i < f || i > e) && r.domain([t[0], t[n - 1]]);
  }
}, s = (r) => {
  var t = r.length;
  if (!(t <= 0))
    for (var n = 0, a = r[0].length; n < a; ++n)
      for (var f = 0, e = 0, o = 0; o < t; ++o) {
        var i = y(r[o][n][1]) ? r[o][n][0] : r[o][n][1];
        i >= 0 ? (r[o][n][0] = f, r[o][n][1] = f + i, f = r[o][n][1]) : (r[o][n][0] = e, r[o][n][1] = e + i, e = r[o][n][1]);
      }
}, B = (r) => {
  var t = r.length;
  if (!(t <= 0))
    for (var n = 0, a = r[0].length; n < a; ++n)
      for (var f = 0, e = 0; e < t; ++e) {
        var o = y(r[e][n][1]) ? r[e][n][0] : r[e][n][1];
        o >= 0 ? (r[e][n][0] = f, r[e][n][1] = f + o, f = r[e][n][1]) : (r[e][n][0] = 0, r[e][n][1] = 0);
      }
}, F = {
  sign: s,
  // @ts-expect-error definitelytyped types are incorrect
  expand: k,
  // @ts-expect-error definitelytyped types are incorrect
  none: _,
  // @ts-expect-error definitelytyped types are incorrect
  silhouette: D,
  // @ts-expect-error definitelytyped types are incorrect
  wiggle: E,
  positive: B
}, Y = (r, t, n) => {
  var a = F[n], f = M().keys(t).value((e, o) => +N(e, o, 0)).order(S).offset(a);
  return f(r);
}, L = (r) => {
  var t = r.flat(2).filter(p);
  return [Math.min(...t), Math.max(...t)];
}, V = (r) => [r[0] === 1 / 0 ? 0 : r[0], r[1] === -1 / 0 ? 0 : r[1]], Z = (r, t, n) => {
  if (r != null)
    return V(Object.keys(r).reduce((a, f) => {
      var e = r[f], {
        stackedData: o
      } = e, i = o.reduce((m, v) => {
        var c = w(v, t, n), h = L(c);
        return [Math.min(m[0], h[0]), Math.max(m[1], h[1])];
      }, [1 / 0, -1 / 0]);
      return [Math.min(i[0], a[0]), Math.max(i[1], a[1])];
    }, [1 / 0, -1 / 0]));
}, T = /^dataMin[\s]*-[\s]*([0-9]+([.]{1}[0-9]+){0,1})$/, j = /^dataMax[\s]*\+[\s]*([0-9]+([.]{1}[0-9]+){0,1})$/, rr = (r, t, n) => {
  if (r && r.scale && r.scale.bandwidth) {
    var a = r.scale.bandwidth();
    return a;
  }
  if (r && t && t.length >= 2) {
    for (var f = d(t, (c) => c.coordinate), e = 1 / 0, o = 1, i = f.length; o < i; o++) {
      var m = f[o], v = f[o - 1];
      e = Math.min((m.coordinate || 0) - (v.coordinate || 0), e);
    }
    return e === 1 / 0 ? 0 : e;
  }
  return 0;
};
function tr(r) {
  var {
    tooltipEntrySettings: t,
    dataKey: n,
    payload: a,
    value: f,
    name: e
  } = r;
  return u(u({}, t), {}, {
    dataKey: n,
    payload: a,
    value: f,
    name: e
  });
}
export {
  j as MAX_VALUE_REG,
  T as MIN_VALUE_REG,
  H as appendOffsetOfLegend,
  Q as checkDomainOfScale,
  rr as getBandSizeOfAxis,
  Z as getDomainOfStackGroups,
  Y as getStackedData,
  tr as getTooltipEntry,
  N as getValueByDataKey,
  J as isCategoricalAxis,
  B as offsetPositive,
  s as offsetSign
};
