import React from "react";
import { isElement } from "react-is";
import { ChartToolbar } from "@dynatrace/strato-components-preview/charts";
import {
  DEFAULT_MAP_LEGEND_RATIO,
  DEFAULT_MAP_POSITION,
  DEFAULT_SEQUENTIAL_LEGEND_COLOR_PALETTE
} from "../constants.js";
import { CategoricalLegend } from "../slots/CategoricalLegend.js";
import { ChartInteractions } from "../slots/ChartInteractions.js";
import { SequentialLegend } from "../slots/SequentialLegend.js";
import { ThresholdLegend } from "../slots/ThresholdLegend.js";
const iterateConfigSlots = (children) => {
  let slots = {
    toolbar: void 0,
    interactions: void 0,
    legend: void 0
  };
  React.Children.forEach(children, (child) => {
    if (isElement(child)) {
      switch (child.type) {
        case ChartInteractions: {
          const { children: children2, ...previousInteractions } = child.props;
          const interactions = iterateChartInteractionsSlots(children2);
          slots = {
            ...slots,
            interactions: {
              ...previousInteractions,
              ...interactions
            }
          };
          break;
        }
        case ChartToolbar: {
          const { children: children2, ...toolbar } = child.props;
          const childrenToolbar = iterateChartToolbarSlots(children2);
          slots = {
            ...slots,
            toolbar: {
              ...toolbar,
              ...childrenToolbar
            }
          };
          break;
        }
        case SequentialLegend: {
          const { children: children2, ...legend } = child.props;
          slots = {
            ...slots,
            legend: {
              type: "sequential",
              colorPalette: DEFAULT_SEQUENTIAL_LEGEND_COLOR_PALETTE,
              position: DEFAULT_MAP_POSITION,
              ratio: DEFAULT_MAP_LEGEND_RATIO,
              ...legend
            }
          };
          break;
        }
        case CategoricalLegend: {
          const { children: children2, ...legend } = child.props;
          slots = {
            ...slots,
            legend: {
              type: "categorical",
              position: DEFAULT_MAP_POSITION,
              ...legend
            }
          };
          break;
        }
        case ThresholdLegend: {
          const { children: children2, ...legend } = child.props;
          slots = {
            ...slots,
            legend: {
              type: "threshold",
              position: DEFAULT_MAP_POSITION,
              ratio: DEFAULT_MAP_LEGEND_RATIO,
              ...legend
            }
          };
          break;
        }
      }
    }
  });
  return slots;
};
const iterateChartInteractionsSlots = (children) => {
  let interactions = {};
  React.Children.forEach(children, (childInteractions) => {
    if (isElement(childInteractions)) {
      switch (childInteractions.type) {
        case ChartInteractions.Zoom:
          interactions = { ...interactions, zoom: { enabled: true } };
          break;
        case ChartInteractions.ZoomToFit:
          interactions = { ...interactions, zoomToFit: { enabled: true } };
          break;
      }
    }
  });
  return interactions;
};
const iterateChartToolbarSlots = (children) => {
  let toolbar = {};
  React.Children.forEach(children, (childToolbar) => {
    if (isElement(childToolbar) && childToolbar.type === ChartToolbar.DownloadData) {
      toolbar = {
        ...toolbar,
        downloadData: { enabled: true }
      };
    }
  });
  return toolbar;
};
export {
  iterateConfigSlots
};
//# sourceMappingURL=iterate-config-slots.js.map
