﻿// Shared components for GEOKlar site
const { useState, useEffect, useRef } = React;

// ————————————————————————————————————— ICONS
const Icon = {
  check: (p) => (
    <svg viewBox="0 0 20 20" width="16" height="16" fill="none" {...p}>
      <path d="M4 10.5L8 14.5L16 6" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round"/>
    </svg>
  ),
  x: (p) => (
    <svg viewBox="0 0 20 20" width="14" height="14" fill="none" {...p}>
      <path d="M5 5L15 15M15 5L5 15" stroke="currentColor" strokeWidth="1.6" strokeLinecap="round"/>
    </svg>
  ),
  arrow: (p) => (
    <svg viewBox="0 0 20 20" width="16" height="16" fill="none" {...p}>
      <path d="M4 10H16M16 10L11 5M16 10L11 15" stroke="currentColor" strokeWidth="1.6" strokeLinecap="round" strokeLinejoin="round"/>
    </svg>
  ),
  arrowUp: (p) => (
    <svg viewBox="0 0 16 16" width="12" height="12" fill="none" {...p}>
      <path d="M8 13V3M8 3L3 8M8 3L13 8" stroke="currentColor" strokeWidth="1.6" strokeLinecap="round" strokeLinejoin="round"/>
    </svg>
  ),
  flag: (p) => (
    <svg viewBox="0 0 24 24" width="20" height="20" fill="none" {...p}>
      <rect x="3" y="5" width="18" height="14" rx="1.5" fill="#c8102e"/>
      <path d="M9 5V19M3 11.5H21" stroke="white" strokeWidth="2.2"/>
    </svg>
  ),
  price: (p) => (
    <svg viewBox="0 0 24 24" width="20" height="20" fill="none" {...p}>
      <path d="M4 12C4 7.58 7.58 4 12 4C16.42 4 20 7.58 20 12C20 16.42 16.42 20 12 20C7.58 20 4 16.42 4 12Z" stroke="currentColor" strokeWidth="1.5"/>
      <path d="M14 9.5C14 8.67 13.1 8 12 8C10.9 8 10 8.67 10 9.5C10 10.33 10.9 11 12 11C13.1 11 14 11.67 14 12.5C14 13.33 13.1 14 12 14C10.9 14 10 13.33 10 12.5M12 7V8M12 14V15" stroke="currentColor" strokeWidth="1.5" strokeLinecap="round"/>
    </svg>
  ),
  bolt: (p) => (
    <svg viewBox="0 0 24 24" width="20" height="20" fill="none" {...p}>
      <path d="M13 3L5 14H12L11 21L19 10H12L13 3Z" stroke="currentColor" strokeWidth="1.5" strokeLinejoin="round"/>
    </svg>
  ),
  chart: (p) => (
    <svg viewBox="0 0 24 24" width="20" height="20" fill="none" {...p}>
      <path d="M4 20V10M10 20V4M16 20V14M22 20H2" stroke="currentColor" strokeWidth="1.5" strokeLinecap="round"/>
    </svg>
  ),
  plus: (p) => (
    <svg viewBox="0 0 20 20" width="16" height="16" fill="none" {...p}>
      <path d="M10 4V16M4 10H16" stroke="currentColor" strokeWidth="1.6" strokeLinecap="round"/>
    </svg>
  ),
  minus: (p) => (
    <svg viewBox="0 0 20 20" width="16" height="16" fill="none" {...p}>
      <path d="M4 10H16" stroke="currentColor" strokeWidth="1.6" strokeLinecap="round"/>
    </svg>
  ),
  search: (p) => (
    <svg viewBox="0 0 20 20" width="18" height="18" fill="none" {...p}>
      <circle cx="9" cy="9" r="5.5" stroke="currentColor" strokeWidth="1.6"/>
      <path d="M13 13L17 17" stroke="currentColor" strokeWidth="1.6" strokeLinecap="round"/>
    </svg>
  ),
  bell: (p) => (
    <svg viewBox="0 0 20 20" width="18" height="18" fill="none" {...p}>
      <path d="M5 8C5 5.24 7.24 3 10 3C12.76 3 15 5.24 15 8V11L16.5 13.5H3.5L5 11V8Z" stroke="currentColor" strokeWidth="1.6" strokeLinejoin="round"/>
      <path d="M8 16C8 17.1 8.9 18 10 18C11.1 18 12 17.1 12 16" stroke="currentColor" strokeWidth="1.6"/>
    </svg>
  ),
  target: (p) => (
    <svg viewBox="0 0 24 24" width="20" height="20" fill="none" {...p}>
      <circle cx="12" cy="12" r="9" stroke="currentColor" strokeWidth="1.5"/>
      <circle cx="12" cy="12" r="5" stroke="currentColor" strokeWidth="1.5"/>
      <circle cx="12" cy="12" r="1.5" fill="currentColor"/>
    </svg>
  ),
  linkedin: (p) => (
    <svg viewBox="0 0 20 20" width="14" height="14" fill="none" {...p}>
      <path d="M3 7V17H6V7H3ZM4.5 3C3.67 3 3 3.67 3 4.5C3 5.33 3.67 6 4.5 6C5.33 6 6 5.33 6 4.5C6 3.67 5.33 3 4.5 3ZM8 7V17H11V11.5C11 10.12 11.62 9 13 9C14.38 9 15 10.12 15 11.5V17H18V10.5C18 8.01 16.5 6.5 14 6.5C12.5 6.5 11.5 7.5 11 8.5V7H8Z" fill="currentColor"/>
    </svg>
  ),
  x_social: (p) => (
    <svg viewBox="0 0 20 20" width="13" height="13" fill="none" {...p}>
      <path d="M4 4L16 16M16 4L4 16" stroke="currentColor" strokeWidth="1.8" strokeLinecap="round"/>
    </svg>
  ),
  chat: (p) => (
    <svg viewBox="0 0 20 20" width="16" height="16" fill="none" {...p}>
      <path d="M4 5C4 4.45 4.45 4 5 4H15C15.55 4 16 4.45 16 5V12C16 12.55 15.55 13 15 13H10L6 16V13H5C4.45 13 4 12.55 4 12V5Z" stroke="currentColor" strokeWidth="1.5" strokeLinejoin="round"/>
    </svg>
  ),
  sparkle: (p) => (
    <svg viewBox="0 0 20 20" width="14" height="14" fill="none" {...p}>
      <path d="M10 2L11.5 7.5L17 9L11.5 10.5L10 16L8.5 10.5L3 9L8.5 7.5L10 2Z" fill="currentColor"/>
    </svg>
  ),
  info: (p) => (
    <svg viewBox="0 0 16 16" width="14" height="14" fill="none" {...p}>
      <circle cx="8" cy="8" r="7" stroke="currentColor" strokeWidth="1.4"/>
      <path d="M8 7V11.5" stroke="currentColor" strokeWidth="1.5" strokeLinecap="round"/>
      <circle cx="8" cy="4.9" r="0.9" fill="currentColor"/>
    </svg>
  ),
  chevronDown: (p) => (
    <svg viewBox="0 0 16 16" width="11" height="11" fill="none" {...p}>
      <path d="M3.5 5.5L8 10L12.5 5.5" stroke="currentColor" strokeWidth="1.6" strokeLinecap="round" strokeLinejoin="round"/>
    </svg>
  ),
};

