var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
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 __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var use_resolve_color_exports = {};
__export(use_resolve_color_exports, {
  useResolveColor: () => useResolveColor
});
module.exports = __toCommonJS(use_resolve_color_exports);
var import_lodash_es = require("lodash");
var import_core = require("@dynatrace/strato-components-preview/core");
var import_use_color_scale = require("./use-color-scale.js");
var import_coloring = require("../types/coloring.js");
const useResolveColor = (defaultColor, props, colorParser) => {
  const isLegendColor = (0, import_coloring.isLegendColoring)(props);
  const legendColoring = (0, import_use_color_scale.useColorScale)();
  if (!isLegendColor) {
    return props.color ?? defaultColor;
  }
  let colorLegend = defaultColor;
  if (!(0, import_lodash_es.isUndefined)(legendColoring) && colorParser) {
    colorLegend = (item) => {
      const value = (0, import_core._accessValue)(item, props.valueAccessor);
      if ((0, import_lodash_es.isUndefined)(value)) {
        return defaultColor;
      }
      return colorParser(value) ?? defaultColor;
    };
  }
  return colorLegend;
};
