"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_content_exports = {};
__export(card_content_exports, {
  CardContent: () => CardContent
});
module.exports = __toCommonJS(card_content_exports);
var import_classnames = __toESM(require("classnames"));
var import_react = __toESM(require("react"));
var import_ricos_context = require("./../../ricos-context/ricos-context.js");
var import_data_hooks = require("./../data-hooks.js");
var import_constants = require("../constants.js");
var import_card_content_scss = __toESM(require("./card-content-scss.js"));
var import_description = require("./description.js");
var import_ribbon = require("./ribbon.js");
const CardContent = (props) => {
  const { t } = (0, import_react.useContext)(import_ricos_context.RicosContext);
  const { title, buttonText, contentClasses, ribbonPlacement, componentData, ribbonText } = props;
  if (!componentData.cardStyles) {
    componentData.cardStyles = {};
  }
  if (!componentData.cardStyles.titlePriceLayout) {
    componentData.cardStyles.titlePriceLayout = "STACKED";
  }
  const shouldShowButton = !componentData?.hideButton;
  const shouldShowRibbon = !(componentData?.hideRibbon ?? true) && (!ribbonPlacement || ribbonPlacement === "PRODUCT_INFO");
  return /* @__PURE__ */ import_react.default.createElement("div", { className: (0, import_classnames.default)(import_card_content_scss.default.content, contentClasses) }, /* @__PURE__ */ import_react.default.createElement("div", { className: import_card_content_scss.default.contentText }, shouldShowRibbon && /* @__PURE__ */ import_react.default.createElement(RibbonTag, { ribbonText }), /* @__PURE__ */ import_react.default.createElement(TitleAndPrice, { title, componentData, t }), /* @__PURE__ */ import_react.default.createElement(import_description.Description, { componentData })), shouldShowButton && /* @__PURE__ */ import_react.default.createElement(ActionButton, { buttonText, t }));
};
const TitleAndPrice = ({
  title,
  componentData,
  t
}) => {
  const shouldShowPricing = componentData.pricingData && !componentData.hidePrice && (componentData.pricingData.valueFrom || componentData.pricingData.discountedValue || componentData.pricingData.pricingPlanId);
  return /* @__PURE__ */ import_react.default.createElement("div", { className: import_card_content_scss.default.titlePriceContainer }, /* @__PURE__ */ import_react.default.createElement("div", { className: import_card_content_scss.default.title, "data-hook": import_data_hooks.VERTICAL_EMBED_TITLE }, truncateTitle(title)), shouldShowPricing && /* @__PURE__ */ import_react.default.createElement(PricingInfo, { pricingData: componentData.pricingData, t }));
};
const PricingInfo = ({
  pricingData,
  t
}) => {
  const { valueFrom, valueTo, discountedValue, currency, pricingPlanId } = pricingData || {};
  const formatPrice = (price) => {
    const numericPrice = parseFloat(price);
    if (isNaN(numericPrice)) {
      return price;
    }
    return new Intl.NumberFormat("en-US", {
      style: "currency",
      currency,
      minimumFractionDigits: 2,
      maximumFractionDigits: 2
    }).format(numericPrice);
  };
  if (pricingPlanId) {
    return /* @__PURE__ */ import_react.default.createElement("div", { className: (0, import_classnames.default)(import_card_content_scss.default.pricing, import_card_content_scss.default.priceOriginal) }, /* @__PURE__ */ import_react.default.createElement("span", { className: (0, import_classnames.default)(import_card_content_scss.default.price) }, t("VerticalEmbed_Pricing_Plan")));
  }
  return /* @__PURE__ */ import_react.default.createElement("div", { className: (0, import_classnames.default)(import_card_content_scss.default.pricing, import_card_content_scss.default.priceOriginal) }, valueTo !== valueFrom && /* @__PURE__ */ import_react.default.createElement("span", { className: (0, import_classnames.default)(import_card_content_scss.default.price) }, t("VerticalEmbed_From_Price")), valueFrom && /* @__PURE__ */ import_react.default.createElement(
    "span",
    {
      className: (0, import_classnames.default)(import_card_content_scss.default.price, import_card_content_scss.default.priceOriginal, {
        [import_card_content_scss.default.priceStrikethrough]: discountedValue && discountedValue !== valueFrom
      })
    },
    formatPrice(valueFrom)
  ), discountedValue && discountedValue !== valueFrom && /* @__PURE__ */ import_react.default.createElement("span", { className: (0, import_classnames.default)(import_card_content_scss.default.price, import_card_content_scss.default.priceDiscounted) }, formatPrice(discountedValue)));
};
const RibbonTag = ({ ribbonText }) => /* @__PURE__ */ import_react.default.createElement("div", { className: import_card_content_scss.default.ribbon }, /* @__PURE__ */ import_react.default.createElement(import_ribbon.Ribbon, null, truncateRibbonText(ribbonText || "")));
const ActionButton = ({ buttonText }) => /* @__PURE__ */ import_react.default.createElement("div", { "data-hook": import_data_hooks.VERTICAL_EMBED_BUTTON, className: import_card_content_scss.default.button }, /* @__PURE__ */ import_react.default.createElement("div", { className: import_card_content_scss.default.buttonText }, truncateButtonText(buttonText)));
const truncateTitle = (title) => {
  return title.length <= import_constants.MAX_TITLE_LENGTH ? title : `${title.substring(0, import_constants.MAX_TITLE_LENGTH)}...`;
};
const truncateButtonText = (text) => {
  return text.length <= import_constants.MAX_BUTTON_TEXT_LENGTH ? text : `${text.substring(0, import_constants.MAX_BUTTON_TEXT_LENGTH)}...`;
};
const truncateRibbonText = (text) => {
  return text.length <= import_constants.MAX_RIBBON_TEXT_LENGTH ? text : `${text.substring(0, import_constants.MAX_RIBBON_TEXT_LENGTH)}...`;
};
//# sourceMappingURL=card-content.js.map
