const storesPath = "/product-page/";
const storesPath2 = "/stores/";
const bookingsPath = "/bookings-checkout/";
const bookingsPath2 = "/service-page/";
const eventsPath = "/event-details/";
const eventsPath2 = "/events/";
const eventsPath3 = "/event-details-registration/";
const UNIVERSAL_DELIMITER = "?d=";
const UNIVERSAL_REGEX = /^https:\/\/www.wix.app/;
const getWebUrlFromUniversalUrl = (url) => url.split(UNIVERSAL_DELIMITER)[1];
const getVerticalRelativePath = (webUrl) => {
  const position = Math.max(
    webUrl.indexOf(storesPath),
    webUrl.indexOf(storesPath2),
    webUrl.indexOf(bookingsPath),
    webUrl.indexOf(bookingsPath2),
    webUrl.indexOf(eventsPath),
    webUrl.indexOf(eventsPath2),
    webUrl.indexOf(eventsPath3)
  );
  return position >= 0 ? webUrl.slice(position) : void 0;
};
const removeLastSlashFromUrl = (url) => url.replace(/\/$/, "");
const replaceWebUrlInsideUniversalUrl = (universalUrl, webUrl) => {
  const base = universalUrl.split(UNIVERSAL_DELIMITER)[0];
  return `${base}${UNIVERSAL_DELIMITER}${webUrl}`;
};
const changeBaseUrl = (url, baseUrl) => {
  const isUniversalUrl = url.match(UNIVERSAL_REGEX);
  const oldWebUrl = isUniversalUrl ? getWebUrlFromUniversalUrl(url) : url;
  const path = getVerticalRelativePath(oldWebUrl);
  const webUrl = path !== void 0 ? removeLastSlashFromUrl(baseUrl) + path : oldWebUrl;
  return isUniversalUrl ? replaceWebUrlInsideUniversalUrl(url, webUrl) : webUrl;
};
export {
  changeBaseUrl
};
//# sourceMappingURL=change-base-url.js.map