// ————————————————————————————————————— LOGO
function Logo({ light = false }) {
  return (
    <a href="index.html" className="logo" style={light ? { color: 'white' } : {}}>
      <span className="logo-mark"></span>
      <span><span style={{ color: 'var(--gold)' }}>GEO</span>Klar</span>
    </a>
  );
}

// ————————————————————————————————————— HEADER
function NavDropdownLink({ href, label }) {
  const [hov, setHov] = React.useState(false);
  return (
    <a
      href={href}
      onMouseEnter={() => setHov(true)}
      onMouseLeave={() => setHov(false)}
      style={{
        display: 'block', padding: '8px 14px', fontSize: 14, fontWeight: 500,
        borderRadius: 6, textDecoration: 'none', whiteSpace: 'nowrap',
        color: hov ? 'var(--navy)' : 'var(--ink-2)',
        background: hov ? 'rgba(10,31,68,0.05)' : 'transparent',
        transition: 'color .15s ease, background .15s ease',
      }}
    >{label}</a>
  );
}

function SiteHeader({ active }) {
  const [dropOpen, setDropOpen] = React.useState(false);
  const nav = [
    { label: 'Sådan virker det', href: 'index.html#how' },
    { label: 'Priser & services', href: 'priser.html', key: 'pricing' },
    { label: 'Dashboard', href: 'dashboard.html', key: 'dashboard' },
  ];
  const andEtLinks = [
    { label: 'Om', href: 'om.html' },
    { label: 'Blog', href: 'blog.html' },
    { label: 'FAQ', href: 'faq.html' },
  ];
  const andEtActive = active === 'om' || active === 'blog' || active === 'faq';
  return (
    <header className="site-header">
      <div className="wrap-wide site-header-inner">
        <Logo />
        <nav className="site-nav">
          {nav.map(n => (
            <a key={n.label} href={n.href} className={active === n.key ? 'active' : ''}>{n.label}</a>
          ))}
          {/* "Andet" dropdown */}
          <div
            style={{ position: 'relative' }}
            onMouseEnter={() => setDropOpen(true)}
            onMouseLeave={() => setDropOpen(false)}
          >
            <button style={{
              display: 'flex', alignItems: 'center', gap: 3,
              padding: '8px 14px', borderRadius: 'var(--r)',
              fontSize: 14, fontWeight: 500, fontFamily: 'inherit',
              border: 'none', cursor: 'pointer',
              color: andEtActive ? 'var(--navy)' : 'var(--ink-2)',
              background: dropOpen ? 'rgba(10,31,68,0.04)' : 'none',
              transition: 'color .15s ease, background .15s ease',
            }}>
              Andet <Icon.chevronDown style={{ opacity: 0.7, marginTop: 1 }}/>
            </button>
            {dropOpen && (
              // Outer div starts flush at 100% — no gap — with transparent
              // paddingTop acting as a hover bridge so the mouse never leaves
              // the tracking area when moving from button down into the menu.
              <div style={{
                position: 'absolute', top: '100%', right: 0,
                paddingTop: 8, zIndex: 200, minWidth: 156,
              }}>
                <div style={{
                  background: 'white', border: '1px solid var(--line)',
                  borderRadius: 8, boxShadow: 'var(--sh-lg)', padding: 4,
                }}>
                  {andEtLinks.map(d => (
                    <NavDropdownLink key={d.label} href={d.href} label={d.label}/>
                  ))}
                </div>
              </div>
            )}
          </div>
        </nav>
        <div className="site-header-cta">
          <a href="#audit" className="btn btn-gold btn-sm">Få gratis analyse</a>
        </div>
      </div>
    </header>
  );
}

