/* global React, ReactDOM, Nav, Hero, Services, ProblemFinder, Process, Testimonials, FAQ, Footer, FloatingWhatsApp, fireConfetti */

function App() {
  React.useEffect(() => {
    let buf = "";
    const onKey = (e) => {
      if (e.target.tagName === "INPUT" || e.target.tagName === "TEXTAREA") return;
      buf = (buf + e.key.toLowerCase()).slice(-4);
      if (buf === "paul") {
        fireConfetti();
        buf = "";
      }
    };
    window.addEventListener("keydown", onKey);
    return () => window.removeEventListener("keydown", onKey);
  }, []);

  React.useEffect(() => {
    const code = ["ArrowUp", "ArrowUp", "ArrowDown", "ArrowDown", "ArrowLeft", "ArrowRight", "ArrowLeft", "ArrowRight", "b", "a"];
    let idx = 0;
    const onKey = (e) => {
      const k = e.key.length === 1 ? e.key.toLowerCase() : e.key;
      if (k === code[idx]) {
        idx++;
        if (idx === code.length) {
          document.body.classList.add("rainbow");
          fireConfetti();
          setTimeout(() => fireConfetti(), 400);
          setTimeout(() => fireConfetti(), 800);
          idx = 0;
        }
      } else {
        idx = 0;
      }
    };
    window.addEventListener("keydown", onKey);
    return () => window.removeEventListener("keydown", onKey);
  }, []);

  return (
    <>
      <Nav />
      <main>
        <Hero />
        <Services />
        <ProblemFinder />
        <Process />
        <PricingTeaser />
        <Testimonials />
        <FAQ />
        <ContactTeaser />
      </main>
      <Footer />
      <FloatingWhatsApp />
    </>
  );
}

function PricingTeaser() {
  return (
    <section className="section" style={{ position: "relative", overflow: "hidden" }}>
      <div className="wrap" style={{ position: "relative" }}>
        <div style={{ display: "grid", gridTemplateColumns: "1.1fr 1fr", gap: 60, alignItems: "center" }} className="teaser-grid">
          <div>
            <span className="eyebrow grad-text" style={{ fontWeight: 600 }}>Preise</span>
            <h2 className="section-title" style={{ marginBottom: 16 }}>
              Drei Preise.<br />
              <span className="ital grad-text">Keine Überraschungen.</span>
            </h2>
            <p className="section-sub" style={{ marginBottom: 32 }}>
              Klar, transparent und nur zahlen wenn gelöst. Egal ob Video-Hilfe, vor Ort oder Hardware.
            </p>
            <a href="preise.html" className="btn btn-grad btn-lg">
              Alle Preise ansehen
              <svg width="16" height="16" viewBox="0 0 16 16" fill="none">
                <path d="M3 8h10m0 0L8.5 3.5M13 8l-4.5 4.5" stroke="currentColor" strokeWidth="1.8" strokeLinecap="round" strokeLinejoin="round" />
              </svg>
            </a>
          </div>
          <div className="teaser-tiers">
            <MiniTier from="7,90 €" name="Video-Hilfe" desc="Bildschirm teilen, Problem lösen" highlight />
            <MiniTier from="14,90 €" name="Vor Ort" desc="Persönlich am Bodensee" />
            <MiniTier from="auf Anfrage" name="Hardware" desc="Diagnose & Vermittlung" />
          </div>
        </div>
      </div>
      <style>{`
        @media (max-width: 880px) {
          .teaser-grid { grid-template-columns: 1fr !important; gap: 32px !important; }
        }
        .teaser-tiers { display: flex; flex-direction: column; gap: 10px; }
      `}</style>
    </section>
  );
}

