// Tiny i18n layer used across the React landing page AND the static
// privacy / contact pages. EN is canonical (English string = key); LV adds
// translations. Language is stored in localStorage and broadcast via custom
// event so static pages can re-render too.

(function () {
  const LV = {
    // Nav
    'Why Xybos': 'Kāpēc Xybos',
    'Services':  'Pakalpojumi',
    'Process':   'Process',
    'Contact':   'Kontakti',
    'Book a call': 'Pieteikt sarunu',
    'Book a call with Kristaps': 'Pieteikt sarunu ar mums',
    'Write us':  'Rakstīt mums',

    // Hero
    'Enterprise automation.': 'Biznesa līmeņa automatizācija.',
    'Built for demanding businesses.': 'Izstrādāta prasīgiem uzņēmumiem.',
    'Machine-learning systems that run retail, manufacturing and logistics operations — enterprise engineering, your scale.':
      'Mašīnmācīšanās sistēmas, kas vada mazumtirdzniecības, ražošanas un loģistikas operācijas — biznesa līmeņa inženierija jūsu mērogā.',
    'Built by': 'Izstrādā',
    'a team with years of experience': 'komanda ar vairāku gadu pieredzi,',
    'delivering': 'kas piegādā',
    'business-critical': 'kritiski svarīgu',
    'ML automation at scale': 'ML automatizāciju lielā mērogā',

    // Why Xybos
    '[ 01 · WHY XYBOS ]': '[ 01 · KĀPĒC XYBOS ]',
    'Most automation projects fail.': 'Lielākā daļa automatizācijas projektu cieš neveiksmi.',
    "Ours don't.": 'Ne mūsu.',
    "Most automation projects fail in execution, not in the tech. We've spent years building production ML systems at enterprise scale — the kind where downtime costs tens of thousands a day. We bring that same engineering expertise to your project.":
      'Lielākā daļa automatizācijas projektu cieš neveiksmi izpildē, nevis tehnoloģijā. Mēs gadiem esam veidojuši dažādas ML sistēmas uzņēmuma mērogā — tādas, kur dīkstāve maksā desmitiem tūkstošu dienā. To pašu inženierijas precizitāti ienesam arī jūsu projektā.',

    // Pillar 1
    'Enterprise engineering, your scale': 'Liela mēroga inženierija, jūsu mērogā',
    'The same engineering principles found in global enterprise systems — applied to your business. We deliver the system, run it, and keep improving it. You get the outcome, not the team to manage.':
      'Tie paši inženierijas principi, kas atrodami globālās uzņēmumu sistēmās — piemēroti jūsu biznesam. Mēs piegādājam sistēmu, vadām to un nepārtraukti uzlabojam. Jūs saņemat rezultātu, nevis komandu, kas jāvada.',

    // Pillar 2
    'Secure, modern, built to last': 'Drošas, mūsdienīgas, ilgmūžīgas',
    'Modern technologies, secure by default. Your data stays encrypted in transit and at rest, dependencies stay patched, the framework keeps receiving security updates for years. We make engineering choices today with what they cost you tomorrow.':
      'Mūsdienīgas tehnoloģijas, drošas pēc noklusējuma. Jūsu dati paliek šifrēti gan pārraidē, gan glabāšanā, atkarības tiek aktīvi atjauninātas, un ietvars saņem drošības atjauninājumus gadiem. Šodienas inženierijas lēmumus pieņemam, domājot par to, cik tie jums maksās rīt.',

    // Pillar 3
    'Specialists, not generalists.': 'Specializēti, ne universāli.',
    "Operational automation for retail, manufacturing, and logistics. Nothing else lands on our desk. That focus is why we ship faster — and why our systems still run two years in.":
      'Operatīvā automatizācija mazumtirdzniecībai, ražošanai un loģistikai. Nekas cits mums uz galda nenonāk. Tas fokuss ir iemesls, kāpēc piegādājam ātrāk — un kāpēc mūsu sistēmas joprojām strādā arī pēc diviem gadiem.',

    // Services
    '[ 02 · WHAT WE BUILD ]': '[ 02 · KO MĒS BŪVĒJAM ]',
    'Four core services.': 'Četri pamatpakalpojumi.',
    'Each starts with a specific problem.': 'Katrs sākas ar specifisku problēmu.',
    'Each one ends with a system that pays for itself. No products, no templates — every engagement is built from scratch, then deployed and maintained. You see the outcome in your operation; we carry the engineering.':
      'Katrs beidzas ar sistēmu, kas atmaksājas. Bez produktiem, bez šabloniem — katrs projekts tiek būvēts no nulles, pēc tam izvietots un uzturēts. Jūs redzat rezultātu savā operācijā; mēs atbildam par inženieriju.',

    'Store Ordering': 'Veikalu pasūtīšanas',
    'Warehouse': 'Noliktavu',
    'Automation': 'Automatizācija',
    'AI-Powered': 'AI darbinātā',
    'Business Intelligence': 'Biznesa analītika',
    'Custom': 'Pielāgota',
    'Process Automation': 'Procesu automatizācija',

    'RETAIL · ORDERING': 'VEIKALI · PASŪTĪŠANA',
    'LOGISTICS · OPS': 'LOĢISTIKA · OPERĀCIJAS',
    'INSIGHT · DECISION': 'IESKATS · LĒMUMS',
    'OPERATIONS · BACK-OFFICE': 'OPERĀCIJAS · IEKŠĒJĀS SISTĒMAS',

    // Service 1 — Store Ordering
    'Most retailers lose 5–15% of revenue to stockouts and another 10–20% to overstock. Our ordering engine combines your sales history, current stock levels, supplier lead times and seasonality into a daily ML-driven recommendation — or fully automated order placement.':
      'Lielākā daļa mazumtirgotāju zaudē 5–15% ieņēmumu nepietiekamu krājumu dēļ un vēl 10–20% pārmērīgu krājumu dēļ. Mūsu pasūtīšanas dzinējs apvieno jūsu pārdošanas vēsturi, pašreizējos krājumu līmeņus, piegādātāju izpildes laikus un sezonalitāti dienas ML rekomendācijā — vai pilnībā automatizētā pasūtījumu izvietošanā.',
    '30–60% fewer stockouts': 'Par 30–60% mazāk nepietiekamu krājumu',
    '15–25% lower inventory holding cost': 'Par 15–25% zemākas krājumu uzturēšanas izmaksas',
    '4–13% higher turnover': '4–13% lielāks apgrozījums',

    // Service 2 — Warehouse
    "We build an automated warehouse system: inventory tracking, ML demand forecasts that account for seasonality and supplier lead times, purchase orders generated automatically when thresholds are crossed. Your team stops chasing spreadsheets — they oversee a system that handles the calculations, the timing, and the paperwork.":
      'Mēs veidojam automatisku noliktavas sistēmu: krājumu uzraudzība, ML pieprasījuma prognozes, kas ņem vērā sezonalitāti un piegādātāju piegādes laikus, automātiski ģenerēti pasūtījumi, kad sasniegtas noteiktas robežas. Jūsu komanda pārstāj slīkt tabulās — viņi uzrauga sistēmu, kas pārņem aprēķinus, laiku un dokumentāciju.',
    'Pick-path optimisation': 'Izsekošanas ceļa optimizācija',
    'Predictive replenishment': 'Prognozēta papildināšana',
    'WMS / ERP integration ': 'WMS / ERP integrācija ',

    // Service 3 — BI
    "Dashboards are not insight. We build BI systems that flag what matters, predict what's coming, and tell your team what to do about it — instead of leaving them to interpret another chart.":
      'Informācijas paneļi nav ieskats. Mēs veidojam BI sistēmas, kas norāda, kas ir svarīgs, prognozē, kas notiks, un pasaka jūsu komandai, ko ar to darīt — nevis liek viņiem interpretēt vēl vienu diagrammu.',
    'Predictive forecasts, not retrospective charts': 'Prognozes, nevis retrospektīvas diagrammas',
    'Action-flagged alerts': 'Brīdinājumi ar darbības norādēm',
    'Built on your data warehouse': 'Veidots uz jūsu datu noliktavas',

    // Service 4 — Process Automation
    "The work nobody wants to do but everyone has to: invoice reconciliation, supplier matching, demand forecasting, quality-control flagging, document processing. Where there's a clear rule, we code it. Where there isn't, we let ML learn the pattern from your data.":
      'Darbs, ko neviens negrib darīt, bet visiem jādara: rēķinu saskaņošana, piegādātāju identificēšana, pieprasījuma prognozēšana, kvalitātes problēmu atklāšana, dokumentu apstrāde. Kur ir skaidri noteikumi — to ieprogrammējam. Kur tā nav — ļaujam ML iemācīties no jūsu datiem.',
    "Rules where they fit, ML where they don't": 'Noteikumi kur tie der, ML kur neder',
    '70%+ of manual work eliminated': '70%+ manuālā darba pazūd',
    'Catches errors humans miss': 'Atklāj kļūdas, ko cilvēki nepamana',

    // Process
    '[ 03 · PROCESS ]': '[ 03 · PROCESS ]',
    'A': 'Četru posmu',
    'four-stage': 'sadarbība',
    'engagement.': '.',
    'No surprises, no scope creep, no quarter-long discovery phases. Most engagements ship a working pilot inside three months.':
      'Nekādu pārsteigumu, nekādas apjoma palielināšanās, nekādu ceturkšņa garu izpētes fāžu. Lielākā daļa projektu piegādā strādājošu pilotversiju trīs mēnešu laikā.',
    '// Avg time-to-production · 9.4 weeks': '// Vidējais laiks līdz piegādei · 9.4 nedēļas',

    'Diagnostics': 'Diagnostika',
    'Design':    'Dizains',
    'Build & Pilot': 'Izstrāde un pilotēšana',
    'Operate & Improve': 'Pārvaldība un uzlabošana',
    '1–2 weeks': '1–2 nedēļas',
    '4–10 weeks': '4–10 nedēļas',
    'Ongoing': 'Pastāvīgi',

    "We sit with your team, study the actual workflow, and quantify the cost of the current bottleneck. You receive a written diagnostic: what's broken, what it's costing you, and what's worth automating first.":
      'Mēs sēžam kopā ar jūsu komandu, izpētām reālo darbplūsmu un kvantificējam pašreizējās problēmas izmaksas. Jūs saņemat rakstisku diagnostiku: kas ir salauzts, cik tas jums maksā un ko ir vērts automatizēt vispirms.',
    "We propose a system: the data we need, the model we'll build, the integrations involved, the KPIs we'll be measured against. You see the full plan, fixed price and realistic timeline before signing anything.":
      'Mēs piedāvājam sistēmu: nepieciešamos datus, modeli, ko veidosim, iesaistītās integrācijas, KPI, pēc kuriem mūs vērtēs. Jūs redzat pilnu plānu, fiksētu cenu un reālistisku laika grafiku pirms jebkādas parakstīšanas.',
    "We build in short cycles, demo every two weeks, and run the system in parallel with your current process before any switchover. You verify the ROI on your own data — not on a presentation.":
      'Mēs būvējam īsos ciklos, demonstrējam ik pēc divām nedēļām un palaižam sistēmu paralēli jūsu pašreizējam procesam pirms jebkādas pārslēgšanas. Jūs pārbaudāt ROI uz saviem datiem — nevis uz prezentācijas.',
    'Once live, we keep the system running — monitored, maintained, and continuously improved. ML systems get sharper as more of your data flows through them, and we make sure yours stays running.':
      'Tiklīdz sistēma ir palaista, mēs to uzturam darbībā — uzraudzītu, apkalpotu un nepārtraukti uzlabotu. ML sistēmas kļūst asākas, jo vairāk jūsu datu plūst caur tām, un mēs nodrošinām, ka jūsu sistēma turpina darboties.',

    // CTA
    '[ 04 · CONTACT ]': '[ 04 · KONTAKTI ]',
    "Let's see if it's": 'Apskatīsim, vai mēs',
    'a fit.': 'esam piemēroti.',
    "A 30-minute conversation is enough to tell whether automation is the right answer right now — or whether the problem you're seeing is actually something else.":
      '30 minūšu saruna ir pietiekama, lai saprastu, vai automatizācija ir pareizā atbilde tieši tagad — vai arī problēma, ko jūs redzat, patiesībā ir kaut kas cits.',
    "// 30 min · what we'll cover": '// 30 min · ko mēs apspriedīsim',
    'The bottleneck': 'Problēma',
    "What's broken and what it's costing.": 'Kas ir salauzts un cik tas maksā.',
    'Whether ML fits': 'Vai ML der',
    "Honest answer — sometimes it doesn't.": 'Godīga atbilde — dažreiz neder.',
    'Concrete next step': 'Konkrēts nākamais solis',
    'A diagnostic SOW, or a referral, or nothing.': 'Diagnostikas SOW, ieteikums vai nekas.',
    'Kristaps Lokmanis · CEO': 'Kristaps Lokmanis · vadītājs',
    '// avg response': '// vid. atbildes laiks',
    '// weekdays': '// darba dienās',

    // Footer
    'Sitemap': 'Lapas karte',
    'Privacy': 'Privātums',
    'Xybos — operational intelligence, engineered.': 'Xybos — operacionālā inteliģence, projektēta.',
    'Machine-learning systems that automate the operational core of mid-sized retail, manufacturing and logistics businesses — engineered by a team with deep experience in large-scale ML delivery.':
      'Mašīnmācīšanās sistēmas, kas automatizē vidēja izmēra mazumtirdzniecības, ražošanas un loģistikas uzņēmumu operacionālo kodolu — projektē komanda ar dziļu pieredzi liela mēroga ML piegādē.',
    '© 2026 Xybos SIA': '© 2026 Xybos SIA',
    'Riga, Latvia': 'Rīga, Latvija',
  };

  const dicts = { en: {}, lv: LV };

  let LANG;
  try { LANG = localStorage.getItem('xy_lang') || 'en'; } catch (e) { LANG = 'en'; }
  if (LANG !== 'en' && LANG !== 'lv') LANG = 'en';

  const listeners = new Set();

  window.t = function (key) {
    const d = dicts[LANG] || {};
    return d[key] != null ? d[key] : key;
  };
  window.getLang = function () { return LANG; };
  window.setLang = function (lang) {
    if (lang !== 'en' && lang !== 'lv') return;
    LANG = lang;
    try { localStorage.setItem('xy_lang', lang); } catch (e) {}
    if (typeof document !== 'undefined') document.documentElement.lang = lang;
    listeners.forEach((fn) => { try { fn(lang); } catch (e) {} });
    try { window.dispatchEvent(new CustomEvent('xy:lang', { detail: lang })); } catch (e) {}
  };
  window.onLangChange = function (fn) { listeners.add(fn); return function () { listeners.delete(fn); }; };

  if (typeof document !== 'undefined') document.documentElement.lang = LANG;
})();