// ————————————————————————————————————— FOOTER
function SiteFooter() {
  return (
    <footer className="site-footer">
      <div className="wrap-wide">
        <div className="footer-grid">
          <div className="footer-brand">
            <Logo light />
            <p style={{ color: 'rgba(255,255,255,0.6)' }}>
              Generativ søgemaskine­optimering for danske revisionsfirmaer. Bliv den revisor AI anbefaler.
            </p>
          </div>
          <div className="footer-col">
            <h4>Produkt</h4>
            <a href="#audit">Gratis analyse</a>
            <a href="priser.html">Priser</a>
            <a href="index.html#how">Sådan virker det</a>
          </div>
          <div className="footer-col">
            <h4>Ressourcer</h4>
            <a href="index.html#faq">FAQ</a>
          </div>
          <div className="footer-col">
            <h4>Firma</h4>
            <a href="om.html">Om os</a>
            <a href="#">Kontakt</a>
            <a href="#">Karriere</a>
          </div>
          <div className="footer-col">
            <h4>Juridisk</h4>
            <a href="privatlivspolitik.html">Privatlivspolitik</a>
            <a href="cookiepolitik.html">Cookiepolitik</a>
            <a href="vilkaar.html">Vilkår</a>
          </div>
        </div>
        <div className="footer-bottom">
          <div>© 2026 GEOKlar · CVR 43 12 88 77 · København, Danmark</div>
          <div className="footer-socials">
            <a href="#" aria-label="LinkedIn"><Icon.linkedin style={{ color: 'white' }} /></a>
            <a href="#" aria-label="X"><Icon.x_social style={{ color: 'white' }} /></a>
          </div>
        </div>
      </div>
    </footer>
  );
}

