import { BorderStyle } from "./BorderStyle.js";
import { BorderWidth } from "./BorderWidth.js";
import { overlayColors, ColorMode, defaultColorMode } from "./Color.js";
import { Duration } from "./Duration.js";
import { shadowsByColorMode } from "./Shadow.js";
import { TimingFunction } from "./TimingFunction.js";
import { TransitionProperty } from "./TransitionProperty.js";
const getTokenValue = (tokenType, token) => {
  if (token in tokenType) {
    return tokenType[token];
  } else {
    return token;
  }
};
const buildColor = (colors) => {
  return (theme) => {
    return overlayColors(colors.map((color) => theme.rawColors[color] ?? color));
  };
};
const buildBorder = (color, width = "1px", style = "SOLID") => {
  return (theme) => {
    var _a;
    const widthValue = getTokenValue(BorderWidth, width);
    const styleValue = getTokenValue(BorderStyle, style);
    const colorValue = typeof color === "function" ? color(theme) : ((_a = theme.colors) == null ? void 0 : _a[color]) ?? color;
    return `${widthValue} ${styleValue} ${colorValue}`;
  };
};
const buildShadow = (shadowKey, property = "box-shadow") => {
  return (theme) => {
    const shadowKeys = Array.isArray(shadowKey) ? shadowKey : [shadowKey];
    const shadows = shadowKeys.map((shadowKey2) => {
      if (!shadowKey2) {
        return null;
      }
      const colorMode = Object.values(ColorMode).find(
        (colorMode2) => {
          var _a, _b;
          return theme.rawColors.Text === ((_b = (_a = theme.rawColors.modes) == null ? void 0 : _a[colorMode2]) == null ? void 0 : _b.Text);
        }
      );
      const shadowValues = shadowsByColorMode[colorMode ?? defaultColorMode][shadowKey2];
      if (property === "filter") {
        return shadowValues === null ? "drop-shadow(0, 0)" : shadowValues.map((shadowValue) => `drop-shadow(${shadowValue})`).join(" ");
      } else {
        return shadowValues === null ? "none" : shadowValues.join(", ");
      }
    });
    return shadows.length === 1 ? shadows[0] : shadows;
  };
};
const buildTransition = (property = "ALL", duration = "200ms", timingFunction = "EASE_IN_OUT", delay = "0ms") => {
  const properties = getTokenValue(TransitionProperty, property).split(",").map((property2) => property2.trim());
  const transitions = properties.map(
    (property2) => `${property2} ${getTokenValue(Duration, duration)} ${getTokenValue(
      TimingFunction,
      timingFunction
    )} ${getTokenValue(Duration, delay)}`
  );
  return transitions.join(", ");
};
export {
  buildBorder,
  buildColor,
  buildShadow,
  buildTransition,
  getTokenValue
};
