/**
 * Central language-aware route map.
 * Single source of truth for all internal navigation.
 * 
 * Usage:
 *   import { getLocalizedPath } from "@/lib/routes";
 *   const href = getLocalizedPath("vrTraining", i18n.language);
 */

export type RouteKey =
  | "home"
  | "solutions"
  | "vrTraining"
  | "vrShowroom"
  | "vrExperiences"
  | "vrGamesEvents"
  | "vrSimulering"
  | "vrSjukvard"
  | "vrIndustri"
  | "vrForetagsutbildning"
  | "vrDomstolUtbildning"
  | "aiSolutions"
  | "aiReception"
  | "aiAutomation"
  | "aiVrTraining"
  | "aiMarketing"
  | "aiStrategy"
  | "aiTrainingSolutions"
  | "vrTrainingHealthcarePublicSector"
  | "vrAiGuideEnterpriseTraining"
  | "hologramSolutions"
  | "holobox"
  | "holospin"
  | "holonet"
  | "invisibleScreen"
  | "hologramPyramid"
  | "hologramProduction"
  | "hologramEvents"
  | "hologramRetail"
  | "hologramBrandActivation"
  | "hologramProductLaunch"
  | "hologramTechnology"
  | "hyrHologram"
  | "magicMirror"
  | "massaEvent"
  | "cases"
  | "news"
  | "about"
  | "contact"
  // Industry / Branscher
  | "industryEventExpo"
  | "industryRetail"
  | "industryTraining"
  | "industryIndustrial"
  | "industryPublicSector"
  | "experienceAdvantage";

const routeMap: Record<RouteKey, { sv: string; en: string }> = {
  home:                 { sv: "/",                        en: "/en" },
  solutions:            { sv: "/tjanster",                en: "/solutions" },

  // VR
  vrTraining:           { sv: "/vr-utbildning",           en: "/vr" },
  vrShowroom:           { sv: "/vr-showroom",             en: "/vr-showrooms" },
  vrExperiences:        { sv: "/vr-upplevelser",          en: "/vr-experiences" },
  vrGamesEvents:        { sv: "/vr-spel-events",          en: "/en/vr-games-events" },
  vrSimulering:         { sv: "/vr-simulering",           en: "/en/vr-simulation" },
  vrSjukvard:           { sv: "/vr-sjukvard",             en: "/en/vr-healthcare" },
  vrIndustri:           { sv: "/vr-industri",             en: "/en/vr-industry" },
  vrForetagsutbildning: { sv: "/vr-foretagsutbildning",   en: "/enterprise-vr-training" },
  vrDomstolUtbildning:  { sv: "/offentlig-sektor",         en: "/en/public-sector-vr-training" },

  // AI
  aiSolutions:          { sv: "/ai-losningar",            en: "/ai" },
  aiReception:          { sv: "/ai-reception-concierge",   en: "/ai-reception-concierge" },
  aiAutomation:         { sv: "/ai-automation-enterprise", en: "/ai-automation-enterprise" },
  aiVrTraining:         { sv: "/ai-vr-training",           en: "/ai-vr-training" },
  aiMarketing:          { sv: "/ai-marketing-interactive", en: "/en/ai-marketing-interactive" },
  aiStrategy:           { sv: "/ai-strategy",              en: "/en/ai-strategy" },
  aiTrainingSolutions:  { sv: "/ai-utbildningslosningar",  en: "/ai-training-solutions" },
  vrTrainingHealthcarePublicSector: { sv: "/vr-utbildning-vard-offentlig-sektor", en: "/vr-training-healthcare-public-sector" },
  vrAiGuideEnterpriseTraining: { sv: "/vr-ai-losningar-foretagsutbildning", en: "/best-vr-ai-solutions-enterprise-training" },

  // Hologram
  hologramSolutions:    { sv: "/hologramlosningar",        en: "/hologram" },
  holobox:              { sv: "/holobox",                  en: "/holobox" },
  holospin:             { sv: "/holospin",                 en: "/holospin" },
  holonet:              { sv: "/holonet",                  en: "/holonet" },
  invisibleScreen:      { sv: "/invisible-screen",         en: "/invisible-screen" },
  hologramPyramid:      { sv: "/3d-hologram",              en: "/3d-hologram" },
  hologramProduction:   { sv: "/hologramproduktion",       en: "/en/hologram-production" },
  hologramEvents:       { sv: "/hologram-events",          en: "/en/hologram-events" },
  hologramRetail:       { sv: "/hologram-retail",          en: "/en/hologram-retail" },
  hologramBrandActivation: { sv: "/hologram-brand-activation", en: "/en/hologram-brand-activation" },
  hologramProductLaunch: { sv: "/hologram-product-launch",  en: "/en/hologram-product-launch" },
  hologramTechnology:   { sv: "/hologramdisplayer",        en: "/hologram-technology" },
  hyrHologram:          { sv: "/hyr-hologram",             en: "/en/rent-hologram" },
  magicMirror:          { sv: "/magic-mirror",             en: "/magic-mirror" },
  massaEvent:           { sv: "/massa-event",              en: "/en/trade-show-events" },
  experienceAdvantage:  { sv: "/the-experience-advantage",  en: "/en/the-experience-advantage" },

  // Company
  cases:                { sv: "/cases",                    en: "/en/cases" },
  news:                 { sv: "/nyheter",                  en: "/en/news" },
  about:                { sv: "/om-oss",                   en: "/about" },
  contact:              { sv: "/kontakt",                  en: "/contact" },

  // Industry / Branscher
  industryEventExpo:    { sv: "/branscher/massor-event",   en: "/event-expo" },
  industryRetail:       { sv: "/branscher/retail-varumarken", en: "/retail" },
  industryTraining:     { sv: "/vr-utbildning",            en: "/vr" },
  industryIndustrial:   { sv: "/vr-industri",              en: "/en/vr-industry" },
  industryPublicSector: { sv: "/branscher/offentlig-sektor-myndigheter", en: "/public-sector" },
};

/**
 * Returns the correct URL for the given route key and language.
 * Falls back to English if language is not "sv".
 */
export function getLocalizedPath(key: RouteKey, lang: string): string {
  const entry = routeMap[key];
  if (!entry) {
    console.warn(`[routes] Unknown route key: ${key}`);
    return "/";
  }
  return lang === "sv" ? entry.sv : entry.en;
}

/**
 * All route paths that belong to solution pages (for active-state detection).
 */
export const allSolutionPaths: string[] = Object.values(routeMap)
  .filter((_, i) => {
    const keys = Object.keys(routeMap) as RouteKey[];
    const k = keys[i];
    return k !== "home" && k !== "cases" && k !== "news" && k !== "about" && k !== "contact"
      && !k.startsWith("industry");
  })
  .flatMap((entry) => {
    const paths = [entry.sv, entry.en];
    return [...new Set(paths)];
  });

/**
 * All industry/branscher paths for active-state detection.
 */
export const allIndustryPaths: string[] = Object.entries(routeMap)
  .filter(([k]) => k.startsWith("industry"))
  .flatMap(([, entry]) => {
    const paths = [entry.sv, entry.en];
    return [...new Set(paths)];
  });