function MiniTier({ from, name, desc, highlight }) {
  return (
    <a href="preise.html" style={{
      display: "flex",
      alignItems: "center",
      gap: 20,
      padding: 22,
      background: highlight ? "linear-gradient(135deg, #faf5ff 0%, #fdf2f8 100%)" : "#fff",
      border: highlight ? "1px solid rgba(124,58,237,0.25)" : "1px solid var(--line)",
      borderRadius: 20,
      transition: "all .3s ease",
    }}
    onMouseEnter={(e) => { e.currentTarget.style.transform = "translateX(4px)"; e.currentTarget.style.borderColor = "rgba(124,58,237,0.5)"; }}
    onMouseLeave={(e) => { e.currentTarget.style.transform = "translateX(0)"; e.currentTarget.style.borderColor = highlight ? "rgba(124,58,237,0.25)" : "var(--line)"; }}
    >
      <div style={{ minWidth: 120, fontSize: 22, fontWeight: 600, letterSpacing: "-0.02em" }} className={highlight ? "grad-text" : ""}>
        {from}
      </div>
      <div style={{ flex: 1 }}>
        <div style={{ fontWeight: 600, fontSize: 16 }}>{name}</div>
        <div style={{ fontSize: 13, color: "var(--muted)", marginTop: 2 }}>{desc}</div>
      </div>
      <svg width="18" height="18" viewBox="0 0 16 16" fill="none">
        <path d="M3 8h10m0 0L8.5 3.5M13 8l-4.5 4.5" stroke="currentColor" strokeWidth="1.8" strokeLinecap="round" strokeLinejoin="round" />
      </svg>
    </a>
  );
}

function ContactTeaser() {
  return (
    <section style={{ padding: "120px 0", background: "var(--ink)", color: "#fff", position: "relative", overflow: "hidden" }}>
      <div className="blob" style={{ width: 500, height: 500, background: "#7c3aed", top: -100, left: -150, opacity: 0.4 }} />
      <div className="blob" style={{ width: 500, height: 500, background: "#ec4899", bottom: -150, right: -100, opacity: 0.35 }} />

      <div className="wrap" style={{ position: "relative", textAlign: "center" }}>
        <h2 className="section-title" style={{ color: "#fff", textAlign: "center", maxWidth: 800, margin: "0 auto 24px" }}>
          Bereit Ihr Problem zu <span className="ital" style={{ background: "linear-gradient(120deg, #c4b5fd, #f9a8d4)", WebkitBackgroundClip: "text", backgroundClip: "text", color: "transparent" }}>lösen?</span>
        </h2>
        <p className="section-sub" style={{ color: "rgba(255,255,255,0.7)", margin: "0 auto 40px", textAlign: "center" }}>
          Eine kurze Nachricht reicht. Ich melde mich meist innerhalb weniger Stunden zurück.
        </p>

        <div style={{ display: "flex", gap: 12, justifyContent: "center", flexWrap: "wrap" }}>
          <a href="kontakt.html" className="btn btn-grad btn-lg">
            Termin anfragen
            <svg width="16" height="16" viewBox="0 0 16 16" fill="none">
              <path d="M3 8h10m0 0L8.5 3.5M13 8l-4.5 4.5" stroke="currentColor" strokeWidth="1.8" strokeLinecap="round" strokeLinejoin="round" />
            </svg>
          </a>
          <a href="https://wa.me/4915122202137?text=Hallo%20Paul," target="_blank" rel="noopener" className="btn btn-lg" style={{ background: "#25D366", color: "#fff" }}>
            <svg width="18" height="18" viewBox="0 0 32 32" fill="#fff" style={{ marginRight: 4 }}>
              <path d="M16 3C8.8 3 3 8.8 3 16c0 2.3.6 4.5 1.7 6.4L3 29l6.8-1.7c1.8 1 3.9 1.5 6.2 1.5 7.2 0 13-5.8 13-13S23.2 3 16 3Zm7.5 18.4c-.3.9-1.8 1.7-2.5 1.8-.7.1-1.5.4-5.2-1-4.4-1.7-7.2-6.2-7.4-6.5-.2-.3-1.7-2.3-1.7-4.4 0-2.1 1.1-3.1 1.5-3.5.4-.4.8-.5 1.1-.5h.8c.3 0 .6 0 .9.7l1.4 3.4c.1.2.1.5-.1.7l-.6.7-.4.5c-.2.3-.4.5-.2.9.2.4.9 1.5 1.9 2.5 1.4 1.2 2.5 1.6 2.9 1.8.4.2.6.2.8-.1l1.2-1.4c.3-.3.6-.3.9-.2l3.1 1.5c.4.2.6.3.7.4.1.3.1 1 0 1.8Z" />
            </svg>
            WhatsApp jetzt
          </a>
        </div>

        <div style={{ marginTop: 40, fontSize: 14, color: "rgba(255,255,255,0.5)" }}>
          oder direkt schreiben an <a href="mailto:hilfe@paulfaller.me" style={{ color: "#fff", borderBottom: "1px solid rgba(255,255,255,0.3)" }}>hilfe@paulfaller.me</a>
        </div>
      </div>
    </section>
  );
}

