import { featureCollection as turfFeatureCollection } from "@turf/helpers";
import { _getCanvasColor as getCanvasColor } from "@dynatrace/strato-components-preview/charts";
import { getArcLineFeatures } from "./get-arc-line-features.js";
import { getStraightLineFeatures } from "./get-straight-line-features.js";
import { MAX_LINE_THICKNESS, MIN_LINE_THICKNESS } from "../../../constants.js";
import { calculateHoveredColor } from "../../../functions/calculate-hovered-color.js";
import { defineColor } from "../../../functions/define-color.js";
const getLineThickness = (thickness) => {
  if (thickness < MIN_LINE_THICKNESS) {
    return MIN_LINE_THICKNESS;
  }
  if (thickness > MAX_LINE_THICKNESS) {
    return MAX_LINE_THICKNESS;
  }
  return thickness;
};
const getFeatureProperties = (thickness, curve) => (properties, id) => {
  const lineThickness = getLineThickness(thickness);
  return {
    ...properties,
    id,
    __lineWidth: lineThickness,
    curve
  };
};
const getFeatures = (path, featureProperties) => {
  const isCurve = featureProperties.curve === "smooth";
  if (isCurve) {
    return getArcLineFeatures(path, featureProperties);
  }
  return getStraightLineFeatures(path, featureProperties);
};
const getConnectionColor = (connection, color) => {
  const parsedColor = defineColor(color, connection);
  const canvasColor = getCanvasColor(parsedColor);
  const hoveredColor = calculateHoveredColor(canvasColor);
  return {
    __lineColor: canvasColor,
    __lineHoveredColor: hoveredColor
  };
};
const parseConnectionDataToGeoJSON = (data, thickness, color, curve) => {
  const featuresCollections = [];
  const getProperties = getFeatureProperties(thickness, curve);
  data.forEach((connection, index) => {
    const { path, ...properties } = connection;
    const featureProperties = {
      ...getProperties({ path, ...properties }, `connection-${index}`),
      ...getConnectionColor(connection, color)
    };
    const features = getFeatures(path, featureProperties);
    const featuresCollection = turfFeatureCollection(features);
    featuresCollections.push(featuresCollection);
  });
  return featuresCollections;
};
export {
  parseConnectionDataToGeoJSON
};
//# sourceMappingURL=parse-connection-data-to-geo-json.js.map
