/* ============================================================================
   TALYA SMART 2027 — DATA MODEL
   The whole site is data-driven. Nothing about a Lab or a Problem is hardcoded
   in a screen; screens read from `PROBLEMS` and `LABS` and compose at runtime.
   ============================================================================ */

/* ---- PROBLEMS -------------------------------------------------------------
   How CEOs actually think — symptoms, not sectors. Each problem carries the
   word that names the resulting "OS", a one-line symptom, and the levers it
   pulls inside the simulator. ------------------------------------------------ */
const PROBLEMS = [
  {
    key: "growth",
    label: "Growth",
    osWord: "Growth",
    symptom: "Growth has plateaued and the old playbook stopped working.",
    levers: { revenue: 1.0, savings: 0.55, headcount: 0.15 },
    projects: ["Demand Intelligence", "Visibility Engine", "Conversion AI", "Retention Model"],
  },
  {
    key: "sales",
    label: "Sales",
    osWord: "Revenue",
    symptom: "Pipeline is unpredictable and every deal costs too much to win.",
    levers: { revenue: 1.0, savings: 0.5, headcount: 0.1 },
    projects: ["Lead Scoring AI", "Pricing Intelligence", "Quote Automation", "Win-Loss Model"],
  },
  {
    key: "operations",
    label: "Operations",
    osWord: "Automation",
    symptom: "40–60% of the workday is spent on work software should already do.",
    levers: { revenue: 0.5, savings: 1.0, headcount: 0.45 },
    projects: ["Workflow Automation", "Document AI", "Scheduling AI", "Ops Copilot"],
  },
  {
    key: "service",
    label: "Customer Service",
    osWord: "Service",
    symptom: "Support volume scales with headcount, and customers feel it.",
    levers: { revenue: 0.45, savings: 0.95, headcount: 0.4 },
    projects: ["AI Front Desk", "Resolution Engine", "Sentiment Routing", "Self-Serve AI"],
  },
  {
    key: "staffing",
    label: "Staffing",
    osWord: "Workforce",
    symptom: "You can't hire fast enough, and the talent you have is overloaded.",
    levers: { revenue: 0.4, savings: 0.85, headcount: 0.6 },
    projects: ["Workforce Copilot", "Onboarding AI", "Knowledge Engine", "Capacity Model"],
  },
  {
    key: "supply",
    label: "Supply Chain",
    osWord: "Supply Chain",
    symptom: "Inventory, demand, and logistics drift out of sync every week.",
    levers: { revenue: 0.6, savings: 0.95, headcount: 0.3 },
    projects: ["Demand Forecasting", "Inventory AI", "Route Optimization", "Supplier Intelligence"],
  },
  {
    key: "technology",
    label: "Technology",
    osWord: "Platform",
    symptom: "Your systems can't keep up with what the business now needs.",
    levers: { revenue: 0.7, savings: 0.75, headcount: 0.25 },
    projects: ["AI Platform Layer", "Data Unification", "Integration Mesh", "Inference Infra"],
  },
  {
    key: "unknown",
    label: "Don't Know",
    osWord: "Transformation",
    symptom: "Something is shifting in your industry — you feel it before you can name it.",
    levers: { revenue: 0.7, savings: 0.75, headcount: 0.35 },
    projects: ["Opportunity Diagnostic", "Quick-Win Automation", "AI Roadmap", "Pilot Program"],
  },
];

/* ---- LABS -----------------------------------------------------------------
   The 8 Transformation Labs, grounded in the real Talya Smart portfolio.
   accent  → CSS var --accent for this lab
   vision  → the "by 2030, every X becomes…" future framing
   solutions → 4 named AI products
   doNothing → 4-stage decay timeline (2026 → 2030) + a cost-of-delay multiple
   sim     → heuristic baseline used by "Your Company After AI"
   --------------------------------------------------------------------------- */
