import { jsx, jsxs } from "react/jsx-runtime";
import { cn } from "../utils/cn.js";
import { getChartMargin, defaultGridProps, defaultLegendProps, getDefaultChartColor } from "./chart-utils.js";
import { i as isNullish, e as interpolateNumber, l as getLinearRegression, R as ResponsiveContainer } from "../../ResponsiveContainer-by1DMaUt.js";
import * as React from "react";
import { Component, useEffect, useMemo, useRef, useState, useCallback, forwardRef } from "react";
import { aE as implicitZAxis, d as useAppDispatch, aF as addZAxis, aG as removeZAxis, m as createSelector, q as selectChartDataWithIndexesIfNotInPanorama, o as selectAxisWithScale, p as selectTicksOfGraphicalItem, aH as selectZAxisWithScale, y as selectUnfilteredCartesianItems, r as resolveDefaultProps, h as useIsPanorama, A as getTooltipNameProp, ae as findAllByType, u as useAppSelector, S as SetTooltipEntrySettings, G as Global, L as Layer, E as getValueByDataKey, F as getCateCoordinateOfLine, l as selectActiveTooltipIndex, k as svgPropertiesNoEvents, at as DATA_ITEM_DATAKEY_ATTRIBUTE_NAME, au as DATA_ITEM_INDEX_ATTRIBUTE_NAME, ai as adaptEventsOfChild, f as filterProps, H as Curve, J as arrayTooltipSearcher, T as Tooltip } from "../../RechartsWrapper-B6DckFGn.js";
import { C as CartesianChart } from "../../CartesianChart-6PlEqMR8.js";
import { C as CartesianGrid, X as XAxis, Y as YAxis } from "../../YAxis-DXrEaAmy.js";
import { S as Symbols, J as JavascriptAnimate, L as Legend } from "../../CategoricalChart-B4Tr_94h.js";
import { c as clsx } from "../../clsx-DgYk2OaC.js";
import { L as LabelList } from "../../LabelList-DRKy5CtG.js";
import { S as Shape, C as Cell, u as useMouseEnterItemDispatch, a as useMouseLeaveItemDispatch, b as useMouseClickItemDispatch } from "../../tooltipContext-DXoEe1YL.js";
import { S as SetErrorBarContext } from "../../ErrorBarContext-qjBcIXik.js";
import { u as useNeedsClip, G as GraphicalItemClipPath } from "../../GraphicalItemClipPath-CPP-wn97.js";
import { R as RegisterGraphicalItemId, S as SetLegendPayload, a as SetCartesianGraphicalItem, u as useAnimationId } from "../../SetGraphicalItem-88i2L04q.js";
function _defineProperty$1(e, r, t) {
  return (r = _toPropertyKey$1(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: true, configurable: true, writable: true }) : e[r] = t, e;
}
function _toPropertyKey$1(t) {
  var i = _toPrimitive$1(t, "string");
  return "symbol" == typeof i ? i : i + "";
}
function _toPrimitive$1(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);
}
function SetZAxisSettings(settings) {
  var dispatch = useAppDispatch();
  useEffect(() => {
    dispatch(addZAxis(settings));
    return () => {
      dispatch(removeZAxis(settings));
    };
  }, [settings, dispatch]);
  return null;
}
class ZAxis extends Component {
  render() {
    return /* @__PURE__ */ React.createElement(SetZAxisSettings, {
      domain: this.props.domain,
      id: this.props.zAxisId,
      dataKey: this.props.dataKey,
      name: this.props.name,
      unit: this.props.unit,
      range: this.props.range,
      scale: this.props.scale,
      type: this.props.type,
      allowDuplicatedCategory: implicitZAxis.allowDuplicatedCategory,
      allowDataOverflow: implicitZAxis.allowDataOverflow,
      reversed: implicitZAxis.reversed,
      includeHidden: implicitZAxis.includeHidden
    });
  }
}
_defineProperty$1(ZAxis, "displayName", "ZAxis");
_defineProperty$1(ZAxis, "defaultProps", {
  zAxisId: 0,
  range: implicitZAxis.range,
  scale: implicitZAxis.scale,
  type: implicitZAxis.type
});
var _excluded$1 = ["option", "isActive"];
function _extends$1() {
  return _extends$1 = Object.assign ? Object.assign.bind() : function(n) {
    for (var e = 1; e < arguments.length; e++) {
      var t = arguments[e];
      for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]);
    }
    return n;
  }, _extends$1.apply(null, arguments);
}
function _objectWithoutProperties$1(e, t) {
  if (null == e) return {};
  var o, r, i = _objectWithoutPropertiesLoose$1(e, t);
  if (Object.getOwnPropertySymbols) {
    var n = Object.getOwnPropertySymbols(e);
    for (r = 0; r < n.length; r++) o = n[r], -1 === t.indexOf(o) && {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]);
  }
  return i;
}
function _objectWithoutPropertiesLoose$1(r, e) {
  if (null == r) return {};
  var t = {};
  for (var n in r) if ({}.hasOwnProperty.call(r, n)) {
    if (-1 !== e.indexOf(n)) continue;
    t[n] = r[n];
  }
  return t;
}
function ScatterSymbol(_ref) {
  var {
    option,
    isActive
  } = _ref, props = _objectWithoutProperties$1(_ref, _excluded$1);
  if (typeof option === "string") {
    return /* @__PURE__ */ React.createElement(Shape, _extends$1({
      option: /* @__PURE__ */ React.createElement(Symbols, _extends$1({
        type: option
      }, props)),
      isActive,
      shapeType: "symbols"
    }, props));
  }
  return /* @__PURE__ */ React.createElement(Shape, _extends$1({
    option,
    isActive,
    shapeType: "symbols"
  }, props));
}
var selectXAxisWithScale = (state, xAxisId, _yAxisId, _zAxisId, _id, _cells, isPanorama) => selectAxisWithScale(state, "xAxis", xAxisId, isPanorama);
var selectXAxisTicks = (state, xAxisId, _yAxisId, _zAxisId, _id, _cells, isPanorama) => selectTicksOfGraphicalItem(state, "xAxis", xAxisId, isPanorama);
var selectYAxisWithScale = (state, _xAxisId, yAxisId, _zAxisId, _id, _cells, isPanorama) => selectAxisWithScale(state, "yAxis", yAxisId, isPanorama);
var selectYAxisTicks = (state, _xAxisId, yAxisId, _zAxisId, _id, _cells, isPanorama) => selectTicksOfGraphicalItem(state, "yAxis", yAxisId, isPanorama);
var selectZAxis = (state, _xAxisId, _yAxisId, zAxisId) => selectZAxisWithScale(state, "zAxis", zAxisId, false);
var pickScatterId = (_state, _xAxisId, _yAxisId, _zAxisId, id) => id;
var pickCells = (_state, _xAxisId, _yAxisId, _zAxisId, _id, cells) => cells;
var scatterChartDataSelector = (state, xAxisId, yAxisId, _zAxisId, _id, _cells, isPanorama) => selectChartDataWithIndexesIfNotInPanorama(state, xAxisId, yAxisId, isPanorama);
var selectSynchronisedScatterSettings = createSelector([selectUnfilteredCartesianItems, pickScatterId], (graphicalItems, id) => {
  return graphicalItems.filter((item) => item.type === "scatter").find((item) => item.id === id);
});
var selectScatterPoints = createSelector([scatterChartDataSelector, selectXAxisWithScale, selectXAxisTicks, selectYAxisWithScale, selectYAxisTicks, selectZAxis, selectSynchronisedScatterSettings, pickCells], (_ref, xAxis, xAxisTicks, yAxis, yAxisTicks, zAxis, scatterSettings, cells) => {
  var {
    chartData,
    dataStartIndex,
    dataEndIndex
  } = _ref;
  if (scatterSettings == null) {
    return void 0;
  }
  var displayedData;
  if ((scatterSettings === null || scatterSettings === void 0 ? void 0 : scatterSettings.data) != null && scatterSettings.data.length > 0) {
    displayedData = scatterSettings.data;
  } else {
    displayedData = chartData === null || chartData === void 0 ? void 0 : chartData.slice(dataStartIndex, dataEndIndex + 1);
  }
  if (displayedData == null || xAxis == null || yAxis == null || xAxisTicks == null || yAxisTicks == null || (xAxisTicks === null || xAxisTicks === void 0 ? void 0 : xAxisTicks.length) === 0 || (yAxisTicks === null || yAxisTicks === void 0 ? void 0 : yAxisTicks.length) === 0) {
    return void 0;
  }
  return computeScatterPoints({
    displayedData,
    xAxis,
    yAxis,
    zAxis,
    scatterSettings,
    xAxisTicks,
    yAxisTicks,
    cells
  });
});
var _excluded = ["onMouseEnter", "onClick", "onMouseLeave"], _excluded2 = ["id"], _excluded3 = ["animationBegin", "animationDuration", "animationEasing", "hide", "isAnimationActive", "legendType", "lineJointType", "lineType", "shape", "xAxisId", "yAxisId", "zAxisId"];
function _objectWithoutProperties(e, t) {
  if (null == e) return {};
  var o, r, i = _objectWithoutPropertiesLoose(e, t);
  if (Object.getOwnPropertySymbols) {
    var n = Object.getOwnPropertySymbols(e);
    for (r = 0; r < n.length; r++) o = n[r], -1 === t.indexOf(o) && {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]);
  }
  return i;
}
function _objectWithoutPropertiesLoose(r, e) {
  if (null == r) return {};
  var t = {};
  for (var n in r) if ({}.hasOwnProperty.call(r, n)) {
    if (-1 !== e.indexOf(n)) continue;
    t[n] = r[n];
  }
  return t;
}
function _extends() {
  return _extends = Object.assign ? Object.assign.bind() : function(n) {
    for (var e = 1; e < arguments.length; e++) {
      var t = arguments[e];
      for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]);
    }
    return n;
  }, _extends.apply(null, arguments);
}
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 computeLegendPayloadFromScatterProps = (props) => {
  var {
    dataKey,
    name,
    fill,
    legendType,
    hide
  } = props;
  return [{
    inactive: hide,
    dataKey,
    type: legendType,
    color: fill,
    value: getTooltipNameProp(name, dataKey),
    payload: props
  }];
};
function ScatterLine(_ref) {
  var {
    points,
    props
  } = _ref;
  var {
    line,
    lineType,
    lineJointType
  } = props;
  if (!line) {
    return null;
  }
  var scatterProps = svgPropertiesNoEvents(props);
  var customLineProps = filterProps(line, false);
  var linePoints, lineItem;
  if (lineType === "joint") {
    linePoints = points.map((entry) => ({
      x: entry.cx,
      y: entry.cy
    }));
  } else if (lineType === "fitting") {
    var {
      xmin,
      xmax,
      a,
      b
    } = getLinearRegression(points);
    var linearExp = (x) => a * x + b;
    linePoints = [{
      x: xmin,
      y: linearExp(xmin)
    }, {
      x: xmax,
      y: linearExp(xmax)
    }];
  }
  var lineProps = _objectSpread(_objectSpread(_objectSpread({}, scatterProps), {}, {
    fill: "none",
    stroke: scatterProps && scatterProps.fill
  }, customLineProps), {}, {
    points: linePoints
  });
  if (/* @__PURE__ */ React.isValidElement(line)) {
    lineItem = /* @__PURE__ */ React.cloneElement(line, lineProps);
  } else if (typeof line === "function") {
    lineItem = line(lineProps);
  } else {
    lineItem = /* @__PURE__ */ React.createElement(Curve, _extends({}, lineProps, {
      type: lineJointType
    }));
  }
  return /* @__PURE__ */ React.createElement(Layer, {
    className: "recharts-scatter-line",
    key: "recharts-scatter-line"
  }, lineItem);
}
function ScatterSymbols(props) {
  var {
    points,
    showLabels,
    allOtherScatterProps
  } = props;
  var {
    shape,
    activeShape,
    dataKey
  } = allOtherScatterProps;
  var activeIndex = useAppSelector(selectActiveTooltipIndex);
  var {
    onMouseEnter: onMouseEnterFromProps,
    onClick: onItemClickFromProps,
    onMouseLeave: onMouseLeaveFromProps
  } = allOtherScatterProps, restOfAllOtherProps = _objectWithoutProperties(allOtherScatterProps, _excluded);
  var onMouseEnterFromContext = useMouseEnterItemDispatch(onMouseEnterFromProps, allOtherScatterProps.dataKey);
  var onMouseLeaveFromContext = useMouseLeaveItemDispatch(onMouseLeaveFromProps);
  var onClickFromContext = useMouseClickItemDispatch(onItemClickFromProps, allOtherScatterProps.dataKey);
  if (points == null) {
    return null;
  }
  var {
    id
  } = allOtherScatterProps, allOtherPropsWithoutId = _objectWithoutProperties(allOtherScatterProps, _excluded2);
  var baseProps = svgPropertiesNoEvents(allOtherPropsWithoutId);
  return /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(ScatterLine, {
    points,
    props: allOtherPropsWithoutId
  }), points.map((entry, i) => {
    var isActive = activeShape && activeIndex === String(i);
    var option = isActive ? activeShape : shape;
    var symbolProps = _objectSpread(_objectSpread(_objectSpread({
      key: "symbol-".concat(i)
    }, baseProps), entry), {}, {
      [DATA_ITEM_INDEX_ATTRIBUTE_NAME]: i,
      [DATA_ITEM_DATAKEY_ATTRIBUTE_NAME]: String(dataKey)
    });
    return /* @__PURE__ */ React.createElement(Layer, _extends({
      className: "recharts-scatter-symbol"
    }, adaptEventsOfChild(restOfAllOtherProps, entry, i), {
      // @ts-expect-error the types need a bit of attention
      onMouseEnter: onMouseEnterFromContext(entry, i),
      onMouseLeave: onMouseLeaveFromContext(entry, i),
      onClick: onClickFromContext(entry, i),
      key: "symbol-".concat(entry === null || entry === void 0 ? void 0 : entry.cx, "-").concat(entry === null || entry === void 0 ? void 0 : entry.cy, "-").concat(entry === null || entry === void 0 ? void 0 : entry.size, "-").concat(i)
    }), /* @__PURE__ */ React.createElement(ScatterSymbol, _extends({
      option,
      isActive
    }, symbolProps)));
  }), showLabels && LabelList.renderCallByParent(allOtherPropsWithoutId, points));
}
function SymbolsWithAnimation(_ref2) {
  var {
    previousPointsRef,
    props
  } = _ref2;
  var {
    points,
    isAnimationActive,
    animationBegin,
    animationDuration,
    animationEasing
  } = props;
  var prevPoints = previousPointsRef.current;
  var animationId = useAnimationId(props, "recharts-scatter-");
  var [isAnimating, setIsAnimating] = useState(false);
  var handleAnimationEnd = useCallback(() => {
    setIsAnimating(false);
  }, []);
  var handleAnimationStart = useCallback(() => {
    setIsAnimating(true);
  }, []);
  return /* @__PURE__ */ React.createElement(JavascriptAnimate, {
    begin: animationBegin,
    duration: animationDuration,
    isActive: isAnimationActive,
    easing: animationEasing,
    onAnimationEnd: handleAnimationEnd,
    onAnimationStart: handleAnimationStart,
    key: animationId
  }, (t) => {
    var stepData = t === 1 ? points : points.map((entry, index) => {
      var prev = prevPoints && prevPoints[index];
      if (prev) {
        var interpolatorCx = interpolateNumber(prev.cx, entry.cx);
        var interpolatorCy = interpolateNumber(prev.cy, entry.cy);
        var interpolatorSize = interpolateNumber(prev.size, entry.size);
        return _objectSpread(_objectSpread({}, entry), {}, {
          cx: interpolatorCx(t),
          cy: interpolatorCy(t),
          size: interpolatorSize(t)
        });
      }
      var interpolator = interpolateNumber(0, entry.size);
      return _objectSpread(_objectSpread({}, entry), {}, {
        size: interpolator(t)
      });
    });
    if (t > 0) {
      previousPointsRef.current = stepData;
    }
    return /* @__PURE__ */ React.createElement(Layer, null, /* @__PURE__ */ React.createElement(ScatterSymbols, {
      points: stepData,
      allOtherScatterProps: props,
      showLabels: !isAnimating
    }));
  });
}
function RenderSymbols(props) {
  var {
    points,
    isAnimationActive
  } = props;
  var previousPointsRef = useRef(null);
  var prevPoints = previousPointsRef.current;
  if (isAnimationActive && points && points.length && (!prevPoints || prevPoints !== points)) {
    return /* @__PURE__ */ React.createElement(SymbolsWithAnimation, {
      props,
      previousPointsRef
    });
  }
  return /* @__PURE__ */ React.createElement(ScatterSymbols, {
    points,
    allOtherScatterProps: props,
    showLabels: true
  });
}
function getTooltipEntrySettings(props) {
  var {
    dataKey,
    points,
    stroke,
    strokeWidth,
    fill,
    name,
    hide,
    tooltipType
  } = props;
  return {
    dataDefinedOnItem: points === null || points === void 0 ? void 0 : points.map((p) => p.tooltipPayload),
    positions: points === null || points === void 0 ? void 0 : points.map((p) => p.tooltipPosition),
    settings: {
      stroke,
      strokeWidth,
      fill,
      nameKey: void 0,
      dataKey,
      name: getTooltipNameProp(name, dataKey),
      hide,
      type: tooltipType,
      color: fill,
      unit: ""
      // why doesn't Scatter support unit?
    }
  };
}
function computeScatterPoints(_ref3) {
  var {
    displayedData,
    xAxis,
    yAxis,
    zAxis,
    scatterSettings,
    xAxisTicks,
    yAxisTicks,
    cells
  } = _ref3;
  var xAxisDataKey = isNullish(xAxis.dataKey) ? scatterSettings.dataKey : xAxis.dataKey;
  var yAxisDataKey = isNullish(yAxis.dataKey) ? scatterSettings.dataKey : yAxis.dataKey;
  var zAxisDataKey = zAxis && zAxis.dataKey;
  var defaultRangeZ = zAxis ? zAxis.range : ZAxis.defaultProps.range;
  var defaultZ = defaultRangeZ && defaultRangeZ[0];
  var xBandSize = xAxis.scale.bandwidth ? xAxis.scale.bandwidth() : 0;
  var yBandSize = yAxis.scale.bandwidth ? yAxis.scale.bandwidth() : 0;
  return displayedData.map((entry, index) => {
    var x = getValueByDataKey(entry, xAxisDataKey);
    var y = getValueByDataKey(entry, yAxisDataKey);
    var z = !isNullish(zAxisDataKey) && getValueByDataKey(entry, zAxisDataKey) || "-";
    var tooltipPayload = [{
      // @ts-expect-error name prop should not have dataKey in it
      name: isNullish(xAxis.dataKey) ? scatterSettings.name : xAxis.name || xAxis.dataKey,
      unit: xAxis.unit || "",
      // @ts-expect-error getValueByDataKey does not validate the output type
      value: x,
      payload: entry,
      dataKey: xAxisDataKey,
      type: scatterSettings.tooltipType
    }, {
      // @ts-expect-error name prop should not have dataKey in it
      name: isNullish(yAxis.dataKey) ? scatterSettings.name : yAxis.name || yAxis.dataKey,
      unit: yAxis.unit || "",
      // @ts-expect-error getValueByDataKey does not validate the output type
      value: y,
      payload: entry,
      dataKey: yAxisDataKey,
      type: scatterSettings.tooltipType
    }];
    if (z !== "-") {
      tooltipPayload.push({
        // @ts-expect-error name prop should not have dataKey in it
        name: zAxis.name || zAxis.dataKey,
        unit: zAxis.unit || "",
        // @ts-expect-error getValueByDataKey does not validate the output type
        value: z,
        payload: entry,
        dataKey: zAxisDataKey,
        type: scatterSettings.tooltipType
      });
    }
    var cx = getCateCoordinateOfLine({
      axis: xAxis,
      ticks: xAxisTicks,
      bandSize: xBandSize,
      entry,
      index,
      dataKey: xAxisDataKey
    });
    var cy = getCateCoordinateOfLine({
      axis: yAxis,
      ticks: yAxisTicks,
      bandSize: yBandSize,
      entry,
      index,
      dataKey: yAxisDataKey
    });
    var size = z !== "-" ? zAxis.scale(z) : defaultZ;
    var radius = Math.sqrt(Math.max(size, 0) / Math.PI);
    return _objectSpread(_objectSpread({}, entry), {}, {
      cx,
      cy,
      x: cx - radius,
      y: cy - radius,
      width: 2 * radius,
      height: 2 * radius,
      size,
      node: {
        x,
        y,
        z
      },
      tooltipPayload,
      tooltipPosition: {
        x: cx,
        y: cy
      },
      payload: entry
    }, cells && cells[index] && cells[index].props);
  });
}
var errorBarDataPointFormatter = (dataPoint, dataKey, direction) => {
  return {
    x: dataPoint.cx,
    y: dataPoint.cy,
    value: direction === "x" ? +dataPoint.node.x : +dataPoint.node.y,
    // @ts-expect-error getValueByDataKey does not validate the output type
    errorVal: getValueByDataKey(dataPoint, dataKey)
  };
};
function ScatterWithId(props) {
  var {
    hide,
    points,
    className,
    needClip,
    xAxisId,
    yAxisId,
    id,
    children
  } = props;
  if (hide) {
    return null;
  }
  var layerClass = clsx("recharts-scatter", className);
  var clipPathId = id;
  return /* @__PURE__ */ React.createElement(Layer, {
    className: layerClass,
    clipPath: needClip ? "url(#clipPath-".concat(clipPathId, ")") : null,
    id
  }, needClip && /* @__PURE__ */ React.createElement("defs", null, /* @__PURE__ */ React.createElement(GraphicalItemClipPath, {
    clipPathId,
    xAxisId,
    yAxisId
  })), /* @__PURE__ */ React.createElement(SetErrorBarContext, {
    xAxisId,
    yAxisId,
    data: points,
    dataPointFormatter: errorBarDataPointFormatter,
    errorBarOffset: 0
  }, children), /* @__PURE__ */ React.createElement(Layer, {
    key: "recharts-scatter-symbols"
  }, /* @__PURE__ */ React.createElement(RenderSymbols, props)));
}
var defaultScatterProps = {
  xAxisId: 0,
  yAxisId: 0,
  zAxisId: 0,
  legendType: "circle",
  lineType: "joint",
  lineJointType: "linear",
  data: [],
  shape: "circle",
  hide: false,
  isAnimationActive: !Global.isSsr,
  animationBegin: 0,
  animationDuration: 400,
  animationEasing: "linear"
};
function ScatterImpl(props) {
  var _resolveDefaultProps = resolveDefaultProps(props, defaultScatterProps), {
    animationBegin,
    animationDuration,
    animationEasing,
    hide,
    isAnimationActive,
    legendType,
    lineJointType,
    lineType,
    shape,
    xAxisId,
    yAxisId,
    zAxisId
  } = _resolveDefaultProps, everythingElse = _objectWithoutProperties(_resolveDefaultProps, _excluded3);
  var {
    needClip
  } = useNeedsClip(xAxisId, yAxisId);
  var cells = useMemo(() => findAllByType(props.children, Cell), [props.children]);
  var isPanorama = useIsPanorama();
  var points = useAppSelector((state) => {
    return selectScatterPoints(state, xAxisId, yAxisId, zAxisId, props.id, cells, isPanorama);
  });
  if (needClip == null) {
    return null;
  }
  return /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(SetTooltipEntrySettings, {
    fn: getTooltipEntrySettings,
    args: _objectSpread(_objectSpread({}, props), {}, {
      points
    })
  }), /* @__PURE__ */ React.createElement(ScatterWithId, _extends({}, everythingElse, {
    xAxisId,
    yAxisId,
    zAxisId,
    lineType,
    lineJointType,
    legendType,
    shape,
    hide,
    isAnimationActive,
    animationBegin,
    animationDuration,
    animationEasing,
    points,
    needClip
  })));
}
function Scatter(outsideProps) {
  var props = resolveDefaultProps(outsideProps, defaultScatterProps);
  var isPanorama = useIsPanorama();
  return /* @__PURE__ */ React.createElement(RegisterGraphicalItemId, {
    id: props.id,
    type: "scatter"
  }, (id) => /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(SetLegendPayload, {
    legendPayload: computeLegendPayloadFromScatterProps(props)
  }), /* @__PURE__ */ React.createElement(SetCartesianGraphicalItem, {
    type: "scatter",
    id,
    data: props.data,
    xAxisId: props.xAxisId,
    yAxisId: props.yAxisId,
    zAxisId: props.zAxisId,
    dataKey: props.dataKey,
    hide: props.hide,
    name: props.name,
    tooltipType: props.tooltipType,
    isPanorama
  }), /* @__PURE__ */ React.createElement(ScatterImpl, _extends({}, props, {
    id
  }))));
}
Scatter.displayName = "Scatter";
var allowedTooltipTypes = ["item"];
var ScatterChart$1 = /* @__PURE__ */ forwardRef((props, ref) => {
  return /* @__PURE__ */ React.createElement(CartesianChart, {
    chartName: "ScatterChart",
    defaultTooltipEventType: "item",
    validateTooltipEventTypes: allowedTooltipTypes,
    tooltipPayloadSearcher: arrayTooltipSearcher,
    categoricalChartProps: props,
    ref
  });
});
const CustomTooltip = ({ active, payload }) => {
  if (active && payload && payload.length && payload[0]) {
    const firstPayload = payload[0];
    const data = firstPayload.payload;
    if (!data || typeof data !== "object") {
      return null;
    }
    return /* @__PURE__ */ jsxs("div", { className: "rounded-xl border border-border/30 bg-popover/95 backdrop-blur-md p-3 shadow-2xl", children: [
      /* @__PURE__ */ jsx("p", { className: "text-sm font-semibold text-primary mb-2", children: firstPayload.name }),
      /* @__PURE__ */ jsx("div", { className: "space-y-1", children: Object.entries(data || {}).map(([key, value]) => /* @__PURE__ */ jsxs("div", { className: "flex justify-between gap-4", children: [
        /* @__PURE__ */ jsxs("span", { className: "text-xs text-secondary capitalize", children: [
          key,
          ":"
        ] }),
        /* @__PURE__ */ jsx("span", { className: "text-xs font-semibold text-primary", children: typeof value === "number" ? value.toLocaleString() : String(value) })
      ] }, key)) })
    ] });
  }
  return null;
};
function ScatterChart({
  data,
  config,
  className,
  showGrid = true,
  showTooltip = true,
  showLegend = false,
  showXAxis = true,
  showYAxis = true,
  xAxisKey = "x",
  yAxisKey = "y",
  zAxisKey,
  xAxisProps,
  yAxisProps,
  zAxisProps,
  tooltipProps,
  legendProps,
  scatterProps,
  height = 400,
  width = "100%"
}) {
  const getColor = (index, customColor) => {
    if (customColor) return customColor;
    return getDefaultChartColor(index);
  };
  const isMultipleDatasets = !Array.isArray(data);
  return /* @__PURE__ */ jsx("div", { className: cn("w-full focus:outline-none", className), children: /* @__PURE__ */ jsx(ResponsiveContainer, { width, height, children: /* @__PURE__ */ jsxs(ScatterChart$1, { margin: getChartMargin(showLegend), children: [
    showGrid && /* @__PURE__ */ jsx(CartesianGrid, { ...defaultGridProps }),
    showXAxis && /* @__PURE__ */ jsx(
      XAxis,
      {
        type: "number",
        dataKey: xAxisKey,
        name: xAxisKey,
        stroke: "hsl(var(--text-secondary))",
        tick: { fill: "hsl(var(--text-secondary))", fontSize: 10 },
        axisLine: false,
        tickLine: { stroke: "hsl(var(--border))" },
        ...xAxisProps
      }
    ),
    showYAxis && /* @__PURE__ */ jsx(
      YAxis,
      {
        type: "number",
        dataKey: yAxisKey,
        name: yAxisKey,
        stroke: "hsl(var(--text-secondary))",
        tick: { fill: "hsl(var(--text-secondary))", fontSize: 10 },
        axisLine: false,
        tickLine: false,
        ...yAxisProps
      }
    ),
    zAxisKey && /* @__PURE__ */ jsx(
      ZAxis,
      {
        type: "number",
        dataKey: zAxisKey,
        name: zAxisKey,
        range: [60, 400],
        ...zAxisProps
      }
    ),
    showTooltip && /* @__PURE__ */ jsx(
      Tooltip,
      {
        content: /* @__PURE__ */ jsx(CustomTooltip, {}),
        cursor: {
          fill: "hsl(var(--muted))",
          opacity: 0.5,
          strokeDasharray: "3 3"
        },
        ...tooltipProps
      }
    ),
    showLegend && /* @__PURE__ */ jsx(Legend, { ...defaultLegendProps, ...legendProps }),
    isMultipleDatasets ? Object.entries(data).map(([key, dataset], index) => {
      const configItem = config[key] || {};
      return /* @__PURE__ */ jsx(
        Scatter,
        {
          name: configItem.label || key,
          data: dataset,
          fill: getColor(index, configItem.color),
          shape: configItem.shape,
          isAnimationActive: false,
          ...scatterProps
        },
        key
      );
    }) : /* @__PURE__ */ jsx(
      Scatter,
      {
        name: "Data",
        data,
        fill: getColor(0, config.default?.color),
        isAnimationActive: false,
        ...scatterProps,
        children: Array.isArray(data) && data.map((_entry, index) => /* @__PURE__ */ jsx(Cell, { fill: getColor(index) }, `cell-${index}`))
      }
    )
  ] }) }) });
}
ScatterChart.displayName = "ScatterChart";
export {
  ScatterChart
};
