import React from "react";
import { Source } from "react-map-gl/maplibre";
import { BubbleCircleLayer } from "./BubbleCircleLayer.js";
import { BubbleLayerTooltip } from "./BubbleLayerTooltip.js";
import { BubbleOutlineLayer } from "./BubbleOutlineLayer.js";
import { SizeInterpolationContext } from "./contexts/size-interpolation.context.js";
import { buildRadiusScale } from "./functions/build-radius-scale.js";
import { parseBubbleDataToGeoJSON } from "./functions/parse-bubble-data-to-geo-json.js";
import { DEFAULT_BUBBLE_COLOR, DEFAULT_RADIUS } from "../../constants.js";
import { isBubbleTooltipTemplate } from "../../functions/tooltip-type-guards.js";
import { useLayerColoringStrategy } from "../../hooks/use-layer-coloring-strategy.js";
import { useLegendInteractionHighlighting } from "../../hooks/use-legend-interaction-highlighting.js";
import { useLegendInteractionVisibility } from "../../hooks/use-legend-interaction-visibility.js";
import { useResolveColor } from "../../hooks/use-resolve-color.js";
import { useTooltipTemplate } from "../../hooks/use-tooltip-template.js";
import { BubbleLayerTooltip as BubbleLayerTooltipSlot } from "../../slots/BubbleLayerTooltip.js";
import {
  isScaleRadius
} from "../../types/bubble-layer.js";
const BubbleLayer = (props) => {
  const {
    data,
    layerId,
    radius = DEFAULT_RADIUS,
    children,
    sizeInterpolation = "fixed"
  } = props;
  const colorParser = useLayerColoringStrategy();
  const bubbleColor = useResolveColor(DEFAULT_BUBBLE_COLOR, props, colorParser);
  const sourceId = `source-${layerId}`;
  useLegendInteractionHighlighting(props, sourceId);
  useLegendInteractionVisibility(props, layerId);
  let radiusScale = (value) => value;
  if (isScaleRadius(props)) {
    const { radiusRange = [10, 100], radius: radius2, scale = "linear" } = props;
    radiusScale = buildRadiusScale(data, radius2, scale, radiusRange);
  }
  const dataGeoJson = parseBubbleDataToGeoJSON(
    data,
    bubbleColor,
    radius,
    radiusScale
  );
  const tooltipTemplate = useTooltipTemplate(children, BubbleLayerTooltipSlot);
  return /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(SizeInterpolationContext.Provider, { value: sizeInterpolation }, /* @__PURE__ */ React.createElement(Source, { id: sourceId, type: "geojson", data: dataGeoJson, generateId: true }, /* @__PURE__ */ React.createElement(BubbleCircleLayer, { id: layerId, source: sourceId }), /* @__PURE__ */ React.createElement(BubbleOutlineLayer, { beforeId: layerId, source: sourceId }))), /* @__PURE__ */ React.createElement(
    BubbleLayerTooltip,
    {
      layerId,
      tooltipTemplate: isBubbleTooltipTemplate(tooltipTemplate) ? tooltipTemplate : void 0
    }
  ));
};
BubbleLayer["displayName"] = "BubbleLayer";
export {
  BubbleLayer
};
//# sourceMappingURL=BubbleLayer.js.map
