/**
 * Site patterns: mainwhite.svg (white sections) · main.svg (green edge frames)
 */

export type TopoPatternId = "topo-main" | "none";

/** White sections — full mainwhite pattern */
export type TopoSectionTone = "light" | "green";

export const SITE_TOPO_PATTERN = "topo-main" as const satisfies TopoPatternId;

export const MAIN_WHITE_PATTERN_SRC = "/patterns/mainwhite.svg";
export const MAIN_GREEN_PATTERN_SRC = "/patterns/main.svg";

export { BRAND_GREEN } from "@/content/brand-colors";

export type TopoPatternAsset = {
  src: string;
  positions: [string, string];
  defaultOpacity: number;
};

export const MAIN_WHITE_ASSET: TopoPatternAsset = {
  src: MAIN_WHITE_PATTERN_SRC,
  positions: ["50% 46%", "42% 58%"],
  defaultOpacity: 0.42,
};

export const MAIN_GREEN_EDGE_ASSET: TopoPatternAsset = {
  src: MAIN_GREEN_PATTERN_SRC,
  positions: ["left center", "right center"],
  defaultOpacity: 0.58,
};

export function getAssetForTone(tone: TopoSectionTone): TopoPatternAsset {
  return tone === "light" ? MAIN_WHITE_ASSET : MAIN_GREEN_EDGE_ASSET;
}

export function toneUsesEdgeLayout(tone: TopoSectionTone): boolean {
  return tone === "green";
}

export const PAGE_TOPO_PATTERN: Record<string, TopoPatternId> = {
  home: SITE_TOPO_PATTERN,
  program: SITE_TOPO_PATTERN,
  speakers: SITE_TOPO_PATTERN,
  partners: SITE_TOPO_PATTERN,
  pitch: SITE_TOPO_PATTERN,
  exhibit: SITE_TOPO_PATTERN,
  sponsor: SITE_TOPO_PATTERN,
  contact: SITE_TOPO_PATTERN,
  payment: SITE_TOPO_PATTERN,
  "payment-success": SITE_TOPO_PATTERN,
  privacy: SITE_TOPO_PATTERN,
};

export function getPageTopoPattern(pathname: string): TopoPatternId {
  if (pathname === "/") return PAGE_TOPO_PATTERN.home;
  if (pathname.startsWith("/program")) return PAGE_TOPO_PATTERN.program;
  if (pathname.startsWith("/speakers")) return PAGE_TOPO_PATTERN.speakers;
  if (pathname.startsWith("/partners")) return PAGE_TOPO_PATTERN.partners;
  if (pathname.startsWith("/pitch-competition")) return PAGE_TOPO_PATTERN.pitch;
  if (pathname.startsWith("/exhibit")) return PAGE_TOPO_PATTERN.exhibit;
  if (pathname.startsWith("/sponsor")) return PAGE_TOPO_PATTERN.sponsor;
  if (pathname.startsWith("/contact")) return PAGE_TOPO_PATTERN.contact;
  if (pathname === "/payment/success") return PAGE_TOPO_PATTERN["payment-success"];
  if (pathname.startsWith("/payment")) return PAGE_TOPO_PATTERN.payment;
  if (pathname.startsWith("/privacy")) return PAGE_TOPO_PATTERN.privacy;
  return SITE_TOPO_PATTERN;
}

export function resolveTopoPattern(
  pattern: TopoPatternId | undefined,
  fallback: TopoPatternId = SITE_TOPO_PATTERN
): Exclude<TopoPatternId, "none"> | null {
  const resolved = pattern && pattern !== "none" ? pattern : fallback;
  if (resolved === "none") return null;
  return "topo-main";
}

/** Map section variant → pattern tone (white = light, muted/inverse = green) */
export function toneFromSectionVariant(
  variant: "default" | "muted" | "inverse"
): TopoSectionTone {
  return variant === "default" ? "light" : "green";
}