// ————————————————————————————————————— STRIPED PLACEHOLDER
function StripePH({ label, w, h, style = {} }) {
  return (
    <div style={{
      width: w || '100%', height: h || 80,
      background: 'repeating-linear-gradient(135deg, rgba(10,31,68,0.04) 0 6px, rgba(10,31,68,0.08) 6px 12px)',
      border: '1px solid var(--line)',
      borderRadius: 6,
      display: 'grid', placeItems: 'center',
      ...style,
    }}>
      <span className="mono" style={{ color: 'var(--ink-3)' }}>{label}</span>
    </div>
  );
}

// ————————————————————————————————————— INFO TOOLTIP
function InfoTip({ text, stopNav = false }) {
  return (
    <span
      className="tip" tabIndex={0} role="button" aria-label={text}
      onClick={stopNav ? (e) => { e.stopPropagation(); e.preventDefault(); } : undefined}
    >
      <Icon.info/>
      <span className="tip-body">{text}</span>
    </span>
  );
}

// ————————————————————————————————————— PRICING CARD (shared)
function PricingCard({ p }) {
  const href = p.href || (p.free ? 'index.html#audit' : `checkout.html?tier=${p.name.toLowerCase()}`);
  return (
    <div style={{
      background: p.popular ? 'var(--bg-warm)' : (p.free ? 'var(--bg-alt)' : 'white'),
      border: p.popular ? '1.5px solid var(--gold)' : '1px solid var(--line)',
      borderRadius: 12,
      padding: 28,
      position: 'relative',
      display: 'flex',
      flexDirection: 'column',
    }}>
      {p.popular && (
        <div style={{
          position: 'absolute', top: -11, right: 20,
          background: 'var(--gold)', color: 'white',
          padding: '4px 10px', borderRadius: 100,
          fontSize: 11, fontWeight: 600, letterSpacing: '0.02em',
        }}>Mest populær</div>
      )}
      <div style={{ fontSize: 13, fontWeight: 600, color: 'var(--ink-2)', marginBottom: 8, textTransform: 'uppercase', letterSpacing: '0.08em' }}>{p.name}</div>
      {p.tag && <p style={{ fontSize: 13, color: 'var(--ink-3)', marginBottom: 20, minHeight: 36 }}>{p.tag}</p>}
      <div style={{ display: 'flex', alignItems: 'baseline', gap: 6, marginBottom: p.per ? 4 : 24 }}>
        <span style={{ fontFamily: 'var(--font-display)', fontSize: 34, fontWeight: 600, color: 'var(--navy)', letterSpacing: '-0.02em', lineHeight: 1 }}>{typeof p.price === 'number' ? p.price.toLocaleString('da-DK') + ' kr' : p.price}</span>
      </div>
      {p.per && <div style={{ fontSize: 12, color: 'var(--ink-3)', marginBottom: 20 }}>{p.per}</div>}
      <a href={href} className={p.popular ? 'btn btn-gold' : 'btn btn-outline'} style={{ justifyContent: 'center', marginBottom: 24 }}>{p.cta}</a>
      <ul style={{ listStyle: 'none', display: 'grid', gap: 10, fontSize: 13, margin: 0, padding: 0 }}>
        {p.feats.map(f => (
          <li key={typeof f === 'string' ? f : f.key} style={{ display: 'flex', gap: 10, color: 'var(--ink-2)', alignItems: 'flex-start', lineHeight: 1.45 }}>
            <Icon.check style={{ color: 'var(--green)', flexShrink: 0, marginTop: 2 }}/>
            <span>{f}</span>
          </li>
        ))}
      </ul>
    </div>
  );
}

// Export
Object.assign(window, { Icon, Logo, SiteHeader, SiteFooter, StripePH, InfoTip, PricingCard });