// React-aware helpers
function useLang() {
  const [, force] = React.useState(0);
  React.useEffect(() => window.onLangChange(() => force((n) => n + 1)), []);
  return window.getLang();
}

// EN/LV pill switch — fits next to the nav CTA
function LangToggle({ compact = false }) {
  const lang = useLang();
  return (
    <div style={{
      display: 'inline-flex', alignItems: 'center', gap: 0, padding: 3,
      border: '1px solid var(--line)', borderRadius: 999,
      background: 'rgba(255,255,255,.03)',
      fontFamily: 'var(--mono)', fontSize: 11, letterSpacing: 0.6, fontWeight: 600,
    }}>
      {['en', 'lv'].map((l) => {
        const active = l === lang;
        return (
          <button key={l} type="button"
            onClick={() => window.setLang(l)}
            style={{
              padding: compact ? '4px 9px' : '5px 11px',
              borderRadius: 999, border: 'none', cursor: 'pointer',
              background: active ? 'var(--blue)' : 'transparent',
              color: active ? '#fff' : 'rgba(255,255,255,.6)',
              boxShadow: active ? '0 0 14px var(--blue-glow)' : 'none',
              transition: 'background .2s, color .2s, box-shadow .25s',
              fontFamily: 'inherit', fontSize: 'inherit', fontWeight: 'inherit', letterSpacing: 'inherit',
            }}>{l.toUpperCase()}</button>
        );
      })}
    </div>
  );
}

Object.assign(window, { useLang, LangToggle });