const LABS = {
  ecommerce: {
    key: "ecommerce",
    name: "Ecommerce Intelligence Lab",
    short: "Ecommerce",
    accent: "#E879F9",
    exemplars: ["Shopify", "Amazon Marketplace"],
    vision: "every online store becomes an AI storefront, a media engine, and a logistics brain",
    unit: "store",
    solutions: [
      { name: "Storefront AI", desc: "A storefront that merchandises itself to every shopper in real time." },
      { name: "Conversion AI", desc: "Turn browsers into buyers with checkout and on-site CRO that tunes itself." },
      { name: "Acquisition AI", desc: "Generate, test, and buy performance creative that finds your next customer." },
      { name: "Retention AI", desc: "Predict churn, automate the lifecycle, and grow LTV on autopilot." },
    ],
    doNothing: [
      { year: "2026", title: "Stores compete on ad spend and hand-built merchandising.", level: 0.18 },
      { year: "2027", title: "AI storefronts personalize better than your best merchandiser.", level: 0.42 },
      { year: "2028", title: "AI ad engines win the auction and the customer.", level: 0.7 },
      { year: "2030", title: "AI-native commerce brands own demand end to end.", level: 1.0 },
    ],
    delayMultiple: "2.7×",
    sim: { baseMargin: 10, futureMargin: 24, revLift: 0.44, save: 0.38 },
  },
  retail: {
    key: "retail",
    name: "Retail Intelligence Lab",
    short: "Retail",
    accent: "#FB7185",
    exemplars: ["KolayHalal", "TurkishBrands"],
    vision: "every retailer becomes a marketplace, a media network, and a pricing engine",
    unit: "store",
    solutions: [
      { name: "Commerce AI", desc: "A storefront that merchandises itself to every shopper in real time." },
      { name: "Inventory AI", desc: "Forecast demand to the SKU and never tie up cash in dead stock again." },
      { name: "Marketplace AI", desc: "List, optimize, and reprice across every channel from one brain." },
      { name: "Pricing AI", desc: "Margin-aware dynamic pricing that reacts to demand and competitors hourly." },
    ],
    doNothing: [
      { year: "2026", title: "Shelves and channels are managed by hand.", level: 0.2 },
      { year: "2027", title: "AI merchandising outsells your best buyer.", level: 0.45 },
      { year: "2028", title: "Dynamic pricing engines undercut you on every SKU.", level: 0.72 },
      { year: "2030", title: "AI-native retailers own discovery and margin.", level: 1.0 },
    ],
    delayMultiple: "2.6×",
    sim: { baseMargin: 9, futureMargin: 22, revLift: 0.38, save: 0.36 },
  },
  logistics: {
    key: "logistics",
    name: "Logistics Intelligence Lab",
    short: "Logistics",
    accent: "#34D399",
    exemplars: ["ShipScanner", "Auto Baba"],
    vision: "every carrier becomes an autonomous routing, freight, and customs network",
    unit: "fleet",
    solutions: [
      { name: "Route AI", desc: "Continuously re-optimized routes that cut miles, fuel, and idle time." },
      { name: "Freight AI", desc: "Match loads, predict capacity, and quote freight in seconds." },
      { name: "Customs AI", desc: "Classify, document, and clear shipments without the paperwork drag." },
      { name: "Procurement AI", desc: "Source carriers and parts at the right price before you need them." },
    ],
    doNothing: [
      { year: "2026", title: "Routing and freight quoting run on spreadsheets and instinct.", level: 0.2 },
      { year: "2027", title: "AI dispatch undercuts your lanes on price and speed.", level: 0.46 },
      { year: "2028", title: "Autonomous freight networks lock in the best capacity.", level: 0.74 },
      { year: "2030", title: "Self-optimizing logistics platforms own the corridor.", level: 1.0 },
    ],
    delayMultiple: "3.1×",
    sim: { baseMargin: 8, futureMargin: 19, revLift: 0.34, save: 0.44 },
  },
  telecom: {
    key: "telecom",
    name: "Telecom Intelligence Lab",
    short: "Telecom",
    accent: "#22D3EE",
    exemplars: ["Lumen", "Akamai", "Tailscale-class infrastructure"],
    vision: "every network becomes a self-operating, inference-ready compute platform",
    unit: "network",
    solutions: [
      { name: "Edge AI", desc: "Push inference to the edge and turn latency into a product advantage." },
      { name: "AI Marketplaces", desc: "Monetize capacity by brokering compute, models, and bandwidth." },
      { name: "AI Networks", desc: "Self-healing operations that detect, route around, and resolve faults." },
      { name: "Inference Platforms", desc: "Serve models at carrier scale with predictable cost and uptime." },
    ],
    doNothing: [
      { year: "2026", title: "Networks run normally, operated by large teams.", level: 0.2 },
      { year: "2027", title: "AI takes over support and tier-1 operations.", level: 0.48 },
      { year: "2028", title: "AI runs network operations end to end.", level: 0.76 },
      { year: "2030", title: "Autonomous telecom platforms set the cost floor.", level: 1.0 },
    ],
    delayMultiple: "3.0×",
    sim: { baseMargin: 18, futureMargin: 34, revLift: 0.3, save: 0.5 },
  },
  service: {
    key: "service",
    name: "Service Business Lab",
    short: "Service",
    accent: "#E0B15E",
    exemplars: ["TSmart Home", "Joy Dry Cleaners"],
    vision: "every service business becomes a dispatch, scheduling, and support engine",
    unit: "business",
    solutions: [
      { name: "Scheduling AI", desc: "Book, confirm, and reschedule jobs without a single phone tag loop." },
      { name: "Dispatch AI", desc: "Route the right tech to the right job with live capacity awareness." },
      { name: "Customer Service AI", desc: "Answer, quote, and resolve around the clock in your brand voice." },
      { name: "Field Copilot", desc: "Put the whole playbook in every technician's pocket, on demand." },
    ],
    doNothing: [
      { year: "2026", title: "Jobs are booked and dispatched by hand.", level: 0.2 },
      { year: "2027", title: "AI front desks answer faster and never miss a call.", level: 0.45 },
      { year: "2028", title: "AI dispatch fills calendars competitors leave empty.", level: 0.72 },
      { year: "2030", title: "AI-run service brands own the neighborhood.", level: 1.0 },
    ],
    delayMultiple: "2.7×",
    sim: { baseMargin: 11, futureMargin: 26, revLift: 0.42, save: 0.4 },
  },
  distribution: {
    key: "distribution",
    name: "Distribution Intelligence Lab",
    short: "Distribution",
    accent: "#F59E0B",
    exemplars: ["TG Gourmet", "Food Distribution"],
    vision: "every distributor becomes a demand-planning and warehouse-automation engine",
    unit: "network",
    solutions: [
      { name: "Procurement AI", desc: "Buy at the right price, at the right time, with the right partner." },
      { name: "Warehouse AI", desc: "Slot, pick, and replenish with an operation that tunes itself." },
      { name: "Demand Planning", desc: "Forecast by SKU and lane so cash stops sitting on the floor." },
      { name: "Order Intelligence", desc: "Catch shrink, errors, and margin leaks before they ship." },
    ],
    doNothing: [
      { year: "2026", title: "Buying and planning lean on relationships and guesswork.", level: 0.2 },
      { year: "2027", title: "AI demand planning out-forecasts your best planner.", level: 0.46 },
      { year: "2028", title: "Automated warehouses set a cost you can't match.", level: 0.73 },
      { year: "2030", title: "AI-native distributors own the supply layer.", level: 1.0 },
    ],
    delayMultiple: "2.9×",
    sim: { baseMargin: 7, futureMargin: 17, revLift: 0.33, save: 0.43 },
  },
  realestate: {
    key: "realestate",
    name: "Real Estate Intelligence Lab",
    short: "Real Estate",
    accent: "#2DD4BF",
    exemplars: ["Commercial & residential portfolios"],
    vision: "every operator becomes a leasing, property, and construction intelligence engine",
    unit: "portfolio",
    solutions: [
      { name: "Leasing AI", desc: "Qualify, tour, and convert leads while your team sleeps." },
      { name: "Property AI", desc: "Predict maintenance, optimize energy, and lift NOI per door." },
      { name: "Construction AI", desc: "Catch schedule and cost overruns before they compound." },
      { name: "Underwriting AI", desc: "Model deals in minutes with market intelligence baked in." },
    ],
    doNothing: [
      { year: "2026", title: "Leasing and operations run on portals and phone calls.", level: 0.2 },
      { year: "2027", title: "AI leasing converts the renters you never reach.", level: 0.45 },
      { year: "2028", title: "AI operations lift NOI past what you can offer.", level: 0.72 },
      { year: "2030", title: "AI-run portfolios outbid and outperform you.", level: 1.0 },
    ],
    delayMultiple: "2.5×",
    sim: { baseMargin: 22, futureMargin: 38, revLift: 0.29, save: 0.37 },
  },
  manufacturing: {
    key: "manufacturing",
    name: "Manufacturing Intelligence Lab",
    short: "Manufacturing",
    accent: "#38BDF8",
    exemplars: ["Industrial production lines"],
    vision: "every plant becomes a vision-guided, self-tuning, predictive factory",
    unit: "plant",
    solutions: [
      { name: "Vision AI", desc: "Catch defects at line speed that human QA can't see." },
      { name: "Factory AI", desc: "Tune throughput, energy, and yield continuously, line by line." },
      { name: "Predictive Maintenance", desc: "Fix machines before they fail and kill unplanned downtime." },
      { name: "Planning AI", desc: "Schedule production against real demand, not last quarter's." },
    ],
    doNothing: [
      { year: "2026", title: "Quality and uptime depend on people watching lines.", level: 0.2 },
      { year: "2027", title: "Vision AI yields more from the same equipment.", level: 0.47 },
      { year: "2028", title: "Predictive factories eliminate the downtime you eat.", level: 0.74 },
      { year: "2030", title: "Self-tuning plants set the price you can't reach.", level: 1.0 },
    ],
    delayMultiple: "3.2×",
    sim: { baseMargin: 12, futureMargin: 27, revLift: 0.31, save: 0.46 },
  },

  software: {
    key: "software",
    name: "Software Development Lab",
    short: "Software",
    accent: "#818CF8",
    exemplars: ["Internal tooling teams", "SaaS builders"],
    vision: "every software team becomes AI-native — coding agents, internal tools, and custom platforms that ship in weeks",
    unit: "team",
    solutions: [
      { name: "Coding Agent Mesh", desc: "Multi-agent teams that build, review, and ship production code with you." },
      { name: "Repo Intelligence", desc: "Understand, refactor, and modernize legacy codebases on demand." },
      { name: "Internal Tools AI", desc: "Stand up the internal apps your team keeps asking for, in days not quarters." },
      { name: "Custom SaaS Builds", desc: "Ship a vertical platform under your brand on a proven engine." },
    ],
    doNothing: [
      { year: "2026", title: "Software is built by hand, sprint by sprint.", level: 0.2 },
      { year: "2027", title: "AI-native teams ship 5× faster than yours.", level: 0.46 },
      { year: "2028", title: "Coding agents make custom software nearly free.", level: 0.74 },
      { year: "2030", title: "Teams without AI leverage can't compete on speed or cost.", level: 1.0 },
    ],
    delayMultiple: "3.0×",
    sim: { baseMargin: 20, futureMargin: 38, revLift: 0.4, save: 0.5 },
  },

  construction: {
    key: "construction",
    name: "Construction Lab",
    short: "Construction",
    accent: "#FB923C",
    exemplars: ["Contractors", "Developers"],
    vision: "every builder becomes a cost-controlled, inspection-ready, schedule-certain operation",
    unit: "project",
    solutions: [
      { name: "Cost Control AI", desc: "Catch overruns before they compound, line by line." },
      { name: "Inspection & Quality AI", desc: "Vision-based site QA that never misses a defect." },
      { name: "Schedule Intelligence", desc: "Predict slippage and resequence before the delay hits." },
      { name: "Field Operations AI", desc: "Put the plans, RFIs, and approvals in every hand on site." },
    ],
    doNothing: [
      { year: "2026", title: "Cost and schedule run on spreadsheets and gut feel.", level: 0.2 },
      { year: "2027", title: "AI cost control wins the bids you lose on margin.", level: 0.46 },
      { year: "2028", title: "AI inspection sets a quality bar you can't staff for.", level: 0.73 },
      { year: "2030", title: "AI-run builders deliver faster, cheaper, safer.", level: 1.0 },
    ],
    delayMultiple: "2.9×",
    sim: { baseMargin: 9, futureMargin: 21, revLift: 0.33, save: 0.45 },
  },

  trade: {
    key: "trade",
    name: "Trade Lab",
    short: "Trade",
    accent: "#FACC15",
    exemplars: ["Importers & exporters", "Cross-border brokers"],
    vision: "every trader becomes a cross-border intelligence, compliance, and sourcing engine",
    unit: "trade desk",
    solutions: [
      { name: "Sourcing Intelligence", desc: "Find, score, and qualify suppliers across borders in minutes." },
      { name: "Customs & Compliance AI", desc: "Classify, document, and clear shipments without the drag." },
      { name: "Market-Entry AI", desc: "Map demand, pricing, and regulation for any new market." },
      { name: "Trade Finance AI", desc: "Model risk, terms, and cash across every cross-border deal." },
    ],
    doNothing: [
      { year: "2026", title: "Trade runs on relationships, faxes, and spreadsheets.", level: 0.2 },
      { year: "2027", title: "AI sourcing out-negotiates your best buyer.", level: 0.46 },
      { year: "2028", title: "AI compliance clears faster than you can file.", level: 0.73 },
      { year: "2030", title: "AI-native traders own the cross-border lane.", level: 1.0 },
    ],
    delayMultiple: "2.8×",
    sim: { baseMargin: 8, futureMargin: 19, revLift: 0.36, save: 0.42 },
  },

  "personal-ai": {
    key: "personal-ai",
    name: "Personal AI Training Lab",
    short: "Personal AI",
    accent: "#C084FC",
    exemplars: ["Founders & operators", "Executive teams"],
    vision: "every operator gets a private AI model trained on their work, voice, and decisions",
    unit: "operator",
    solutions: [
      { name: "Private Operator Model", desc: "A private AI trained on your documents, decisions, voice, and operating style." },
      { name: "Inbox & Decision Copilot", desc: "Triage email, draft replies, and surface the decisions only you can make." },
      { name: "Knowledge Engine", desc: "Your company's history and playbooks, instantly recallable." },
      { name: "Delegation AI", desc: "Hand off the repeatable thinking so you get your time back." },
    ],
    doNothing: [
      { year: "2026", title: "You hold the whole business in your head.", level: 0.2 },
      { year: "2027", title: "Operators with a private AI move twice as fast.", level: 0.46 },
      { year: "2028", title: "Your competitors delegate to AI; you still can't.", level: 0.72 },
      { year: "2030", title: "The operators who scaled themselves win.", level: 1.0 },
    ],
    delayMultiple: "2.7×",
    sim: { baseMargin: 15, futureMargin: 30, revLift: 0.38, save: 0.48 },
  },
};

