"use strict";
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 schema_gradient_to_css_exports = {};
__export(schema_gradient_to_css_exports, {
  schemaGradientToCss: () => schemaGradientToCss
});
module.exports = __toCommonJS(schema_gradient_to_css_exports);
var import_color_utils = require("../theme-utils/color-utils.js");
var import_theme_color_token = require("./theme-color-token.js");
const resolveStopColor = (color, palette) => palette && color ? (0, import_theme_color_token.resolveDocumentColorToHex)(color, palette) ?? color : color;
const formatStop = (stop, palette) => {
  const color = resolveStopColor(stop.color, palette);
  const position = ((stop.position ?? 0) * 100).toFixed(2);
  return `${(0, import_color_utils.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 "";
};
//# sourceMappingURL=schema-gradient-to-css.js.map
