import { c as clsx } from "./clsx-DgYk2OaC.js";
import * as React from "react";
import { forwardRef, useRef, useImperativeHandle, useState, useCallback, useEffect, useMemo, cloneElement } from "react";
import { g as getDefaultExportFromCjs } from "./_commonjsHelpers-DWwsNxpa.js";
var get$2 = {};
var isUnsafeProperty = {};
var hasRequiredIsUnsafeProperty;
function requireIsUnsafeProperty() {
  if (hasRequiredIsUnsafeProperty) return isUnsafeProperty;
  hasRequiredIsUnsafeProperty = 1;
  (function(exports) {
    Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
    function isUnsafeProperty2(key) {
      return key === "__proto__";
    }
    exports.isUnsafeProperty = isUnsafeProperty2;
  })(isUnsafeProperty);
  return isUnsafeProperty;
}
var isDeepKey = {};
var hasRequiredIsDeepKey;
function requireIsDeepKey() {
  if (hasRequiredIsDeepKey) return isDeepKey;
  hasRequiredIsDeepKey = 1;
  (function(exports) {
    Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
    function isDeepKey2(key) {
      switch (typeof key) {
        case "number":
        case "symbol": {
          return false;
        }
        case "string": {
          return key.includes(".") || key.includes("[") || key.includes("]");
        }
      }
    }
    exports.isDeepKey = isDeepKey2;
  })(isDeepKey);
  return isDeepKey;
}
var toKey = {};
var hasRequiredToKey;
function requireToKey() {
  if (hasRequiredToKey) return toKey;
  hasRequiredToKey = 1;
  (function(exports) {
    Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
    function toKey2(value) {
      if (typeof value === "string" || typeof value === "symbol") {
        return value;
      }
      if (Object.is(value?.valueOf?.(), -0)) {
        return "-0";
      }
      return String(value);
    }
    exports.toKey = toKey2;
  })(toKey);
  return toKey;
}
var toPath = {};
var hasRequiredToPath;
function requireToPath() {
  if (hasRequiredToPath) return toPath;
  hasRequiredToPath = 1;
  (function(exports) {
    Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
    function toPath2(deepKey) {
      const result = [];
      const length = deepKey.length;
      if (length === 0) {
        return result;
      }
      let index = 0;
      let key = "";
      let quoteChar = "";
      let bracket = false;
      if (deepKey.charCodeAt(0) === 46) {
        result.push("");
        index++;
      }
      while (index < length) {
        const char = deepKey[index];
        if (quoteChar) {
          if (char === "\\" && index + 1 < length) {
            index++;
            key += deepKey[index];
          } else if (char === quoteChar) {
            quoteChar = "";
          } else {
            key += char;
          }
        } else if (bracket) {
          if (char === '"' || char === "'") {
            quoteChar = char;
          } else if (char === "]") {
            bracket = false;
            result.push(key);
            key = "";
          } else {
            key += char;
          }
        } else {
          if (char === "[") {
            bracket = true;
            if (key) {
              result.push(key);
              key = "";
            }
          } else if (char === ".") {
            if (key) {
              result.push(key);
              key = "";
            }
          } else {
            key += char;
          }
        }
        index++;
      }
      if (key) {
        result.push(key);
      }
      return result;
    }
    exports.toPath = toPath2;
  })(toPath);
  return toPath;
}
var hasRequiredGet$1;
function requireGet$1() {
  if (hasRequiredGet$1) return get$2;
  hasRequiredGet$1 = 1;
  (function(exports) {
    Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
    const isUnsafeProperty2 = /* @__PURE__ */ requireIsUnsafeProperty();
    const isDeepKey2 = /* @__PURE__ */ requireIsDeepKey();
    const toKey2 = /* @__PURE__ */ requireToKey();
    const toPath2 = /* @__PURE__ */ requireToPath();
    function get2(object, path, defaultValue) {
      if (object == null) {
        return defaultValue;
      }
      switch (typeof path) {
        case "string": {
          if (isUnsafeProperty2.isUnsafeProperty(path)) {
            return defaultValue;
          }
          const result = object[path];
          if (result === void 0) {
            if (isDeepKey2.isDeepKey(path)) {
              return get2(object, toPath2.toPath(path), defaultValue);
            } else {
              return defaultValue;
            }
          }
          return result;
        }
        case "number":
        case "symbol": {
          if (typeof path === "number") {
            path = toKey2.toKey(path);
          }
          const result = object[path];
          if (result === void 0) {
            return defaultValue;
          }
          return result;
        }
        default: {
          if (Array.isArray(path)) {
            return getWithPath(object, path, defaultValue);
          }
          if (Object.is(path?.valueOf(), -0)) {
            path = "-0";
          } else {
            path = String(path);
          }
          if (isUnsafeProperty2.isUnsafeProperty(path)) {
            return defaultValue;
          }
          const result = object[path];
          if (result === void 0) {
            return defaultValue;
          }
          return result;
        }
      }
    }
    function getWithPath(object, path, defaultValue) {
      if (path.length === 0) {
        return defaultValue;
      }
      let current = object;
      for (let index = 0; index < path.length; index++) {
        if (current == null) {
          return defaultValue;
        }
        if (isUnsafeProperty2.isUnsafeProperty(path[index])) {
          return defaultValue;
        }
        current = current[path[index]];
      }
      if (current === void 0) {
        return defaultValue;
      }
      return current;
    }
    exports.get = get2;
  })(get$2);
  return get$2;
}
var get$1;
var hasRequiredGet;
function requireGet() {
  if (hasRequiredGet) return get$1;
  hasRequiredGet = 1;
  get$1 = requireGet$1().get;
  return get$1;
}
var getExports = /* @__PURE__ */ requireGet();
const get = /* @__PURE__ */ getDefaultExportFromCjs(getExports);
var mathSign = (value) => {
  if (value === 0) {
    return 0;
  }
  if (value > 0) {
    return 1;
  }
  return -1;
};
var isNan = (value) => {
  return typeof value == "number" && value != +value;
};
var isPercent = (value) => typeof value === "string" && value.indexOf("%") === value.length - 1;
var isNumber = (value) => (typeof value === "number" || value instanceof Number) && !isNan(value);
var isNumOrStr = (value) => isNumber(value) || typeof value === "string";
var idCounter = 0;
var uniqueId = (prefix) => {
  var id = ++idCounter;
  return "".concat(prefix || "").concat(id);
};
var getPercentValue = function getPercentValue2(percent, totalValue) {
  var defaultValue = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : 0;
  var validate = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : false;
  if (!isNumber(percent) && typeof percent !== "string") {
    return defaultValue;
  }
  var value;
  if (isPercent(percent)) {
    if (totalValue == null) {
      return defaultValue;
    }
    var index = percent.indexOf("%");
    value = totalValue * parseFloat(percent.slice(0, index)) / 100;
  } else {
    value = +percent;
  }
  if (isNan(value)) {
    value = defaultValue;
  }
  if (validate && totalValue != null && value > totalValue) {
    value = totalValue;
  }
  return value;
};
var hasDuplicate = (ary) => {
  if (!Array.isArray(ary)) {
    return false;
  }
  var len = ary.length;
  var cache = {};
  for (var i = 0; i < len; i++) {
    if (!cache[ary[i]]) {
      cache[ary[i]] = true;
    } else {
      return true;
    }
  }
  return false;
};
var interpolateNumber = (numberA, numberB) => {
  if (isNumber(numberA) && isNumber(numberB)) {
    return (t) => numberA + t * (numberB - numberA);
  }
  return () => numberB;
};
function interpolate(start, end, t) {
  if (isNumber(start) && isNumber(end)) {
    return start + t * (end - start);
  }
  return end;
}
function findEntryInArray(ary, specifiedKey, specifiedValue) {
  if (!ary || !ary.length) {
    return void 0;
  }
  return ary.find((entry) => entry && (typeof specifiedKey === "function" ? specifiedKey(entry) : get(entry, specifiedKey)) === specifiedValue);
}
var getLinearRegression = (data) => {
  if (!data || !data.length) {
    return null;
  }
  var len = data.length;
  var xsum = 0;
  var ysum = 0;
  var xysum = 0;
  var xxsum = 0;
  var xmin = Infinity;
  var xmax = -Infinity;
  var xcurrent = 0;
  var ycurrent = 0;
  for (var i = 0; i < len; i++) {
    xcurrent = data[i].cx || 0;
    ycurrent = data[i].cy || 0;
    xsum += xcurrent;
    ysum += ycurrent;
    xysum += xcurrent * ycurrent;
    xxsum += xcurrent * xcurrent;
    xmin = Math.min(xmin, xcurrent);
    xmax = Math.max(xmax, xcurrent);
  }
  var a = len * xxsum !== xsum * xsum ? (len * xysum - xsum * ysum) / (len * xxsum - xsum * xsum) : 0;
  return {
    xmin,
    xmax,
    a,
    b: (ysum - a * xsum) / len
  };
};
var isNullish = (value) => {
  return value === null || typeof value === "undefined";
};
var upperFirst = (value) => {
  if (isNullish(value)) {
    return value;
  }
  return "".concat(value.charAt(0).toUpperCase()).concat(value.slice(1));
};
var throttle$2 = {};
var debounce$1 = {};
var debounce = {};
var hasRequiredDebounce$1;
function requireDebounce$1() {
  if (hasRequiredDebounce$1) return debounce;
  hasRequiredDebounce$1 = 1;
  (function(exports) {
    Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
    function debounce2(func, debounceMs, { signal, edges } = {}) {
      let pendingThis = void 0;
      let pendingArgs = null;
      const leading = edges != null && edges.includes("leading");
      const trailing = edges == null || edges.includes("trailing");
      const invoke = () => {
        if (pendingArgs !== null) {
          func.apply(pendingThis, pendingArgs);
          pendingThis = void 0;
          pendingArgs = null;
        }
      };
      const onTimerEnd = () => {
        if (trailing) {
          invoke();
        }
        cancel();
      };
      let timeoutId = null;
      const schedule = () => {
        if (timeoutId != null) {
          clearTimeout(timeoutId);
        }
        timeoutId = setTimeout(() => {
          timeoutId = null;
          onTimerEnd();
        }, debounceMs);
      };
      const cancelTimer = () => {
        if (timeoutId !== null) {
          clearTimeout(timeoutId);
          timeoutId = null;
        }
      };
      const cancel = () => {
        cancelTimer();
        pendingThis = void 0;
        pendingArgs = null;
      };
      const flush = () => {
        invoke();
      };
      const debounced = function(...args) {
        if (signal?.aborted) {
          return;
        }
        pendingThis = this;
        pendingArgs = args;
        const isFirstCall = timeoutId == null;
        schedule();
        if (leading && isFirstCall) {
          invoke();
        }
      };
      debounced.schedule = schedule;
      debounced.cancel = cancel;
      debounced.flush = flush;
      signal?.addEventListener("abort", cancel, { once: true });
      return debounced;
    }
    exports.debounce = debounce2;
  })(debounce);
  return debounce;
}
var hasRequiredDebounce;
function requireDebounce() {
  if (hasRequiredDebounce) return debounce$1;
  hasRequiredDebounce = 1;
  (function(exports) {
    Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
    const debounce$12 = /* @__PURE__ */ requireDebounce$1();
    function debounce2(func, debounceMs = 0, options = {}) {
      if (typeof options !== "object") {
        options = {};
      }
      const { leading = false, trailing = true, maxWait } = options;
      const edges = Array(2);
      if (leading) {
        edges[0] = "leading";
      }
      if (trailing) {
        edges[1] = "trailing";
      }
      let result = void 0;
      let pendingAt = null;
      const _debounced = debounce$12.debounce(function(...args) {
        result = func.apply(this, args);
        pendingAt = null;
      }, debounceMs, { edges });
      const debounced = function(...args) {
        if (maxWait != null) {
          if (pendingAt === null) {
            pendingAt = Date.now();
          }
          if (Date.now() - pendingAt >= maxWait) {
            result = func.apply(this, args);
            pendingAt = Date.now();
            _debounced.cancel();
            _debounced.schedule();
            return result;
          }
        }
        _debounced.apply(this, args);
        return result;
      };
      const flush = () => {
        _debounced.flush();
        return result;
      };
      debounced.cancel = _debounced.cancel;
      debounced.flush = flush;
      return debounced;
    }
    exports.debounce = debounce2;
  })(debounce$1);
  return debounce$1;
}
var hasRequiredThrottle$1;
function requireThrottle$1() {
  if (hasRequiredThrottle$1) return throttle$2;
  hasRequiredThrottle$1 = 1;
  (function(exports) {
    Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
    const debounce2 = /* @__PURE__ */ requireDebounce();
    function throttle2(func, throttleMs = 0, options = {}) {
      const { leading = true, trailing = true } = options;
      return debounce2.debounce(func, throttleMs, {
        leading,
        maxWait: throttleMs,
        trailing
      });
    }
    exports.throttle = throttle2;
  })(throttle$2);
  return throttle$2;
}
var throttle$1;
var hasRequiredThrottle;
function requireThrottle() {
  if (hasRequiredThrottle) return throttle$1;
  hasRequiredThrottle = 1;
  throttle$1 = requireThrottle$1().throttle;
  return throttle$1;
}
var throttleExports = /* @__PURE__ */ requireThrottle();
const throttle = /* @__PURE__ */ getDefaultExportFromCjs(throttleExports);
var isDev = process.env.NODE_ENV !== "production";
var warn = function warn2(condition, format) {
  for (var _len = arguments.length, args = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) {
    args[_key - 2] = arguments[_key];
  }
  if (isDev && typeof console !== "undefined" && console.warn) {
    if (format === void 0) {
      console.warn("LogUtils requires an error message argument");
    }
    if (!condition) {
      if (format === void 0) {
        console.warn("Minified exception occurred; use the non-minified dev environment for the full error message and additional helpful warnings.");
      } else {
        var argIndex = 0;
        console.warn(format.replace(/%s/g, () => args[argIndex++]));
      }
    }
  }
};
function ownKeys(e, r) {
  var t = Object.keys(e);
  if (Object.getOwnPropertySymbols) {
    var o = Object.getOwnPropertySymbols(e);
    r && (o = o.filter(function(r2) {
      return Object.getOwnPropertyDescriptor(e, r2).enumerable;
    })), t.push.apply(t, o);
  }
  return t;
}
function _objectSpread(e) {
  for (var r = 1; r < arguments.length; r++) {
    var t = null != arguments[r] ? arguments[r] : {};
    r % 2 ? ownKeys(Object(t), true).forEach(function(r2) {
      _defineProperty(e, r2, t[r2]);
    }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function(r2) {
      Object.defineProperty(e, r2, Object.getOwnPropertyDescriptor(t, r2));
    });
  }
  return e;
}
function _defineProperty(e, r, t) {
  return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: true, configurable: true, writable: true }) : e[r] = t, e;
}
function _toPropertyKey(t) {
  var i = _toPrimitive(t, "string");
  return "symbol" == typeof i ? i : i + "";
}
function _toPrimitive(t, r) {
  if ("object" != typeof t || !t) return t;
  var e = t[Symbol.toPrimitive];
  if (void 0 !== e) {
    var i = e.call(t, r);
    if ("object" != typeof i) return i;
    throw new TypeError("@@toPrimitive must return a primitive value.");
  }
  return ("string" === r ? String : Number)(t);
}
var ResponsiveContainer = /* @__PURE__ */ forwardRef((_ref, ref) => {
  var {
    aspect,
    initialDimension = {
      width: -1,
      height: -1
    },
    width = "100%",
    height = "100%",
    /*
     * default min-width to 0 if not specified - 'auto' causes issues with flexbox
     * https://github.com/recharts/recharts/issues/172
     */
    minWidth = 0,
    minHeight,
    maxHeight,
    children,
    debounce: debounce2 = 0,
    id,
    className,
    onResize,
    style = {}
  } = _ref;
  var containerRef = useRef(null);
  var onResizeRef = useRef();
  onResizeRef.current = onResize;
  useImperativeHandle(ref, () => containerRef.current);
  var [sizes, setSizes] = useState({
    containerWidth: initialDimension.width,
    containerHeight: initialDimension.height
  });
  var setContainerSize = useCallback((newWidth, newHeight) => {
    setSizes((prevState) => {
      var roundedWidth = Math.round(newWidth);
      var roundedHeight = Math.round(newHeight);
      if (prevState.containerWidth === roundedWidth && prevState.containerHeight === roundedHeight) {
        return prevState;
      }
      return {
        containerWidth: roundedWidth,
        containerHeight: roundedHeight
      };
    });
  }, []);
  useEffect(() => {
    var callback = (entries) => {
      var _onResizeRef$current;
      var {
        width: containerWidth2,
        height: containerHeight2
      } = entries[0].contentRect;
      setContainerSize(containerWidth2, containerHeight2);
      (_onResizeRef$current = onResizeRef.current) === null || _onResizeRef$current === void 0 || _onResizeRef$current.call(onResizeRef, containerWidth2, containerHeight2);
    };
    if (debounce2 > 0) {
      callback = throttle(callback, debounce2, {
        trailing: true,
        leading: false
      });
    }
    var observer = new ResizeObserver(callback);
    var {
      width: containerWidth,
      height: containerHeight
    } = containerRef.current.getBoundingClientRect();
    setContainerSize(containerWidth, containerHeight);
    observer.observe(containerRef.current);
    return () => {
      observer.disconnect();
    };
  }, [setContainerSize, debounce2]);
  var chartContent = useMemo(() => {
    var {
      containerWidth,
      containerHeight
    } = sizes;
    if (containerWidth < 0 || containerHeight < 0) {
      return null;
    }
    warn(isPercent(width) || isPercent(height), "The width(%s) and height(%s) are both fixed numbers,\n       maybe you don't need to use a ResponsiveContainer.", width, height);
    warn(!aspect || aspect > 0, "The aspect(%s) must be greater than zero.", aspect);
    var calculatedWidth = isPercent(width) ? containerWidth : width;
    var calculatedHeight = isPercent(height) ? containerHeight : height;
    if (aspect && aspect > 0) {
      if (calculatedWidth) {
        calculatedHeight = calculatedWidth / aspect;
      } else if (calculatedHeight) {
        calculatedWidth = calculatedHeight * aspect;
      }
      if (maxHeight && calculatedHeight > maxHeight) {
        calculatedHeight = maxHeight;
      }
    }
    warn(calculatedWidth > 0 || calculatedHeight > 0, "The width(%s) and height(%s) of chart should be greater than 0,\n       please check the style of container, or the props width(%s) and height(%s),\n       or add a minWidth(%s) or minHeight(%s) or use aspect(%s) to control the\n       height and width.", calculatedWidth, calculatedHeight, width, height, minWidth, minHeight, aspect);
    return React.Children.map(children, (child) => {
      return /* @__PURE__ */ cloneElement(child, {
        width: calculatedWidth,
        height: calculatedHeight,
        // calculate the actual size and override it.
        style: _objectSpread({
          width: calculatedWidth,
          height: calculatedHeight
        }, child.props.style)
      });
    });
  }, [aspect, children, height, maxHeight, minHeight, minWidth, sizes, width]);
  return /* @__PURE__ */ React.createElement("div", {
    id: id ? "".concat(id) : void 0,
    className: clsx("recharts-responsive-container", className),
    style: _objectSpread(_objectSpread({}, style), {}, {
      width,
      height,
      minWidth,
      minHeight,
      maxHeight
    }),
    ref: containerRef
  }, /* @__PURE__ */ React.createElement("div", {
    style: {
      width: 0,
      height: 0,
      overflow: "visible"
    }
  }, chartContent));
});
export {
  ResponsiveContainer as R,
  isNumber as a,
  interpolate as b,
  isNan as c,
  getPercentValue as d,
  interpolateNumber as e,
  requireToPath as f,
  get as g,
  requireIsUnsafeProperty as h,
  isNullish as i,
  requireToKey as j,
  requireGet$1 as k,
  getLinearRegression as l,
  mathSign as m,
  upperFirst as n,
  isNumOrStr as o,
  isPercent as p,
  findEntryInArray as q,
  requireIsDeepKey as r,
  hasDuplicate as s,
  uniqueId as u,
  warn as w
};
