---
import "../styles/globals.css";
const { title = "Valtrix – Struktur schafft Wert", description = "Cloud, Security & AI Consulting aus Berlin", path = "/" } = Astro.props;
// Language & routing helpers
const pathname = Astro.url.pathname;
const isEn = pathname.startsWith('/en');
const isDe = pathname.startsWith('/de');
const lang = isEn ? 'en' : 'de';
// Default to /de for links so navigation always points to language-prefixed routes
const prefix = isEn ? '/en' : '/de';
const stripLang = (p) => p.replace(/^\/(?:en|de)(?=\/|$)/, '');
const altHref = isEn ? ('/de' + (stripLang(pathname) || '/')) : ('/en' + (stripLang(pathname) || '/'));
// Canonical/alternate URLs (use provided path when present for og/link tags)
const canonicalPath = path || pathname;
const deHref = canonicalPath.startsWith('/de') ? canonicalPath : ('/de' + (canonicalPath === '/' ? '' : canonicalPath));
const enHref = canonicalPath.startsWith('/en') ? canonicalPath : ('/en' + (canonicalPath === '/' ? '' : canonicalPath));
// Nav labels per language
const labels = isEn ? {
  services: 'Services',
  security: 'Security',
  cases: 'Case Studies',
  about: 'About',
  contact: 'Contact',
  imprint: 'Imprint',
  privacy: 'Privacy',
  langShort: 'DE',
} : {
  services: 'Leistungen',
  security: 'Sicherheit',
  cases: 'Referenzen',
  about: 'Über uns',
  contact: 'Kontakt',
  imprint: 'Impressum',
  privacy: 'Datenschutz',
  langShort: 'EN',
};
---
<!doctype html>
<html lang={lang} data-theme="dark">
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <title>{title}</title>
    <meta name="description" content={description} />
    <meta property="og:title" content={title} />
    <meta property="og:description" content={description} />
    <meta property="og:type" content="website" />
  <meta property="og:url" content={`https://valtrix.systems${path}`} />
    <meta property="og:image" content="/og-image.png" />
    <link rel="icon" type="image/png" href="/logo-valtrix.png" />
    <link rel="alternate" hreflang="de" href={`https://valtrix.systems${deHref}`} />
    <link rel="alternate" hreflang="en" href={`https://valtrix.systems${enHref}`} />
  </head>
  <body class="bg-white transition-colors duration-300">
    <header class="max-w-7xl mx-auto px-6 py-4">
      <nav class="flex items-center justify-between">
        <a href={`${prefix || '/'}`} class="flex items-center gap-3 font-semibold min-w-0">
          <img src="/logo-valtrix.png" alt="Valtrix" class="h-9 w-9 rounded-md shadow-sm"/>
          <span class="tracking-wide text-lg">VALTRIX</span>
        </a>
        <div class="hidden md:flex items-center gap-6">
          <a href={`${prefix}/leistungen`} class="text-textMuted hover:text-white">{labels.services}</a>
          <a href={`${prefix}/sicherheit`} class="text-textMuted hover:text-white">{labels.security}</a>
          <a href={`${prefix}/cases`} class="text-textMuted hover:text-white">{labels.cases}</a>
          <a href={`${prefix}/ueber-uns`} class="text-textMuted hover:text-white">{labels.about}</a>
          <a href={`${prefix}/kontakt`} class="px-4 py-2 rounded-brand bg-primary text-white hover:opacity-90">{labels.contact}</a>
          <a href={altHref} class="px-3 py-2 border rounded-brand hover:bg-graybg" aria-label="Language switch">{labels.langShort}</a>
          <button data-theme-toggle aria-label="Theme" class="px-3 py-2 border rounded-brand hover:bg-graybg">Light</button>
        </div>
        <button id="navToggle" class="md:hidden px-3 py-2 border rounded-brand hover:bg-graybg" aria-controls="mobileMenu" aria-expanded="false" aria-label="Navigation">
          Menu
        </button>
      </nav>
      <!-- Mobile menu -->
      <div id="mobileMenu" class="md:hidden hidden mt-3 border rounded-brand p-4 bg-[color:var(--color-bg,#0b0e14)]">
        <div class="grid gap-3">
          <a href={`${prefix}/leistungen`} class="block text-white">{labels.services}</a>
          <a href={`${prefix}/sicherheit`} class="block text-white">{labels.security}</a>
          <a href={`${prefix}/cases`} class="block text-white">{labels.cases}</a>
          <a href={`${prefix}/ueber-uns`} class="block text-white">{labels.about}</a>
          <a href={`${prefix}/kontakt`} class="block px-4 py-2 text-center rounded-brand bg-primary text-white hover:opacity-90">{labels.contact}</a>
          <div class="flex items-center gap-3 pt-2 border-t mt-2">
            <a href={altHref} class="px-3 py-2 border rounded-brand hover:bg-graybg" aria-label="Language switch">{labels.langShort}</a>
            <button data-theme-toggle aria-label="Theme" class="px-3 py-2 border rounded-brand hover:bg-graybg">Light</button>
          </div>
        </div>
      </div>
    </header>
    <main class="max-w-7xl mx-auto px-6">
      <slot />
    </main>
    <footer class="max-w-7xl mx-auto px-6 py-12 text-sm text-textMuted">
      <div class="flex items-center gap-3 mb-3">
        <strong>Valtrix</strong> · Precision. Power. Purpose.
      </div>
      © {new Date().getFullYear()} Valtrix · <a href={`${prefix}/impressum`} class="underline">{labels.imprint}</a> · <a href={`${prefix}/datenschutz`} class="underline">{labels.privacy}</a>
    </footer>
    <script>
      // Theme toggle for all buttons
      const html = document.documentElement;
      const themeBtns = Array.from(document.querySelectorAll('[data-theme-toggle]'));
      const setTheme = (m)=>{
        html.setAttribute('data-theme', m);
        themeBtns.forEach(b=> b.textContent = m==='dark' ? 'Light' : 'Dark');
      };
      setTheme(localStorage.getItem('theme')||'dark');
      themeBtns.forEach(btn=> btn.addEventListener('click', ()=>{
        const next = html.getAttribute('data-theme')==='dark' ? 'light' : 'dark';
        setTheme(next); localStorage.setItem('theme', next);
      }));

      // Mobile nav toggle
      const navToggle = document.getElementById('navToggle');
      const mobileMenu = document.getElementById('mobileMenu');
      const closeMenu = () => {
        mobileMenu?.classList.add('hidden');
        navToggle?.setAttribute('aria-expanded','false');
      };
      navToggle?.addEventListener('click', ()=>{
        const isOpen = !mobileMenu.classList.contains('hidden');
        if (isOpen) { closeMenu(); }
        else {
          mobileMenu.classList.remove('hidden');
          navToggle.setAttribute('aria-expanded','true');
        }
      });
      // Close menu on link click
      mobileMenu?.querySelectorAll('a').forEach(a=> a.addEventListener('click', closeMenu));
    </script>
  </body>
</html>
