import { hexToRgba } from "../theme-utils/color-utils.js";
import { resolveDocumentColorToHex } from "./theme-color-token.js";
const resolveStopColor = (color, palette) => palette && color ? resolveDocumentColorToHex(color, palette) ?? color : color;
const formatStop = (stop, palette) => {
  const color = resolveStopColor(stop.color, palette);
  const position = ((stop.position ?? 0) * 100).toFixed(2);
  return `${hexToRgba(color)} ${position}%`;
};
const formatStops = (stops, palette) => [...stops ?? []].filter((stop) => stop.color).sort((a, b) => (a.position ?? 0) - (b.position ?? 0)).map((stop) => formatStop(stop, palette)).join(", ");
const schemaGradientToCss = (gradient, palette) => {
  if (!gradient) {
    return "";
  }
  if (gradient.type === "LINEAR") {
    return `linear-gradient(${gradient.angle ?? 90}deg, ${formatStops(gradient.stops, palette)})`;
  }
  if (gradient.type === "RADIAL") {
    return `radial-gradient(circle at ${gradient.centerX ?? 50}% ${gradient.centerY ?? 50}%, ${formatStops(gradient.stops, palette)})`;
  }
  return "";
};
export {
  schemaGradientToCss
};
//# sourceMappingURL=schema-gradient-to-css.js.map
