import React, { useRef } from "react";
import { useIntl } from "react-intl";
import { _ChartToolbarRenderer as ChartToolbarRenderer } from "@dynatrace/strato-components-preview/charts";
import { DownloadIcon } from "@dynatrace/strato-icons";
import { buildAndDownloadCsv } from "../../../functions/build-and-download-csv.js";
import { useMapRawData } from "../../../hooks/use-map-raw-data.js";
import { TOOLBAR_MESSAGES } from "../constants.js";
import { useA11yToolbarTabIndex } from "../hooks/use-a11y-toolbar-tab-index.js";
const MapDownloadDataButton = () => {
  const downloadDataButtonRef = useRef();
  const intl = useIntl();
  const tabIndex = useA11yToolbarTabIndex("download-data");
  const data = useMapRawData();
  const handleDownloadDataKeyboard = (event) => {
    if (event.key === "Enter") {
      buildAndDownloadCsv(data);
    }
  };
  const handleDownloadDataToolbar = () => {
    buildAndDownloadCsv(data);
  };
  return /* @__PURE__ */ React.createElement(
    ChartToolbarRenderer.Control,
    {
      ref: downloadDataButtonRef,
      prefixIcon: /* @__PURE__ */ React.createElement(DownloadIcon, null),
      tooltipText: intl.formatMessage(TOOLBAR_MESSAGES.downloadData),
      testId: "map-toolbar-download",
      onKeyDown: handleDownloadDataKeyboard,
      onClick: handleDownloadDataToolbar,
      tabIndex
    }
  );
};
export {
  MapDownloadDataButton
};
//# sourceMappingURL=MapDownloadDataButton.js.map