const LAB_ORDER = ["ecommerce", "retail", "logistics", "telecom", "service", "distribution", "realestate", "manufacturing", "software", "construction", "trade", "personal-ai"];
const DEFAULT_ACCENT = "#4A76F6"; // Talya brand blue (2026 identity)

/* ---- LAB GROUPS -----------------------------------------------------------
   The entry funnel surfaces these groups first; each expands to its labs. ---- */
const LAB_GROUPS = [
  { key: "telecom-infra", name: "Telecom & Infrastructure Lab", labs: ["telecom"] },
  { key: "commerce", name: "Commerce Lab", labs: ["ecommerce", "retail"] },
  { key: "operations", name: "Operations Lab", labs: ["logistics", "distribution"] },
  { key: "service", name: "Service Business Lab", labs: ["service"] },
  { key: "industrial", name: "Industrial Lab", labs: ["manufacturing", "realestate"] },
  { key: "software", name: "Software & AI Development Lab", labs: ["software"] },
  { key: "construction", name: "Construction & Built World Lab", labs: ["construction"] },
  { key: "trade", name: "Trade & Cross-Border Lab", labs: ["trade"] },
  { key: "personal-ai", name: "Personal AI Training Lab", labs: ["personal-ai"] },
];

/* ---- PAINS ----------------------------------------------------------------
   Third diagnosis tier. Operator-level, visceral (the 11pm feeling), not the
   boardroom line. Multi-select 1–3; rebuild composes solutionFocus (de-duped)
   and uses the MAX urgency of the selected set for the do-nothing timeline.
   simAdjust nudges: margin/revenue/headcount in -1..1, urgency in 0..1. -------- */
