import {
  AppEmbedData_AppType,
  PluginContainerData_Alignment,
  PluginContainerData_Width_Type
} from "./../ricos-schema/legacy/wix/rich_content/v1/index.js";
import { convertDurations } from "./convert-duration.js";
const isTypeAppEmbed = (type) => Object.values(AppEmbedData_AppType).includes(type);
const getLowerCaseAppEmbedType = (type) => type.toLowerCase();
const mapVerticalData = (item, componentType, t) => {
  switch (componentType) {
    case "BOOKING":
      return {
        bookingData: {
          durations: 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: PluginContainerData_Width_Type.CONTENT
      },
      alignment: 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;
};
export {
  getLowerCaseAppEmbedType,
  hasOnlyDefaults,
  isTypeAppEmbed,
  toAppEmbedData
};
//# sourceMappingURL=utils.js.map
