var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var parse_connection_data_to_geo_json_exports = {};
__export(parse_connection_data_to_geo_json_exports, {
  parseConnectionDataToGeoJSON: () => parseConnectionDataToGeoJSON
});
module.exports = __toCommonJS(parse_connection_data_to_geo_json_exports);
var import_helpers = require("@turf/helpers");
var import_charts = require("@dynatrace/strato-components-preview/charts");
var import_get_arc_line_features = require("./get-arc-line-features.js");
var import_get_straight_line_features = require("./get-straight-line-features.js");
var import_constants = require("../../../constants.js");
var import_calculate_hovered_color = require("../../../functions/calculate-hovered-color.js");
var import_define_color = require("../../../functions/define-color.js");
const getLineThickness = (thickness) => {
  if (thickness < import_constants.MIN_LINE_THICKNESS) {
    return import_constants.MIN_LINE_THICKNESS;
  }
  if (thickness > import_constants.MAX_LINE_THICKNESS) {
    return import_constants.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 (0, import_get_arc_line_features.getArcLineFeatures)(path, featureProperties);
  }
  return (0, import_get_straight_line_features.getStraightLineFeatures)(path, featureProperties);
};
const getConnectionColor = (connection, color) => {
  const parsedColor = (0, import_define_color.defineColor)(color, connection);
  const canvasColor = (0, import_charts._getCanvasColor)(parsedColor);
  const hoveredColor = (0, import_calculate_hovered_color.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 = (0, import_helpers.featureCollection)(features);
    featuresCollections.push(featuresCollection);
  });
  return featuresCollections;
};
