/* global React, STOCKS, Sparkline */
const { useState: useStateMP, useEffect: useEffectMP } = React;

/* =========================================================
   HOME — Aurevon Financial Group
   ========================================================= */
function HomePage({ lang }) {
  const t = window.useT(lang);
  const isDe = lang === "de";
  return (
    <>
      {/* HERO */}
      <section className="hero" style={{ background: "var(--paper-50)", padding: "86px 0 0", borderBottom: "1px solid var(--paper-200)" }}>
        <div className="hero-media" aria-hidden></div>
        <div aria-hidden style={{
          position: "absolute", inset: 0, opacity: 0.28, pointerEvents: "none",
          backgroundImage: "linear-gradient(var(--paper-200) 1px, transparent 1px), linear-gradient(90deg, var(--paper-200) 1px, transparent 1px)",
          backgroundSize: "120px 120px",
          maskImage: "radial-gradient(ellipse at 85% 10%, #000 10%, transparent 62%)",
        }}></div>
        <div className="wrap" style={{ position: "relative", zIndex: 1, display: "grid", gridTemplateColumns: "1.35fr 0.85fr", gap: 72, alignItems: "end", paddingBottom: 88 }}>
          <div>
            <div className="eyebrow">{t("hero_eyebrow")}</div>
            <h1 className="h-display" style={{ marginTop: 30, marginBottom: 26 }}>{t("hero_title")}</h1>
            <p className="lede" style={{ maxWidth: "54ch" }}>{t("hero_sub")}</p>
            <div style={{ display: "flex", gap: 10, marginTop: 38, flexWrap: "wrap" }}>
              <a href="#/kontakt" className="btn btn-primary btn-lg">{t("hero_cta_primary")} →</a>
              <a href="#/philosophie" className="btn btn-ghost btn-lg">{t("hero_cta_secondary")}</a>
            </div>
          </div>
          <HeroQuoteCard lang={lang} />
        </div>
        {/* Stats row */}
        <div style={{ position: "relative", zIndex: 1, borderTop: "1px solid var(--paper-200)", background: "rgba(247,244,238,0.86)" }}>
          <div className="wrap" style={{ display: "grid", gridTemplateColumns: "repeat(4, 1fr)", padding: "38px 0" }}>
            {[
              { v: "€ 1,4 Mrd.", l: t("stat_aum") },
              { v: "210", l: t("stat_clients") },
              { v: "Stuttgart", l: t("stat_offices") },
              { v: "2011", l: t("stat_indep") },
            ].map((s, i) => (
              <div key={i} style={{ paddingLeft: i ? 30 : 0, borderLeft: i ? "1px solid var(--paper-200)" : "none" }}>
                <div style={{ fontFamily: "var(--serif)", fontSize: 40, lineHeight: 1, letterSpacing: "-0.02em" }}>{s.v}</div>
                <div className="kicker" style={{ marginTop: 12 }}>{s.l}</div>
              </div>
            ))}
          </div>
        </div>
      </section>

      {/* TWO SPEEDS — hybrid positioning */}
      <section style={{ padding: "26px 0 0", background: "var(--paper-100)" }}>
        <div className="wrap" style={{ display: "grid", gridTemplateColumns: "1fr 1fr", gap: 1, background: "var(--paper-200)" }}>
          <div style={{ background: "var(--paper-50)", padding: "56px 44px 60px" }}>
            <div className="kicker" style={{ color: "var(--gold-deep)", marginBottom: 18 }}>01 — {isDe ? "DER KERN" : "THE CORE"}</div>
            <h2 style={{ fontFamily: "var(--serif)", fontSize: 38, lineHeight: 1.04, letterSpacing: "-0.018em", fontWeight: 400, marginBottom: 18 }}>
              {isDe ? "Vermögen, das ruhig bleiben darf." : "Wealth that is allowed to stay calm."}
            </h2>
            <p style={{ color: "var(--slate-700)", fontSize: 15.5, lineHeight: 1.65, maxWidth: "46ch" }}>
              {isDe
                ? "Langfristige Verwaltung mit schriftlicher Strategie, Sicherheitsmarge und niedrigem Umschlag. Kein Aktionismus, keine Produktlisten — ein Mandat, das Sie verstehen."
                : "Long-term management with a written strategy, margin of safety and low turnover. No activism, no product lists — a mandate you understand."}
            </p>
            <a href="#/vermoegen" style={{ display: "inline-block", marginTop: 26, fontSize: 13, fontWeight: 500, borderBottom: "1px solid var(--ink-900)", paddingBottom: 3 }}>
              {isDe ? "Vermögensverwaltung ansehen" : "See wealth management"} →
            </a>
          </div>
          <div style={{ background: "var(--ink-950)", color: "var(--paper-50)", padding: "56px 44px 60px" }}>
            <div className="kicker" style={{ color: "var(--gold)", marginBottom: 18 }}>02 — {isDe ? "DER SATELLIT" : "THE SATELLITE"}</div>
            <h2 style={{ fontFamily: "var(--serif)", fontSize: 38, lineHeight: 1.04, letterSpacing: "-0.018em", fontWeight: 400, marginBottom: 18 }}>
              {isDe ? "Und ein Desk, der handeln kann." : "And a desk that can act."}
            </h2>
            <p style={{ color: "var(--ink-200)", fontSize: 15.5, lineHeight: 1.65, maxWidth: "46ch" }}>
              {isDe
                ? "Aktive Strategien, taktische Absicherung, Einzelthemen. Order per Telefon oder Portal, Ausführung an XETRA — mit Größen- und Zeitlimits."
                : "Active strategies, tactical hedging, single themes. Orders by phone or portal, execution on XETRA — with size and time limits."}
            </p>
            <a href="#/trading" style={{ display: "inline-block", marginTop: 26, fontSize: 13, fontWeight: 500, color: "var(--paper-50)", borderBottom: "1px solid var(--gold)", paddingBottom: 3 }}>
              {isDe ? "Zum Trading Desk" : "To the trading desk"} →
            </a>
          </div>
        </div>
      </section>

      {/* FOUR AREAS */}
      <section style={{ padding: "104px 0" }}>
        <div className="wrap">
          <div style={{ display: "grid", gridTemplateColumns: "1fr 1fr", gap: 72, marginBottom: 56 }}>
            <div>
              <div className="eyebrow">{t("pillars_eyebrow")}</div>
              <h2 className="h-section" style={{ marginTop: 22 }}>{t("pillars_title")}</h2>
            </div>
            <p className="lede" style={{ alignSelf: "end" }}>{t("pillars_sub")}</p>
          </div>
          <div style={{ display: "grid", gridTemplateColumns: "repeat(2, 1fr)", gap: 1, background: "var(--paper-200)", border: "1px solid var(--paper-200)" }}>
            {[
              ["01", "nav_advisory",   "advisory_lede",  "/vermoegen"],
              ["02", "nav_trading",    "trade_lede",     "/trading"],
              ["03", "nav_planning",   "plan_intro",     "/planung"],
              ["04", "nav_analysis",   "pa_lede",        "/analyse"],
            ].map(([n, tk, dk, href]) => (
              <a key={n} href={"#"+href} style={{ background: "var(--paper-50)", padding: 44, minHeight: 230, display: "grid", gridTemplateColumns: "52px 1fr", gap: 22, alignItems: "start" }}>
                <div className="kicker" style={{ color: "var(--gold-deep)" }}>{n}</div>
                <div>
                  <h3 style={{ fontFamily: "var(--serif)", fontSize: 29, lineHeight: 1.06, fontWeight: 400, marginBottom: 13, letterSpacing: "-0.015em" }}>{t(tk)}</h3>
                  <p style={{ color: "var(--slate-700)", fontSize: 14.5, lineHeight: 1.6, maxWidth: "44ch" }}>{t(dk)}</p>
                  <div style={{ marginTop: 18, fontSize: 12, color: "var(--ink-900)", fontWeight: 500 }}>
                    {t("pillar_learn")} →
                  </div>
                </div>
              </a>
            ))}
          </div>
        </div>
      </section>

      {/* VALUES STRIP */}
      <section style={{ background: "var(--paper-100)", padding: "92px 0", borderTop: "1px solid var(--paper-200)", borderBottom: "1px solid var(--paper-200)" }}>
        <div className="wrap">
          <div style={{ display: "grid", gridTemplateColumns: "1fr 2.4fr", gap: 72 }}>
            <div>
              <div className="eyebrow">{t("values_eyebrow")}</div>
              <h2 className="h-section" style={{ marginTop: 22 }}>{t("values_title")}</h2>
              <a href="#/werte" style={{ display: "inline-block", marginTop: 24, color: "var(--ink-900)", fontSize: 13, fontWeight: 500, borderBottom: "1px solid var(--ink-900)", paddingBottom: 3 }}>
                {isDe ? "Alle Werte lesen" : "Read all values"} →
              </a>
            </div>
            <div style={{ display: "grid", gridTemplateColumns: "repeat(2, 1fr)", gap: "30px 44px" }}>
              {[1,2,3,4].map(n => (
                <div key={n} style={{ borderTop: "1px solid var(--ink-950)", paddingTop: 16 }}>
                  <div style={{ fontFamily: "var(--mono)", fontSize: 10, color: "var(--gold-deep)", letterSpacing: "0.08em", marginBottom: 10 }}>0{n}</div>
                  <h3 style={{ fontFamily: "var(--serif)", fontSize: 21, fontWeight: 400, marginBottom: 8, letterSpacing: "-0.01em" }}>{t(`val_${n}_t`)}</h3>
                  <p style={{ color: "var(--slate-700)", fontSize: 13.5, lineHeight: 1.55 }}>{t(`val_${n}_d`)}</p>
                </div>
              ))}
            </div>
          </div>
        </div>
      </section>

      {/* TEAM */}
      <section style={{ padding: "88px 0", borderTop: "1px solid var(--paper-200)" }}>
        <div className="wrap">
          <div style={{ display: "flex", justifyContent: "space-between", alignItems: "flex-end", gap: 40, marginBottom: 40 }}>
            <div>
              <div className="eyebrow">{isDe ? "DAS TEAM" : "THE TEAM"}</div>
              <h2 className="h-section" style={{ marginTop: 20 }}>
                {isDe ? "Menschen, die Ihr Mandat kennen." : "People who know your mandate."}
              </h2>
            </div>
            <a href="#/team" className="btn btn-ghost btn-sm">{isDe ? "Ganzes Team →" : "Full team →"}</a>
          </div>
          <div className="home-team">
            {(window.TEAM || []).slice(0, 8).map((m) => (
              <div className="home-team-card" key={m.name}>
                <div className="home-team-ini">{m.name.replace(/^Dr\.\s*/, "").split(/\s+/).map(s => s[0]).slice(0, 2).join("")}</div>
                <div className="home-team-name">{m.name}</div>
                <div className="home-team-role">{m.role[lang] || m.role.de}</div>
                <div className="home-team-focus">{m.focus[lang] || m.focus.de}</div>
              </div>
            ))}
          </div>
          <div style={{ marginTop: 18, fontSize: 12, color: "var(--slate-500)", fontFamily: "var(--mono)" }}>
            {isDe ? "16 Mitarbeitende · Stuttgart" : "16 people · Stuttgart"}
          </div>
        </div>
      </section>

      {/* HOUSE / ADDRESS */}
      <section style={{ padding: "96px 0" }}>
        <div className="wrap" style={{ display: "grid", gridTemplateColumns: "1.1fr 1fr", gap: 72, alignItems: "center" }}>
          <div>
            <div className="eyebrow">{t("contact_eyebrow")}</div>
            <h2 className="h-section" style={{ marginTop: 22, marginBottom: 26 }}>
              {isDe ? "Eine Adresse. Keine Filialkulisse." : "One address. No branch theatre."}
            </h2>
            <p style={{ color: "var(--slate-700)", fontSize: 15.5, lineHeight: 1.7, maxWidth: "46ch" }}>
              {isDe
                ? "Wir sitzen in der Königstraße in Stuttgart und arbeiten für Mandate im gesamten DACH-Raum. Wer anruft, erreicht einen Menschen, der das Mandat kennt."
                : "We sit on Königstraße in Stuttgart and work for mandates across DACH. Anyone who calls reaches a person who knows the mandate."}
            </p>
            <div style={{ display: "grid", gridTemplateColumns: "1fr 1fr", gap: 26, marginTop: 34, maxWidth: 520 }}>
              {[
                [t("contact_phone"), "+49 711 9330 800"],
                [t("contact_hours"), t("contact_hours_value").replace("·", "·\n")],
              ].map(([k, v]) => (
                <div key={k} style={{ borderTop: "1px solid var(--paper-300)", paddingTop: 12 }}>
                  <div className="kicker" style={{ marginBottom: 8 }}>{k}</div>
                  <div style={{ fontFamily: "var(--mono)", fontSize: 13, whiteSpace: "pre-line", lineHeight: 1.6 }}>{v}</div>
                </div>
              ))}
            </div>
          </div>
          <div className="map-embed">
            <iframe title="Aurevon · Königstraße 41, Stuttgart" loading="lazy" referrerPolicy="no-referrer-when-downgrade"
              src="https://maps.google.com/maps?q=K%C3%B6nigstra%C3%9Fe%2041%2C%2070173%20Stuttgart&t=m&z=17&output=embed"></iframe>
            <div className="map-embed-cap"><span>Königstraße 41 · Stuttgart</span><span>{isDe ? "Satellit" : "Satellite"}</span></div>
          </div>
        </div>
      </section>

      {/* CTA STRIP */}
      <section style={{ background: "var(--ink-950)", color: "var(--paper-50)", padding: "76px 0" }}>
        <div className="wrap" style={{ display: "grid", gridTemplateColumns: "1.3fr 1fr", gap: 56, alignItems: "center" }}>
          <h2 className="h-section" style={{ color: "var(--paper-50)" }}>
            {isDe ? "Lassen Sie uns ein erstes Gespräch führen." : "Let's have a first conversation."}
          </h2>
          <div>
            <p style={{ color: "var(--ink-200)", fontSize: 15.5, lineHeight: 1.6, marginBottom: 26, maxWidth: "44ch" }}>
              {isDe
                ? "Kostenfrei, vertraulich, unverbindlich. Wir antworten innerhalb eines Werktags."
                : "Complimentary, confidential, no obligation. We reply within one business day."}
            </p>
            <div style={{ display: "flex", gap: 10 }}>
              <a href="#/kontakt" className="btn btn-gold btn-lg">{t("hero_cta_primary")} →</a>
              <a href="#/team" className="btn btn-lg" style={{ color: "var(--paper-50)", border: "1px solid rgba(255,255,255,0.22)" }}>{t("nav_team")}</a>
            </div>
          </div>
        </div>
      </section>
    </>
  );
}

