"use client";
import {
  __esm
} from "./chunk-GGWZFCYS.js";

// src/platform-domains.ts
function byKey(key) {
  return PLATFORM_DOMAINS.find((e) => e.key === key);
}
function envOverrideFor(key) {
  const envVar = byKey(key)?.envVar;
  if (!envVar) return null;
  return ENV_OVERRIDES[envVar] || null;
}
function ensureScheme(url) {
  const trimmed = url.trim();
  if (/^[a-z][a-z0-9+.-]*:\/\//i.test(trimmed)) return trimmed;
  return `https://${trimmed.replace(/^\/+/, "")}`;
}
function getPlatformProductionUrl(platform) {
  const resolved = envOverrideFor(platform) ?? byKey(platform)?.defaultUrl ?? envOverrideFor("flamingo") ?? "https://www.flamingo.run";
  return ensureScheme(resolved);
}
function hostOf(value) {
  if (!value) return null;
  try {
    return new URL(value).hostname.toLowerCase();
  } catch {
    return null;
  }
}
function expandWwwApex(host) {
  if (host.startsWith("www.")) return [host, host.slice(4)];
  if (host.split(".").length === 2) return [host, `www.${host}`];
  return [host];
}
function toRegistrableBaseDomain(host) {
  const parts = host.split(".");
  if (parts.length >= 2) return parts.slice(-2).join(".");
  return void 0;
}
function aliasHostsOf(key) {
  return byKey(key)?.aliasHostnames ?? [];
}
function hostsForEntry(entry, opts) {
  const resolved = hostOf(getPlatformProductionUrl(entry.key));
  const hosts = resolved ? expandWwwApex(resolved) : [];
  if (opts.includeAliases) hosts.push(...aliasHostsOf(entry.key));
  return hosts;
}
function getPlatformByHostname(hostname) {
  const host = hostname.toLowerCase();
  for (const entry of PLATFORM_DOMAINS) {
    if (entry.pseudo) continue;
    if (hostsForEntry(entry, { includeAliases: true }).includes(host)) return entry.key;
  }
  return null;
}
function isPreviewHost(hostname) {
  return hostname.endsWith(".vercel.app");
}
function getAllPlatformBaseDomains() {
  if (typeof window === "undefined") return [];
  const hostname = window.location.hostname;
  if (hostname === "localhost" || hostname === "127.0.0.1" || hostname.startsWith("127.")) {
    return [];
  }
  const previewEnv = process.env.VERCEL_ENV === "preview" || process.env.NEXT_PUBLIC_VERCEL_ENV === "preview" || isPreviewHost(hostname);
  if (previewEnv) {
    return [".vercel.app", "vercel.app"];
  }
  const baseDomains = /* @__PURE__ */ new Set();
  for (const entry of PLATFORM_DOMAINS) {
    if (entry.pseudo) continue;
    const host = hostOf(getPlatformProductionUrl(entry.key));
    if (!host) continue;
    const base = toRegistrableBaseDomain(host);
    if (base) {
      baseDomains.add(`.${base}`);
      baseDomains.add(base);
    }
  }
  return Array.from(baseDomains);
}
var PLATFORM_DOMAINS, ENV_OVERRIDES, _orderIdx;
var init_platform_domains = __esm({
  "src/platform-domains.ts"() {
    "use strict";
    PLATFORM_DOMAINS = [
      { key: "marketing-hub", defaultUrl: "https://marketing-hub.flamingo.so", envVar: "NEXT_PUBLIC_MARKETING_HUB_URL" },
      { key: "company-hub", defaultUrl: "https://company-hub.flamingo.so", envVar: "NEXT_PUBLIC_COMPANY_HUB_URL" },
      { key: "product-hub", defaultUrl: "https://product-hub.flamingo.so", envVar: "NEXT_PUBLIC_PRODUCT_HUB_URL" },
      { key: "revenue-hub", defaultUrl: "https://revenue-hub.flamingo.so", envVar: "NEXT_PUBLIC_REVENUE_HUB_URL" },
      { key: "people-hub", defaultUrl: "https://people-hub.flamingo.so", envVar: "NEXT_PUBLIC_PEOPLE_HUB_URL" },
      { key: "openmsp", defaultUrl: "https://www.openmsp.ai", envVar: "NEXT_PUBLIC_OPENMSP_URL" },
      // ORDERING INVARIANT (first-wins, load-bearing): `flamingo` MUST precede `flamingo-teaser` + `universal`.
      // All three resolve to www.flamingo.run; the reverse index is first-wins → flamingo claims the shared host,
      // teaser keeps only its unique flamingo.cx aliases, universal contributes no unique host.
      // ⚠️ DO NOT REORDER — enforced by the module-load self-check at the bottom of this file.
      { key: "flamingo", defaultUrl: "https://www.flamingo.run", envVar: "NEXT_PUBLIC_FLAMINGO_URL" },
      { key: "tmcg", defaultUrl: "https://www.tmcg.miami", envVar: "NEXT_PUBLIC_TMCG_URL" },
      { key: "flamingo-teaser", defaultUrl: "https://www.flamingo.run", envVar: "NEXT_PUBLIC_FLAMINGO_URL", aliasHostnames: ["flamingo.cx", "www.flamingo.cx"] },
      { key: "openframe", defaultUrl: "https://openframe.ai", envVar: "NEXT_PUBLIC_OPENFRAME_URL", aliasHostnames: ["openframe.ai", "www.openframe.ai", "hub.openframe.ai"] },
      { key: "openframe-dashboard", defaultUrl: "https://openframe.ai", envVar: "NEXT_PUBLIC_OPENFRAME_DASHBOARD_URL", pseudo: true },
      { key: "universal", defaultUrl: "https://www.flamingo.run", envVar: "NEXT_PUBLIC_FLAMINGO_URL" }
    ];
    ENV_OVERRIDES = {
      NEXT_PUBLIC_MARKETING_HUB_URL: process.env.NEXT_PUBLIC_MARKETING_HUB_URL,
      NEXT_PUBLIC_COMPANY_HUB_URL: process.env.NEXT_PUBLIC_COMPANY_HUB_URL,
      NEXT_PUBLIC_PRODUCT_HUB_URL: process.env.NEXT_PUBLIC_PRODUCT_HUB_URL,
      NEXT_PUBLIC_REVENUE_HUB_URL: process.env.NEXT_PUBLIC_REVENUE_HUB_URL,
      NEXT_PUBLIC_PEOPLE_HUB_URL: process.env.NEXT_PUBLIC_PEOPLE_HUB_URL,
      NEXT_PUBLIC_OPENMSP_URL: process.env.NEXT_PUBLIC_OPENMSP_URL,
      NEXT_PUBLIC_FLAMINGO_URL: process.env.NEXT_PUBLIC_FLAMINGO_URL,
      NEXT_PUBLIC_TMCG_URL: process.env.NEXT_PUBLIC_TMCG_URL,
      NEXT_PUBLIC_OPENFRAME_URL: process.env.NEXT_PUBLIC_OPENFRAME_URL,
      NEXT_PUBLIC_OPENFRAME_DASHBOARD_URL: process.env.NEXT_PUBLIC_OPENFRAME_DASHBOARD_URL
    };
    _orderIdx = (k) => PLATFORM_DOMAINS.findIndex((e) => e.key === k);
    if (_orderIdx("flamingo") > _orderIdx("flamingo-teaser") || _orderIdx("flamingo") > _orderIdx("universal") || getPlatformByHostname("flamingo.cx") !== "flamingo-teaser" || getPlatformByHostname("hub.openframe.ai") !== "openframe") {
      console.error(
        "[platform-domains] \u26A0\uFE0F PLATFORM_DOMAINS ordering invariant violated \u2014 `flamingo` must precede `flamingo-teaser`/`universal`, and the openframe/teaser aliases must be intact. Do not reorder the table."
      );
    }
  }
});

// src/utils/cn.ts
import { clsx } from "clsx";
import { extendTailwindMerge } from "tailwind-merge";
function cn(...inputs) {
  return twMerge(clsx(inputs));
}
function getBaseUrl(platform) {
  if (process.env.NODE_ENV !== "production") {
    return process.env.NEXT_PUBLIC_DEV_URL || "http://localhost:3000";
  }
  if (platform) {
    return getPlatformProductionUrl(platform);
  }
  if (process.env.VERCEL_PROJECT_PRODUCTION_URL) {
    return `https://${process.env.VERCEL_PROJECT_PRODUCTION_URL}`;
  }
  return getPlatformProductionUrl(process.env.NEXT_PUBLIC_APP_TYPE || "openmsp");
}
var twMerge;
var init_cn = __esm({
  "src/utils/cn.ts"() {
    "use strict";
    init_platform_domains();
    twMerge = extendTailwindMerge({
      extend: {
        classGroups: {
          "ods-typography": ["text-h1", "text-h2", "text-h3", "text-h4", "text-h5", "text-h6"]
        }
      }
    });
  }
});

export {
  getPlatformProductionUrl,
  getAllPlatformBaseDomains,
  init_platform_domains,
  cn,
  getBaseUrl,
  init_cn
};
//# sourceMappingURL=chunk-XTCBRQN2.js.map