const PAINS = [
  { key: "cashflow", label: "Cashflow is tight", copy: "Cash is hitting the wall before the work pays.",
    solutionFocus: ["Finance Ops Automation", "Cash & Reconciliation Dashboard", "Logistics CRM & AR Cash Collection"],
    module: "Cash & Reconciliation Dashboard", simAdjust: { revenue: -0.2, urgency: 0.3 } },
  { key: "customers", label: "I can't find customers", copy: "Pipeline is empty. Marketing isn't moving the needle.",
    solutionFocus: ["Channel Intelligence & Listing AI", "Marketing Automation Platform", "Affiliate & Loyalty Attribution Platform"],
    module: "Marketing Automation Platform", simAdjust: { revenue: 0.3 } },
  { key: "notime", label: "I have no time for myself", copy: "Every hour goes into the business. I haven't taken a weekend in months.",
    solutionFocus: ["Operator AI · Private GPU", "Personal AI Training · Private Operator Model", "Local Services Scheduling AI"],
    module: "Operator AI · Private GPU", elevatesGPU: true, elevatesPersonalAI: true, simAdjust: { headcount: 0.3 } },
  { key: "emails", label: "I'm drowning in emails", copy: "My inbox is the business. Nothing else gets done.",
    solutionFocus: ["Operator AI · Private GPU", "Customer Service AI", "Document Processing & Archive Platform"],
    module: "Operator AI · Private GPU", elevatesGPU: true, elevatesPersonalAI: true, simAdjust: { margin: 0.2 } },
  { key: "balance", label: "Work–life balance is gone", copy: "I haven't been present at home in a year.",
    solutionFocus: ["Operator AI · Private GPU", "Personal AI Training · Private Operator Model", "Dispatch AI"],
    module: "Operator AI · Private GPU", elevatesGPU: true, elevatesPersonalAI: true, simAdjust: { headcount: 0.3 } },
  { key: "competitors", label: "Competitors are pulling ahead", copy: "They moved while I was running operations.",
    solutionFocus: ["Channel Intelligence & Listing AI", "Pricing AI", "Industry Intelligence"],
    module: "Channel Intelligence & Listing AI", simAdjust: { urgency: 0.4 } },
  { key: "rules", label: "The rules keep changing", copy: "Regulation, platforms, payments — every quarter is a new policy.",
    solutionFocus: ["Compliance AI", "Legal & Contract AI", "Tender / RFP Legal AI"],
    module: "Compliance AI", simAdjust: { urgency: 0.3 } },
  { key: "ainative", label: "Losing to AI-native competitors", copy: "A 5-person startup with AI is winning my customers.",
    solutionFocus: ["AI Orchestrator", "Vertical Deploy Stack", "Operator AI · Private GPU"],
    module: "AI Orchestrator", elevatesGPU: true, simAdjust: { urgency: 0.6 } },
  { key: "existential", label: "Afraid I'll lose the business", copy: "This isn't a feature problem. This is existential.",
    solutionFocus: ["__three-path__", "Industry Intelligence", "Personal AI Training · Private Operator Model"],
    module: "AI Orchestrator", elevatesPersonalAI: true, softenArchitect: true, simAdjust: { urgency: 0.7 } },
  { key: "team", label: "My team can't keep up", copy: "Hiring is too slow. Training is too slow. Quality is slipping.",
    solutionFocus: ["Workforce Copilot", "Onboarding AI", "Knowledge Engine", "Operator AI · Private GPU"],
    module: "Operator AI · Private GPU", elevatesGPU: true, elevatesPersonalAI: true, simAdjust: { headcount: 0.3 } },
];

