"use strict";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
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 __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
  // If the importer is in node compatibility mode or this is not an ESM
  // file that has been converted to a CommonJS file using a Babel-
  // compatible transform (i.e. "__esModule" has not been set), then set
  // "default" to the CommonJS "module.exports" for node compatibility.
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
  mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var card_exports = {};
__export(card_exports, {
  Card: () => Card
});
module.exports = __toCommonJS(card_exports);
var import_react = __toESM(require("react"));
var import_ricos_document = require("./../../ricos-schema/next-schema/generated/ricos_document.js");
var import_constants = require("../constants.js");
var import_vertical_embed_styles = require("../viewer/vertical-embed-styles.js");
var import_card_content = require("./card-content.js");
var import_card_content_scss = __toESM(require("./card-content-scss.js"));
var import_card_scss = __toESM(require("./card-scss.js"));
var import_ribbon = require("./ribbon.js");
var import_use_background_image_url = require("./use-background-image-url.js");
const Card = (props) => {
  const { title, buttonText, direction, image, componentData, ribbonText } = props;
  const imageStyles = componentData?.imageStyles || {};
  const shouldShowImage = !componentData?.hideImage && (image?.src?.url || image?.src?.id);
  const ribbonPlacement = componentData?.ribbonStyles?.ribbonPlacement || import_ricos_document.AppEmbedData_RibbonStyles_Placement.PRODUCT_INFO;
  const shouldShowRibbon = !(componentData?.hideRibbon ?? true) && ribbonText;
  const { containerRef, backgroundImageUrl } = (0, import_use_background_image_url.useBackgroundImageUrl)(image);
  const imageContainerProps = (0, import_vertical_embed_styles.generateImageContainerProps)(imageStyles, import_card_scss.default);
  return /* @__PURE__ */ import_react.default.createElement(
    "div",
    {
      style: { direction },
      className: (0, import_vertical_embed_styles.generateContainerClassName)(direction, imageStyles, import_card_scss.default)
    },
    shouldShowImage && /* @__PURE__ */ import_react.default.createElement("div", { className: import_card_scss.default.imageContainer }, /* @__PURE__ */ import_react.default.createElement(
      "div",
      {
        ref: containerRef,
        className: imageContainerProps.className,
        style: {
          ...imageContainerProps.style,
          backgroundImage: backgroundImageUrl ? `url(${backgroundImageUrl})` : void 0
        },
        role: "img",
        "aria-label": title
      }
    ), shouldShowRibbon && ribbonPlacement === import_ricos_document.AppEmbedData_RibbonStyles_Placement.IMAGE && /* @__PURE__ */ import_react.default.createElement("div", { className: import_card_scss.default.imageRibbon }, /* @__PURE__ */ import_react.default.createElement(import_ribbon.Ribbon, null, truncateRibbonText(ribbonText || "")))),
    /* @__PURE__ */ import_react.default.createElement(
      import_card_content.CardContent,
      {
        title,
        buttonText,
        componentData,
        imagePosition: imageStyles.imagePosition || import_ricos_document.AppEmbedData_ImageStyles_Position.START,
        contentClasses: (0, import_vertical_embed_styles.generateContentClasses)(
          componentData?.cardStyles,
          imageStyles.imagePosition || import_ricos_document.AppEmbedData_ImageStyles_Position.START,
          import_card_content_scss.default
        ),
        ribbonText,
        ribbonPlacement
      }
    )
  );
};
const truncateRibbonText = (text) => {
  return text.length <= import_constants.MAX_RIBBON_TEXT_LENGTH ? text : `${text.substring(0, import_constants.MAX_RIBBON_TEXT_LENGTH)}...`;
};
//# sourceMappingURL=card.js.map