/* ---------- Hero card — quote + house facts ---------- */
function HeroQuoteCard({ lang }) {
  const t = window.useT(lang);
  return (
    <div style={{ background: "var(--paper-50)", border: "1px solid var(--ink-950)", padding: 32 }}>
      <div style={{ display: "flex", justifyContent: "space-between", fontSize: 9, letterSpacing: "0.18em", color: "var(--gold-deep)", marginBottom: 24, fontFamily: "var(--mono)", textTransform: "uppercase" }}>
        <span>● {t("hero_card_head")}</span>
        <span>{t("hero_card_tail")}</span>
      </div>
      <p style={{ fontFamily: "var(--serif)", fontSize: 23, lineHeight: 1.4, letterSpacing: "-0.008em" }}>
        {t("hero_quote")}
      </p>
      <div style={{ marginTop: 26, paddingTop: 20, borderTop: "1px solid var(--paper-300)", display: "grid", gridTemplateColumns: "1fr 1fr", gap: 16, fontFamily: "var(--mono)", fontSize: 10.5 }}>
        {[
          [lang === "de" ? "Treuhand" : "Fiduciary", t("hero_badge_fid")],
          [lang === "de" ? "Honorar" : "Fee-only", t("hero_badge_fee")],
          [lang === "de" ? "Eigentum" : "Owner-led", t("hero_badge_priv")],
          [lang === "de" ? "Register" : "Register", t("hero_badge_reg")],
        ].map(([a, b]) => (
          <div key={a}>
            <div style={{ color: "var(--slate-500)", marginBottom: 4, textTransform: "uppercase", letterSpacing: "0.1em", fontSize: 9 }}>{a}</div>
            <div style={{ color: "var(--ink-950)", fontSize: 12, fontFamily: "var(--sans)" }}>{b}</div>
          </div>
        ))}
      </div>
    </div>
  );
}

window.HomePage = HomePage;
