"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 utils_exports = {};
__export(utils_exports, {
  getLowerCaseAppEmbedType: () => getLowerCaseAppEmbedType,
  hasOnlyDefaults: () => hasOnlyDefaults,
  isTypeAppEmbed: () => isTypeAppEmbed,
  toAppEmbedData: () => toAppEmbedData
});
module.exports = __toCommonJS(utils_exports);
var import_v1 = require("./../ricos-schema/legacy/wix/rich_content/v1/index.js");
var import_convert_duration = require("./convert-duration.js");
const isTypeAppEmbed = (type) => Object.values(import_v1.AppEmbedData_AppType).includes(type);
const getLowerCaseAppEmbedType = (type) => type.toLowerCase();
const mapVerticalData = (item, componentType, t) => {
  switch (componentType) {
    case "BOOKING":
      return {
        bookingData: {
          durations: (0, import_convert_duration.convertDurations)(item.bookingDetails?.durations, t)
        }
      };
    case "EVENT":
      return {
        eventData: {
          scheduling: item.eventDetails?.formattedDateAndTime,
          location: item.eventDetails?.location
        }
      };
    default:
      return {};
  }
};
const mapPricingData = (item) => {
  if (!item.pricingData) {
    return void 0;
  }
  return {
    valueFrom: item.pricingData.minValue,
    valueTo: item.pricingData.maxValue,
    discountedValue: item.pricingData.discountedValue,
    currency: item.pricingData.currency,
    pricingPlanId: item.pricingData.pricingPlanId
  };
};
const mapImageData = (item) => ({
  src: item.image?.id ? { id: item.image?.id } : { url: item.image?.url },
  height: item.image?.height,
  width: item.image?.width
});
const toAppEmbedData = (item, componentData, t) => {
  const mappedVerticalData = mapVerticalData(item, componentData.type, t);
  const mappedPricingData = mapPricingData(item);
  const mappedImage = mapImageData(item);
  return {
    containerData: {
      width: {
        size: import_v1.PluginContainerData_Width_Type.CONTENT
      },
      alignment: import_v1.PluginContainerData_Alignment.CENTER,
      textWrap: false
    },
    ...item,
    ...componentData,
    name: item.title,
    itemId: item.id,
    url: item.pageUrl,
    image: mappedImage,
    pricingData: mappedPricingData,
    ...mappedVerticalData
  };
};
const hasOnlyDefaults = (styleObj, defaults) => {
  if (!styleObj) {
    return true;
  }
  const enumsAreDefault = Object.entries(defaults).every(
    ([key, defaultValue]) => styleObj[key] === defaultValue || styleObj[key] === void 0
  );
  const hasCustomProps = Object.keys(styleObj).some((key) => !(key in defaults));
  return enumsAreDefault && !hasCustomProps;
};
//# sourceMappingURL=utils.js.map