function FloatingWhatsApp() {
  const [visible, setVisible] = React.useState(false);
  React.useEffect(() => {
    const onScroll = () => setVisible(window.scrollY > 600);
    onScroll();
    window.addEventListener("scroll", onScroll, { passive: true });
    return () => window.removeEventListener("scroll", onScroll);
  }, []);

  return (
    <a
      href="https://wa.me/4915122202137?text=Hallo%20Paul,"
      target="_blank"
      rel="noopener"
      aria-label="WhatsApp öffnen"
      style={{
        position: "fixed",
        bottom: 24, right: 24,
        width: 56, height: 56,
        borderRadius: 999,
        background: "#25D366",
        display: "flex", alignItems: "center", justifyContent: "center",
        boxShadow: "0 10px 30px rgba(37,211,102,0.4)",
        zIndex: 90,
        transition: "transform .3s cubic-bezier(.22,.61,.36,1), opacity .3s",
        opacity: visible ? 1 : 0,
        transform: visible ? "translateY(0) scale(1)" : "translateY(20px) scale(0.8)",
        pointerEvents: visible ? "auto" : "none",
      }}
      onMouseEnter={(e) => { e.currentTarget.style.transform = "translateY(-4px) scale(1.05)"; }}
      onMouseLeave={(e) => { e.currentTarget.style.transform = "translateY(0) scale(1)"; }}
    >
      <svg width="28" height="28" viewBox="0 0 32 32" fill="#fff">
        <path d="M16 3C8.8 3 3 8.8 3 16c0 2.3.6 4.5 1.7 6.4L3 29l6.8-1.7c1.8 1 3.9 1.5 6.2 1.5 7.2 0 13-5.8 13-13S23.2 3 16 3Zm7.5 18.4c-.3.9-1.8 1.7-2.5 1.8-.7.1-1.5.4-5.2-1-4.4-1.7-7.2-6.2-7.4-6.5-.2-.3-1.7-2.3-1.7-4.4 0-2.1 1.1-3.1 1.5-3.5.4-.4.8-.5 1.1-.5h.8c.3 0 .6 0 .9.7l1.4 3.4c.1.2.1.5-.1.7l-.6.7-.4.5c-.2.3-.4.5-.2.9.2.4.9 1.5 1.9 2.5 1.4 1.2 2.5 1.6 2.9 1.8.4.2.6.2.8-.1l1.2-1.4c.3-.3.6-.3.9-.2l3.1 1.5c.4.2.6.3.7.4.1.3.1 1 0 1.8Z" />
      </svg>
      <span style={{
        position: "absolute", inset: 0, borderRadius: 999,
        border: "2px solid #25D366",
        animation: "wa-pulse 2.4s ease-out infinite",
      }} />
      <style>{`
        @keyframes wa-pulse {
          0% { transform: scale(1); opacity: 0.8; }
          100% { transform: scale(1.6); opacity: 0; }
        }
      `}</style>
    </a>
  );
}

ReactDOM.createRoot(document.getElementById("root")).render(<App />);
