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 MapView_exports = {};
__export(MapView_exports, {
  MapView: () => MapView
});
module.exports = __toCommonJS(MapView_exports);
var import_react = __toESM(require("react"));
var import_charts = require("@dynatrace/strato-components-preview/charts");
var import_core = require("@dynatrace/strato-components-preview/core");
var import_MapLegendRenderer = require("./components/legend/MapLegendRenderer.js");
var import_MapContent = require("./components/MapContent.js");
var import_constants = require("./constants.js");
var import_layer_ids_context = require("./contexts/layer-ids.context.js");
var import_map_configuration_context = require("./contexts/map-configuration.context.js");
var import_map_country_code_context = require("./contexts/map-country-code.context.js");
var import_map_data_bounding_box_context = require("./contexts/map-data-bounding-box.context.js");
var import_map_raw_data_context = require("./contexts/map-raw-data.context.js");
var import_build_and_download_csv = require("./functions/build-and-download-csv.js");
var import_extract_layers_data = require("./functions/extract-layers-data.js");
var import_get_data_layers_bounding_box = require("./functions/get-data-layers-bounding-box.js");
var import_get_map_states_template = require("./functions/get-map-states-template.js");
var import_iterate_config_slots = require("./functions/iterate-config-slots.js");
var import_set_layers_id = require("./functions/set-layers-id.js");
var import_use_map_settings = require("./hooks/use-map-settings.js");
var import_useAutoLegendRefresh = require("./hooks/useAutoLegendRefresh.js");
var import_color_scale_provider = require("./providers/color-scale.provider.js");
var import_layer_color_strategy_provider = require("./providers/layer-color-strategy.provider.js");
var import_DisabledState = require("./slots/states/DisabledState.js");
var import_ErrorStateSlot = require("./slots/states/ErrorStateSlot.js");
var import_map_store_provider = require("./store/map-store.provider.js");
var import_react_mapgl_styles = require("./styles/react-mapgl-styles.css");
const _MapView = (0, import_react.forwardRef)(
  (props, forwardedRef) => {
    const {
      children,
      loading = false,
      style: costumerStyle,
      className: customerClassNames,
      ...remaining
    } = props;
    const { layerIds, parsedChildren } = (0, import_set_layers_id.setLayersId)(children);
    const layersData = (0, import_extract_layers_data.extractLayersData)(parsedChildren);
    const dataLayersBBox = (0, import_get_data_layers_bounding_box.getDataLayersBoundingBox)(children);
    const containerRef = (0, import_react.useRef)(null);
    const rootRef = (0, import_core.useMergeRefs)([
      forwardedRef,
      containerRef
    ]);
    (0, import_react.useImperativeHandle)(forwardedRef, () => ({
      element: containerRef.current,
      downloadData: () => {
        (0, import_build_and_download_csv.buildAndDownloadCsv)(layersData);
      }
    }));
    const config = (0, import_iterate_config_slots.iterateConfigSlots)(children);
    const isLegendHidden = !config.legend || !!config.legend.hidden;
    const legendPosition = config.legend?.position;
    const legendRatio = config.legend?.ratio;
    const legendOnRatioChange = config.legend?.onRatioChange;
    const { errorState } = (0, import_get_map_states_template.getMapStatesTemplates)(children);
    const {
      isLoading: isLoadingSettings,
      isMapEnabled,
      countryCode
    } = (0, import_use_map_settings.useMapSettings)();
    const chartHeight = (0, import_charts._coerceSizeValue)(props.height) || import_constants.DEFAULT_MAP_HEIGHT;
    const containerStyles = { width: "100%", ...costumerStyle };
    const chartLayoutRef = (0, import_useAutoLegendRefresh.useAutoLegendRefresh)(layersData);
    return /* @__PURE__ */ import_react.default.createElement(
      "div",
      {
        style: containerStyles,
        className: customerClassNames,
        "data-testid": "mapview-container"
      },
      !isLoadingSettings && !isMapEnabled ? /* @__PURE__ */ import_react.default.createElement(import_DisabledState.DisabledState, { height: chartHeight }) : /* @__PURE__ */ import_react.default.createElement(import_map_country_code_context.MapCountryCodeContext.Provider, { value: countryCode }, /* @__PURE__ */ import_react.default.createElement(import_map_configuration_context.MapConfigurationContext.Provider, { value: config }, /* @__PURE__ */ import_react.default.createElement(import_layer_ids_context.LayerIdsContext.Provider, { value: layerIds }, /* @__PURE__ */ import_react.default.createElement(import_map_raw_data_context.MapRawDataContext.Provider, { value: layersData }, /* @__PURE__ */ import_react.default.createElement(import_map_data_bounding_box_context.MapDataBoundingBoxContext.Provider, { value: dataLayersBBox }, /* @__PURE__ */ import_react.default.createElement(import_map_store_provider.MapStoreProvider, null, /* @__PURE__ */ import_react.default.createElement(import_color_scale_provider.ColorScaleProvider, null, /* @__PURE__ */ import_react.default.createElement(import_layer_color_strategy_provider.LayerColorStrategyProvider, null, /* @__PURE__ */ import_react.default.createElement(
        import_charts._ChartLayout,
        {
          ref: chartLayoutRef,
          chartHeight,
          errorState,
          showLoader: loading || isLoadingSettings
        },
        /* @__PURE__ */ import_react.default.createElement(import_charts._ChartLayout.Graph, null, !isLoadingSettings && /* @__PURE__ */ import_react.default.createElement(import_MapContent.MapContent, { ref: rootRef, ...remaining }, parsedChildren)),
        !isLegendHidden && /* @__PURE__ */ import_react.default.createElement(
          import_charts._ChartLayout.Legend,
          {
            position: legendPosition,
            ratio: legendRatio,
            ratioBoundaries: import_constants.DEFAULT_LEGEND_SIZES,
            onResize: legendOnRatioChange
          },
          /* @__PURE__ */ import_react.default.createElement(import_MapLegendRenderer.MapLegendRenderer, null)
        )
      )))))))))
    );
  }
);
_MapView["displayName"] = "MapView";
const MapView = Object.assign(_MapView, {
  ErrorState: import_ErrorStateSlot.ErrorStateSlot
});
