"use strict";
require("zod");
const CalEventParser = require("./CalEventParser-XK6njYFX.cjs");
const index = require("./orgDomains-W_rFTMBa.cjs");
const appStoreMetadata$1 = {
  campfire: CalEventParser.campfire_config_json,
  dailyvideo: CalEventParser.metadata$1,
  demodesk: CalEventParser.demodesk_config_json,
  dialpad: CalEventParser.dialpad_config_json,
  discord: CalEventParser.discord_config_json,
  eightxeight: CalEventParser.eightxeight_config_json,
  "element-call": CalEventParser.element_call_config_json,
  facetime: CalEventParser.appConfig$1,
  fathom: CalEventParser.fathom_config_json,
  ga4: CalEventParser.ga4_config_json,
  googlevideo: CalEventParser.metadata,
  gtm: CalEventParser.gtm_config_json,
  "horizon-workrooms": CalEventParser.horizon_workrooms_config_json,
  huddle01video: CalEventParser.metadata$2,
  insihts: CalEventParser.insihts_config_json,
  jelly: CalEventParser.jelly_config_json,
  jitsivideo: CalEventParser.metadata$3,
  matomo: CalEventParser.matomo_config_json,
  metapixel: CalEventParser.metapixel_config_json,
  mirotalk: CalEventParser.mirotalk_config_json,
  nextcloudtalk: CalEventParser.config,
  office365video: CalEventParser.config$1,
  ping: CalEventParser.ping_config_json,
  plausible: CalEventParser.appConfig,
  posthog: CalEventParser.posthog_config_json,
  riverside: CalEventParser.riverside_config_json,
  roam: CalEventParser.roam_config_json,
  salesroom: CalEventParser.salesroom_config_json,
  shimmervideo: CalEventParser.config$2,
  signal: CalEventParser.signal_config_json,
  sirius_video: CalEventParser.sirius_video_config_json,
  skype: CalEventParser.skype_config_json,
  sylapsvideo: CalEventParser.config$3,
  tandemvideo: CalEventParser.metadata$4,
  telegram: CalEventParser.appConfig$2,
  "booking-pages-tag": CalEventParser.booking_pages_tag_config_json,
  "event-type-location-video-static": CalEventParser.event_type_location_video_static_config_json,
  twipla: CalEventParser.twipla_config_json,
  umami: CalEventParser.umami_config_json,
  webex: CalEventParser.config$4,
  whatsapp: CalEventParser.whatsapp_config_json,
  whereby: CalEventParser.whereby_config_json,
  zoomvideo: CalEventParser.metadata$5
};
const appStoreMetadata = {};
for (const [key, value] of Object.entries(appStoreMetadata$1)) {
  appStoreMetadata[key] = CalEventParser.getNormalizedAppMetadata(value);
}
const DailyLocationType = "integrations:daily";
const MeetLocationType = "integrations:google:meet";
const OrganizerDefaultConferencingAppType = "conferencing";
var DefaultEventLocationTypeEnum = /* @__PURE__ */ ((DefaultEventLocationTypeEnum2) => {
  DefaultEventLocationTypeEnum2["AttendeeInPerson"] = "attendeeInPerson";
  DefaultEventLocationTypeEnum2["InPerson"] = "inPerson";
  DefaultEventLocationTypeEnum2["Phone"] = "phone";
  DefaultEventLocationTypeEnum2["UserPhone"] = "userPhone";
  DefaultEventLocationTypeEnum2["Link"] = "link";
  DefaultEventLocationTypeEnum2["Conferencing"] = "conferencing";
  DefaultEventLocationTypeEnum2["SomewhereElse"] = "somewhereElse";
  return DefaultEventLocationTypeEnum2;
})(DefaultEventLocationTypeEnum || {});
const defaultLocations = [
  {
    default: true,
    type: "attendeeInPerson",
    label: "in_person_attendee_address",
    variable: "address",
    organizerInputType: null,
    messageForOrganizer: "Cal will ask your invitee to enter an address before scheduling.",
    attendeeInputType: "attendeeAddress",
    attendeeInputPlaceholder: "enter_address",
    defaultValueVariable: "attendeeAddress",
    iconUrl: "/map-pin-dark.svg",
    category: "in person",
    linkType: "static"
  },
  {
    default: true,
    type: "somewhereElse",
    label: "custom_attendee_location",
    variable: "address",
    organizerInputType: null,
    messageForOrganizer: "Cal will ask your invitee to enter any location before scheduling.",
    attendeeInputType: "somewhereElse",
    attendeeInputPlaceholder: "any_location",
    defaultValueVariable: "somewhereElse",
    iconUrl: "/message-pin.svg",
    category: "other",
    linkType: "static"
  },
  {
    default: true,
    type: "inPerson",
    label: "in_person",
    organizerInputType: "text",
    messageForOrganizer: "Provide an Address or Place",
    // HACK:
    variable: "locationAddress",
    defaultValueVariable: "address",
    iconUrl: "/map-pin-dark.svg",
    category: "in person",
    linkType: "static"
  },
  {
    default: true,
    type: "conferencing",
    iconUrl: "/link.svg",
    organizerInputType: null,
    label: "organizer_default_conferencing_app",
    variable: "hostDefault",
    defaultValueVariable: "hostDefault",
    category: "conferencing",
    messageForOrganizer: "",
    linkType: "static"
  },
  {
    default: true,
    type: "link",
    label: "link_meeting",
    organizerInputType: "text",
    variable: "locationLink",
    messageForOrganizer: "Provide a Meeting Link",
    defaultValueVariable: "link",
    iconUrl: "/link.svg",
    category: "other",
    linkType: "static"
  },
  {
    default: true,
    type: "phone",
    label: "attendee_phone_number",
    variable: "phone",
    organizerInputType: null,
    attendeeInputType: "phone",
    attendeeInputPlaceholder: `enter_phone_number`,
    defaultValueVariable: "phone",
    messageForOrganizer: "Cal will ask your invitee to enter a phone number before scheduling.",
    // This isn't inputType phone because organizer doesn't need to provide it.
    // inputType: "phone"
    iconUrl: "/phone.svg",
    category: "phone",
    linkType: "static"
  },
  {
    default: true,
    type: "userPhone",
    label: "organizer_phone_number",
    messageForOrganizer: "Provide your phone number",
    organizerInputType: "phone",
    variable: "locationPhoneNumber",
    defaultValueVariable: "hostPhoneNumber",
    iconUrl: "/phone.svg",
    category: "phone",
    linkType: "static"
  }
];
const AppStoreLocationType = {};
const locationsFromApps = [];
for (const [appName, meta] of Object.entries(appStoreMetadata)) {
  const location = meta.appData?.location;
  if (location) {
    for (const [key, value] of Object.entries(location)) {
      if (typeof value === "string") {
        location[key] = value.replace(/{SLUG}/g, meta.slug).replace(/{TITLE}/g, meta.name);
      }
    }
    const newLocation = {
      ...location,
      messageForOrganizer: location.messageForOrganizer || `Set ${location.label} link`,
      iconUrl: meta.logo,
      // For All event location apps, locationLink is where we store the input
      // TODO: locationLink and link seems redundant. We can modify the code to keep just one of them.
      variable: location.variable || "locationLink",
      defaultValueVariable: location.defaultValueVariable || "link"
    };
    if (newLocation.linkType === "static") {
      newLocation.organizerInputType = location.organizerInputType || "text";
      if (newLocation.organizerInputPlaceholder?.match(/https?:\/\//)) {
        newLocation.organizerInputPlaceholder = ` ${newLocation.organizerInputPlaceholder}`;
      }
    } else {
      newLocation.organizerInputType = null;
    }
    AppStoreLocationType[appName] = newLocation.type;
    locationsFromApps.push({
      ...newLocation
    });
  }
}
const locations = [...defaultLocations, ...locationsFromApps];
const getLocationFromApp = (locationType) => locationsFromApps.find((l) => l.type === locationType);
const getEventLocationType = (locationType) => locations.find((l) => l.type === locationType);
const getStaticLinkLocationByValue = (value) => {
  if (!value) {
    return null;
  }
  return locations.find((l) => {
    if (l.default || l.linkType == "dynamic" || !l.urlRegExp) {
      return;
    }
    return new RegExp(l.urlRegExp).test(value);
  });
};
const guessEventLocationType = (locationTypeOrValue) => getEventLocationType(locationTypeOrValue) || getStaticLinkLocationByValue(locationTypeOrValue);
({ ...DefaultEventLocationTypeEnum, ...AppStoreLocationType });
const privacyFilteredLocations = (locations2) => {
  const locationsAfterPrivacyFilter = locations2.map((location) => {
    const eventLocationType = getEventLocationType(location.type);
    if (!eventLocationType) {
      index.logger.debug(`Couldn't find location type. App might be uninstalled: ${location.type} `);
    }
    if (location.displayLocationPublicly || !eventLocationType) {
      return location;
    } else {
      const { address: _1, link: _2, hostPhoneNumber: _3, ...privacyFilteredLocation } = location;
      index.logger.debug("Applied Privacy Filter", location, privacyFilteredLocation);
      return privacyFilteredLocation;
    }
  });
  return locationsAfterPrivacyFilter;
};
const getHumanReadableLocationValue = (linkValue, translationFunction) => {
  if (!linkValue) {
    return translationFunction("no_location");
  }
  const eventLocationType = getEventLocationType(linkValue);
  const isDefault = eventLocationType?.default;
  if (eventLocationType) {
    return isDefault ? translationFunction(eventLocationType.label) : `${eventLocationType.label}`;
  }
  return linkValue || "";
};
const getLocationValueForDB = (bookingLocationTypeOrValue, eventLocations) => {
  let bookingLocation = bookingLocationTypeOrValue;
  let conferenceCredentialId = void 0;
  eventLocations.forEach((location) => {
    if (location.type === bookingLocationTypeOrValue) {
      const eventLocationType = getEventLocationType(bookingLocationTypeOrValue);
      conferenceCredentialId = location.credentialId;
      if (!eventLocationType) {
        return;
      }
      if (!eventLocationType.default && eventLocationType.linkType === "dynamic") {
        return;
      }
      bookingLocation = location[eventLocationType.defaultValueVariable] || bookingLocation;
    }
  });
  if (bookingLocation.trim().length === 0) {
    bookingLocation = DailyLocationType;
  }
  return { bookingLocation, conferenceCredentialId };
};
exports.AppStoreLocationType = AppStoreLocationType;
exports.DailyLocationType = DailyLocationType;
exports.MeetLocationType = MeetLocationType;
exports.OrganizerDefaultConferencingAppType = OrganizerDefaultConferencingAppType;
exports.defaultLocations = defaultLocations;
exports.getHumanReadableLocationValue = getHumanReadableLocationValue;
exports.getLocationFromApp = getLocationFromApp;
exports.getLocationValueForDB = getLocationValueForDB;
exports.guessEventLocationType = guessEventLocationType;
exports.privacyFilteredLocations = privacyFilteredLocations;
