import { scaleOrdinal } from "d3-scale";
import { isUndefined } from "lodash-es";
import {
  _colorPaletteMap as colorPaletteMap,
  _isCustomColorPalette as isCustomColorPalette
} from "@dynatrace/strato-components-preview/charts";
import { DEFAULT_BASIC_SHAPE_COLOR_TOKEN } from "../constants.js";
const buildCategoricalScale = (categories, colorPalette) => {
  const colors = [];
  if (isCustomColorPalette(colorPalette)) {
    categories.forEach((categoryName, index) => {
      const color = index < colorPalette.length ? colorPalette[index] : DEFAULT_BASIC_SHAPE_COLOR_TOKEN.Default;
      colors.push(color);
    });
    if (categories.length < colorPalette.length) {
      colors.push(DEFAULT_BASIC_SHAPE_COLOR_TOKEN.Default);
    }
  } else {
    categories.forEach((dataName) => {
      const colorToken = colorPaletteMap[colorPalette][dataName];
      if (!isUndefined(colorToken)) {
        colors.push(colorToken.Default);
      }
    });
  }
  return scaleOrdinal(categories, colors);
};
export {
  buildCategoricalScale
};
//# sourceMappingURL=build-categorical-scale.js.map
