"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 helpers_exports = {};
__export(helpers_exports, {
  getRandomValue: () => getRandomValue,
  toBackgroundString: () => toBackgroundString
});
module.exports = __toCommonJS(helpers_exports);
var import_next_schema = require("./../ricos-schema/next-schema/index.js");
var import_resolve_css_color = require("./../_shared/resolve-css-color.js");
var import_uncreachable = require("./../_shared/uncreachable.js");
var import_image_utils = require("./../wix-rich-content-common/lib/image-utils.js");
function getRandomValue(pool) {
  return pool[Math.floor(Math.random() * pool.length)];
}
function toBackgroundString(background, backgroundType, width, height) {
  switch (backgroundType) {
    case import_next_schema.PollData_Design_PollDesign_Background_Type.GRADIENT:
      try {
        const { gradient } = background;
        return `linear-gradient(${gradient.angle}deg, ${(0, import_resolve_css_color.resolveCssColor)(
          gradient.startColor
        )}, ${(0, import_resolve_css_color.resolveCssColor)(gradient.lastColor)})`;
      } catch (error) {
        console.error(error);
        return null;
      }
    case import_next_schema.PollData_Design_PollDesign_Background_Type.IMAGE:
      if (!width || !height) {
        return null;
      }
      const URL = background.image?.src?.url;
      const imageSrc = (0, import_image_utils.getScaleImageSrc)(URL, width, height);
      return `url('${imageSrc}') center / cover`;
    case import_next_schema.PollData_Design_PollDesign_Background_Type.COLOR:
      return (0, import_resolve_css_color.resolveCssColor)(background.color) ?? null;
    default:
      (0, import_uncreachable.unreachable)(backgroundType);
      return (0, import_resolve_css_color.resolveCssColor)(background.color) ?? null;
  }
}
//# sourceMappingURL=helpers.js.map
