export function getTenantCode() {
  const match = window.location.pathname.match(/^\/t\/([^/]+)(?:\/|$)/);
  return match ? match[1] : "";
}

export function resolveTenantCode(route) {
  if (route && route.params && route.params.tenantCode) {
    return String(route.params.tenantCode);
  }
  return getTenantCode();
}

export function tenantPath(path, route) {
  const tenantCode = resolveTenantCode(route);
  const base = tenantCode ? `/t/${tenantCode}` : "";
  const normalized = path.startsWith("/") ? path : `/${path}`;
  return `${base}${normalized}`;
}
