var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
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 __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
  // If the importer is in node compatibility mode or this is not an ESM
  // file that has been converted to a CommonJS file using a Babel-
  // compatible transform (i.e. "__esModule" has not been set), then set
  // "default" to the CommonJS "module.exports" for node compatibility.
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
  mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var ChoroplethLayer_exports = {};
__export(ChoroplethLayer_exports, {
  ChoroplethLayer: () => ChoroplethLayer
});
module.exports = __toCommonJS(ChoroplethLayer_exports);
var import_react = __toESM(require("react"));
var import_maplibre = require("react-map-gl/maplibre");
var import_charts = require("@dynatrace/strato-components-preview/charts");
var import_ChoroplethLayerTooltip = require("./ChoroplethLayerTooltip.js");
var import_parse_region_data_to_geo_json = require("./functions/parse-region-data-to-geo-json.js");
var import_constants = require("../../constants.js");
var import_tooltip_type_guards = require("../../functions/tooltip-type-guards.js");
var import_use_layer_coloring_strategy = require("../../hooks/use-layer-coloring-strategy.js");
var import_use_legend_interaction_highlighting = require("../../hooks/use-legend-interaction-highlighting.js");
var import_use_legend_interaction_visibility = require("../../hooks/use-legend-interaction-visibility.js");
var import_use_map_source = require("../../hooks/use-map-source.js");
var import_use_resolve_color = require("../../hooks/use-resolve-color.js");
var import_use_tooltip_template = require("../../hooks/use-tooltip-template.js");
var import_ChoroplethLayerTooltip2 = require("../../slots/ChoroplethLayerTooltip.js");
const ChoroplethLayer = (props) => {
  const { layerId, data, regionAccessor, children } = props;
  const mapSource = (0, import_use_map_source.useMapSource)();
  const colorParser = (0, import_use_layer_coloring_strategy.useLayerColoringStrategy)();
  const choroplethColor = (0, import_use_resolve_color.useResolveColor)(
    import_constants.DEFAULT_CHOROPLETH_COLOR,
    props,
    colorParser
  );
  const sourceId = layerId.replace("layer", "source");
  (0, import_use_legend_interaction_highlighting.useLegendInteractionHighlighting)(props, sourceId);
  (0, import_use_legend_interaction_visibility.useLegendInteractionVisibility)(props, layerId);
  const dataGeoJSON = (0, import_parse_region_data_to_geo_json.parseRegionDataToGeoJSON)(
    mapSource,
    data,
    regionAccessor,
    choroplethColor
  );
  const tooltipTemplate = (0, import_use_tooltip_template.useTooltipTemplate)(
    children,
    import_ChoroplethLayerTooltip2.ChoroplethLayerTooltip
  );
  return /* @__PURE__ */ import_react.default.createElement(import_react.default.Fragment, null, /* @__PURE__ */ import_react.default.createElement(import_maplibre.Source, { id: sourceId, type: "geojson", data: dataGeoJSON, generateId: true }, /* @__PURE__ */ import_react.default.createElement(
    import_maplibre.Layer,
    {
      id: layerId,
      type: "fill",
      source: sourceId,
      paint: {
        "fill-color": [
          "case",
          ["boolean", ["feature-state", "active"], false],
          ["get", "__color"],
          ["boolean", ["feature-state", "hover"], false],
          ["get", "__hoveredColor"],
          ["get", "__color"]
        ],
        "fill-opacity": [
          "case",
          ["boolean", ["feature-state", "legendHover"], true],
          import_constants.SHAPE_OPACITY,
          import_constants.LEGEND_DIM_OPACITY
        ]
      }
    }
  ), /* @__PURE__ */ import_react.default.createElement(
    import_maplibre.Layer,
    {
      type: "line",
      source: sourceId,
      paint: {
        "line-color": (0, import_charts._getCanvasColor)(import_constants.DEFAULT_COUNTRIES_BORDER_COLOR)
      }
    }
  ), /* @__PURE__ */ import_react.default.createElement(
    import_maplibre.Layer,
    {
      type: "line",
      source: sourceId,
      paint: {
        "line-color": [
          "case",
          ["boolean", ["feature-state", "active"], false],
          (0, import_charts._getCanvasColor)(import_constants.ACTIVE_COLOR),
          (0, import_charts._getCanvasColor)(import_constants.TRANSPARENT_BORDER_COLOR)
        ],
        "line-width": import_constants.ACTIVE_STATE_BORDERS_WIDTH
      }
    }
  )), /* @__PURE__ */ import_react.default.createElement(
    import_ChoroplethLayerTooltip.ChoroplethLayerTooltip,
    {
      layerId,
      tooltipTemplate: (0, import_tooltip_type_guards.isChoroplethTooltipTemplate)(tooltipTemplate) ? tooltipTemplate : void 0
    }
  ));
};
ChoroplethLayer["displayName"] = "ChoroplethLayer";
