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 MapContent_exports = {};
__export(MapContent_exports, {
  MapContent: () => MapContent
});
module.exports = __toCommonJS(MapContent_exports);
var import_lodash_es = require("lodash");
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_core = require("@dynatrace/strato-components-preview/core");
var import_MapToolbar = require("./toolbar/MapToolbar.js");
var import_constants = require("../constants.js");
var import_layer_ids_context = require("../contexts/layer-ids.context.js");
var import_get_color_from_token = require("../functions/get-color-from-token.js");
var import_to_mapbox_initial_view_state = require("../functions/to-mapbox-initial-view-state.js");
var import_use_active_interaction = require("../hooks/use-active-interaction.js");
var import_use_hover_interaction = require("../hooks/use-hover-interaction.js");
var import_use_initial_view_state = require("../hooks/use-initial-view-state.js");
var import_use_map_config = require("../hooks/use-map-config.js");
var import_use_map_performance = require("../hooks/use-map-performance.js");
var import_use_map_source = require("../hooks/use-map-source.js");
var import_use_overlay_events = require("../hooks/use-overlay-events.js");
var import_use_tooltip_event_listeners = require("../hooks/use-tooltip-event-listeners.js");
var import_default_style = require("../map-styles/default-style.js");
const lineLayer = {
  id: "geojson-line",
  type: "line"
};
const fillLayer = {
  id: "geojson-fill",
  type: "fill"
};
const MapSource = () => {
  const mapData = (0, import_use_map_source.useMapSource)();
  return /* @__PURE__ */ import_react.default.createElement(import_maplibre.Source, { id: "data", type: "geojson", data: mapData }, /* @__PURE__ */ import_react.default.createElement(
    import_maplibre.Layer,
    {
      ...fillLayer,
      paint: {
        "fill-color": (0, import_get_color_from_token.getColorFromToken)(import_constants.DEFAULT_COUNTRIES_FILL_COLOR)
      }
    }
  ), /* @__PURE__ */ import_react.default.createElement(
    import_maplibre.Layer,
    {
      ...lineLayer,
      paint: {
        "line-color": (0, import_get_color_from_token.getColorFromToken)(import_constants.DEFAULT_COUNTRIES_BORDER_COLOR)
      }
    }
  ));
};
const MapInteractions = ({ children }) => {
  (0, import_use_hover_interaction.useHoverInteraction)();
  (0, import_use_active_interaction.useActiveInteraction)();
  return children;
};
const MapContent = (0, import_react.forwardRef)((props, forwardedRef) => {
  const {
    initialViewState: initialViewStateProp,
    children,
    style,
    mapStyle = import_default_style.defaultStyle,
    onViewStateChange,
    ...remaining
  } = props;
  const mapContainerRef = (0, import_react.useRef)(null);
  const mergedRefs = (0, import_core.useMergeRefs)([mapContainerRef, forwardedRef]);
  (0, import_use_tooltip_event_listeners.useTooltipEventListeners)();
  const { toolbar: toolbarConfig, interactions: interactionsConfig } = (0, import_use_map_config.useMapConfig)();
  const layerIds = (0, import_react.useContext)(import_layer_ids_context.LayerIdsContext);
  const shouldRenderToolbar = !(0, import_lodash_es.isUndefined)(toolbarConfig) || !(0, import_lodash_es.isUndefined)(interactionsConfig);
  const { height: graphHeight, width: graphWidth } = (0, import_charts._useGraphSize)();
  const {
    handleMouseEnter,
    handleMouseMove,
    handleMouseLeave,
    handleMouseClick,
    handleZoom,
    handleDrag
  } = (0, import_use_overlay_events.useOverlayEvents)();
  const initialViewState = (0, import_use_initial_view_state.useInitialViewState)(initialViewStateProp);
  const { onLoadHandler, onRenderHandler } = (0, import_use_map_performance.useMapPerformance)(mapContainerRef);
  return /* @__PURE__ */ import_react.default.createElement(
    "div",
    {
      "data-testid": "map-container",
      ref: mergedRefs,
      onMouseEnter: handleMouseEnter,
      onMouseLeave: handleMouseLeave
    },
    /* @__PURE__ */ import_react.default.createElement(
      import_maplibre.Map,
      {
        onMove: (evt) => {
          onViewStateChange?.(evt.viewState);
        },
        initialViewState: (0, import_to_mapbox_initial_view_state.toMapBoxInitialViewState)(initialViewState),
        style: {
          width: graphWidth,
          height: `${graphHeight}px`,
          ...style
        },
        mapStyle,
        dragRotate: false,
        fadeDuration: 0,
        RTLTextPlugin: false,
        renderWorldCopies: false,
        interactiveLayerIds: layerIds,
        onMouseMove: (e) => handleMouseMove(e),
        onClick: (e) => handleMouseClick(e),
        onZoom: handleZoom,
        onDrag: handleDrag,
        onRender: () => onRenderHandler && onRenderHandler(),
        onLoad: () => onLoadHandler && onLoadHandler(),
        interactive: true,
        ...remaining
      },
      /* @__PURE__ */ import_react.default.createElement(MapSource, null),
      /* @__PURE__ */ import_react.default.createElement(MapInteractions, null, children),
      shouldRenderToolbar ? /* @__PURE__ */ import_react.default.createElement(import_MapToolbar.MapToolbar, null) : null
    )
  );
});
MapContent["displayName"] = "MapContent";
