import { defaultLocale } from "@/i18n.config";

export function removeBaseUrl(url, lang) {
  // const baseUrlPattern = /^https?:\/\/[a-z\:0-9.]+/;
  const baseUrlPattern = /(https?:\/\/)?ebe3-2804-14d-5c51-9956-28e5-6897-7d43-43a4\.ngrok-free\.app/;
  let result = "";
  const match = baseUrlPattern.exec(url);

  if (match !== null) {
    result = match[0];
  }

  if (result?.length > 0) {
    url = url.replace(result, '');
  }

  if (lang?.length && lang !== defaultLocale) {
    url = `/${lang}/${url}`
  }

  return url;
};