/* Compose selected pains → de-duped solution focus, elevation flags, max urgency. */
function composePains(painKeys) {
  const sel = (painKeys || []).map((k) => PAINS.find((p) => p.key === k)).filter(Boolean);
  if (!sel.length) return { pains: [], focus: [], modules: [], elevateGPU: false, elevatePersonalAI: false, urgency: 0, soften: false, topCopy: null };
  const focus = [];
  const modules = [];
  sel.forEach((p) => {
    p.solutionFocus.forEach((f) => { if (f !== "__three-path__" && !focus.includes(f)) focus.push(f); });
    if (p.module && !modules.includes(p.module)) modules.push(p.module);
  });
  return {
    pains: sel,
    focus,
    modules,
    elevateGPU: sel.some((p) => p.elevatesGPU),
    elevatePersonalAI: sel.some((p) => p.elevatesPersonalAI),
    urgency: Math.max(0, ...sel.map((p) => p.simAdjust.urgency || 0)),
    soften: sel.some((p) => p.softenArchitect),
    topCopy: sel[0].copy,
    threePathFirst: sel.some((p) => p.solutionFocus.includes("__three-path__")),
  };
}

/* ---- OS NAMING ------------------------------------------------------------
   problem × lab → a named "OS". A few hero combos are bespoke (per brief);
   the rest compose from lab.short + problem.osWord so all 64 read tailored. -- */
const BESPOKE_OS = {
  "ecommerce:growth": {
    os: "Ecommerce Growth OS",
    hero: "You don't need more traffic. You need more conversion, more repeat orders, more margin on every visit.",
  },
  "ecommerce:operations": {
    os: "Commerce Automation OS",
    hero: "The average store bleeds hours on catalog, fulfillment, support, and ad management. AI removes 40–60% of that workload.",
  },
  "logistics:supply": {
    os: "Logistics Supply Chain OS",
    hero: "Your margin is hiding in empty miles, slow quotes, and customs delays. AI finds it and routes around the rest.",
  },
};

function osFor(problemKey, labKey) {
  const lab = LABS[labKey];
  const problem = PROBLEMS.find((p) => p.key === problemKey);
  if (!lab || !problem) return null;
  const bespoke = BESPOKE_OS[`${labKey}:${problemKey}`];
  const os = bespoke ? bespoke.os : `${lab.short} ${problem.osWord} OS`;
  const hero =
    bespoke
      ? bespoke.hero
      : `${problem.symptom} In ${lab.name.replace(" Intelligence Lab", "").replace(" Business Lab", "")}, AI is the answer — and it is already moving.`;
  return { os, hero, lab, problem };
}

/* Reorder a lab's solutions so the most relevant ones for this problem lead. */
function orderedSolutions(labKey, problemKey) {
  const lab = LABS[labKey];
  if (!lab) return [];
  const pref = {
    growth: [0, 3, 2, 1],
    sales: [3, 0, 1, 2],
    operations: [2, 1, 0, 3],
    service: [3, 2, 0, 1],
    staffing: [2, 1, 3, 0],
    supply: [1, 2, 0, 3],
    technology: [0, 1, 2, 3],
    unknown: [0, 1, 2, 3],
  }[problemKey] || [0, 1, 2, 3];
  return pref.map((i) => lab.solutions[i % lab.solutions.length]);
}

window.TALYA_DATA = { PROBLEMS, LABS, LAB_ORDER, LAB_GROUPS, PAINS, DEFAULT_ACCENT, osFor, orderedSolutions, composePains };
