const DS_chrome = window.HomesByJoseSolisDesignSystem_53d05b;

function NavBar({ current, onNav, transparent }) {
  const { Button } = DS_chrome;
  const [scrolled, setScrolled] = React.useState(false);
  const [open, setOpen] = React.useState(false);
  React.useEffect(() => {
    const el = document.querySelector("[data-scroll-root]") || window;
    const onScroll = () => {
      const t = el === window ? window.scrollY : el.scrollTop;
      setScrolled(t > 12);
    };
    el.addEventListener("scroll", onScroll);
    onScroll();
    return () => el.removeEventListener("scroll", onScroll);
  }, []);

  const solid = !transparent || scrolled;
  const links = [
    { id: "home", label: "Home" },
    { id: "about", label: "About Jose" },
    { id: "testimonials", label: "Reviews" },
    { id: "contact", label: "Contact" },
  ];
  const fg = solid ? "var(--navy-700)" : "#fff";

  return (
    <header
      style={{
        position: "sticky", top: 0, zIndex: 50,
        background: solid ? "rgba(255,255,255,0.92)" : "transparent",
        backdropFilter: solid ? "saturate(180%) blur(12px)" : "none",
        borderBottom: solid ? "1px solid var(--line)" : "1px solid transparent",
        transition: "background .3s ease, border-color .3s ease",
      }}
    >
      <div style={{ maxWidth: "var(--container)", margin: "0 auto", padding: "0 var(--gutter)", height: "76px", display: "flex", alignItems: "center", justifyContent: "space-between" }}>
        <button onClick={() => onNav("home")} style={{ display: "flex", flexDirection: "column", gap: "2px", background: "none", border: "none", cursor: "pointer", textAlign: "left", padding: 0 }}>
          <span style={{ fontFamily: "var(--font-display)", fontSize: "21px", fontWeight: 600, letterSpacing: "-0.01em", color: fg }}>
            Homes <span style={{ color: "var(--gold-500)" }}>by</span> Jose Solis
          </span>
          <span style={{ fontFamily: "var(--font-ui)", fontSize: "10px", fontWeight: 600, letterSpacing: "0.18em", textTransform: "uppercase", color: solid ? "var(--slate-400)" : "rgba(255,255,255,0.75)" }}>
            Greater Orlando Real Estate
          </span>
        </button>

        <nav style={{ display: "flex", alignItems: "center", gap: "4px" }} className="nav-desktop">
          {links.map((l) => (
            <button key={l.id} onClick={() => onNav(l.id)}
              style={{
                background: "none", border: "none", cursor: "pointer",
                fontFamily: "var(--font-ui)", fontSize: "14.5px", fontWeight: 600,
                color: current === l.id ? "var(--gold-600)" : fg,
                padding: "8px 14px", borderRadius: "var(--radius-sm)",
              }}>
              {l.label}
            </button>
          ))}
          <span style={{ width: "12px" }} />
          <Button variant="accent" size="sm" onClick={() => onNav("contact")}>Schedule a Tour</Button>
        </nav>

        <button className="nav-mobile-btn" onClick={() => setOpen((o) => !o)}
          style={{ display: "none", background: "none", border: "none", cursor: "pointer", color: fg }}>
          <Icon name={open ? "close" : "menu"} size={26} />
        </button>
      </div>

      {open && (
        <div style={{ background: "#fff", borderTop: "1px solid var(--line)", padding: "8px var(--gutter) 16px", display: "flex", flexDirection: "column", gap: "4px" }}>
          {links.map((l) => (
            <button key={l.id} onClick={() => { onNav(l.id); setOpen(false); }}
              style={{ background: "none", border: "none", textAlign: "left", padding: "12px 6px", fontFamily: "var(--font-ui)", fontSize: "16px", fontWeight: 600, color: "var(--navy-700)", borderBottom: "1px solid var(--line-soft)", cursor: "pointer" }}>
              {l.label}
            </button>
          ))}
        </div>
      )}
    </header>
  );
}

function ContactCTA({ onNav }) {
  const { Button } = DS_chrome;
  return (
    <section style={{ background: "var(--navy-700)", color: "#fff", position: "relative", overflow: "hidden" }}>
      <div style={{ position: "absolute", inset: 0, background: "radial-gradient(1200px 400px at 80% -20%, rgba(200,149,68,0.22), transparent 60%)" }} />
      <div style={{ maxWidth: "var(--container)", margin: "0 auto", padding: "84px var(--gutter)", position: "relative", display: "grid", gridTemplateColumns: "1.4fr 1fr", gap: "48px", alignItems: "center" }} className="cta-grid m-sec">
        <div>
          <div style={{ fontFamily: "var(--font-ui)", fontSize: "13px", fontWeight: 700, letterSpacing: "0.16em", textTransform: "uppercase", color: "var(--gold-400)", marginBottom: "16px" }}>Let's talk</div>
          <h2 style={{ fontFamily: "var(--font-display)", fontSize: "40px", fontWeight: 600, lineHeight: 1.12, margin: 0, letterSpacing: "-0.015em" }}>
            Ready to find your place in Florida?
          </h2>
          <p style={{ fontFamily: "var(--font-body)", fontSize: "18px", lineHeight: 1.6, color: "rgba(255,255,255,0.82)", marginTop: "18px", maxWidth: "520px" }}>
            Whether you're buying, selling, or just exploring the market, I'll give you straight answers and a clear plan. No pressure — just guidance.
          </p>
          <div style={{ display: "flex", gap: "14px", marginTop: "30px", flexWrap: "wrap" }}>
            <Button variant="accent" size="lg" iconLeft={<Icon name="phone" size={18} stroke="var(--text-on-accent)" />} onClick={() => onNav("contact")}>Call 407-692-4587</Button>
            <Button variant="secondary" size="lg" onClick={() => onNav("contact")}
              style={{ display: "inline-flex", alignItems: "center", justifyContent: "center", gap: "10px", fontFamily: "var(--font-ui)", fontWeight: 600, letterSpacing: "0.005em", lineHeight: 1, padding: "16px 30px", fontSize: "16.5px", borderRadius: "var(--radius-sm)", cursor: "pointer", background: "transparent", color: "#fff", border: "1.5px solid rgba(255,255,255,0.7)" }}
              iconLeft={<Icon name="mail" size={18} />}>Send a Message</Button>
          </div>
        </div>
        <div style={{ background: "rgba(255,255,255,0.06)", border: "1px solid rgba(255,255,255,0.14)", borderRadius: "var(--radius-lg)", padding: "28px" }}>
          {[
            { icon: "shield", t: "Veteran-owned", s: "15+ years military service" },
            { icon: "mapPin", t: "Local expertise", s: "18 Central Florida cities" },
            { icon: "award", t: "eXp / La Rosa Realty", s: "Licensed Florida REALTOR®" },
          ].map((r) => (
            <div key={r.t} style={{ display: "flex", gap: "14px", alignItems: "center", padding: "14px 0", borderBottom: "1px solid rgba(255,255,255,0.10)" }}>
              <span style={{ width: "42px", height: "42px", borderRadius: "var(--radius-sm)", background: "rgba(200,149,68,0.18)", display: "flex", alignItems: "center", justifyContent: "center", flex: "none" }}>
                <Icon name={r.icon} size={20} stroke="var(--gold-400)" />
              </span>
              <div>
                <div style={{ fontFamily: "var(--font-ui)", fontWeight: 700, fontSize: "15px" }}>{r.t}</div>
                <div style={{ fontFamily: "var(--font-ui)", fontSize: "13px", color: "rgba(255,255,255,0.7)" }}>{r.s}</div>
              </div>
            </div>
          ))}
        </div>
      </div>
    </section>
  );
}

function SiteFooter({ onNav }) {
  return (
    <footer style={{ background: "var(--navy-900)", color: "rgba(255,255,255,0.72)", fontFamily: "var(--font-ui)" }}>
      <div style={{ maxWidth: "var(--container)", margin: "0 auto", padding: "56px var(--gutter) 28px", display: "grid", gridTemplateColumns: "1.6fr 1fr 1.2fr", gap: "40px" }} className="footer-grid">
        <div>
          <div style={{ fontFamily: "var(--font-display)", fontSize: "20px", fontWeight: 600, color: "#fff" }}>
            Homes <span style={{ color: "var(--gold-500)" }}>by</span> Jose Solis
          </div>
          <p style={{ fontSize: "13.5px", lineHeight: 1.7, marginTop: "14px", maxWidth: "300px" }}>
            Helping families buy, sell, and rent across the Greater Orlando area with discipline, honesty, and care.
          </p>
          <div style={{ display: "inline-flex", marginTop: "20px", background: "#fff", borderRadius: "12px", padding: "10px 14px", boxShadow: "0 8px 24px rgba(12,26,51,0.12)" }}>
            <img src="../../assets/IMG_1246.jpeg" alt="La Rosa Realty" style={{ display: "block", height: "54px", width: "auto", maxWidth: "100%" }} />
          </div>
        </div>
        <div>
          <div style={{ fontWeight: 700, color: "#fff", fontSize: "13px", letterSpacing: "0.08em", textTransform: "uppercase", marginBottom: "14px" }}>Explore</div>
          {["Home","About Jose","Reviews","Contact"].map((l, i) => (
            <button key={l} onClick={() => onNav(["home","about","testimonials","contact"][i])} style={{ display: "block", background: "none", border: "none", color: "inherit", cursor: "pointer", fontSize: "14px", padding: "6px 0", fontFamily: "var(--font-ui)" }}>{l}</button>
          ))}
        </div>
        <div>
          <div style={{ fontWeight: 700, color: "#fff", fontSize: "13px", letterSpacing: "0.08em", textTransform: "uppercase", marginBottom: "14px" }}>Get in touch</div>
          <div style={{ display: "flex", alignItems: "center", gap: "9px", fontSize: "14px", padding: "6px 0" }}><Icon name="phone" size={16} stroke="var(--gold-400)" /> 407-692-4587</div>
          <div style={{ display: "flex", alignItems: "center", gap: "9px", fontSize: "13.5px", padding: "6px 0" }}><Icon name="mail" size={16} stroke="var(--gold-400)" /> jose.solistheflrealtor@gmail.com</div>
          <div style={{ display: "flex", gap: "10px", marginTop: "14px", flexWrap: "wrap" }}>
            {window.SOCIALS.map((s) => (
              <a key={s.name} href={s.url} target="_blank" rel="noopener noreferrer" aria-label={s.name} title={s.name}
                style={{ width: "38px", height: "38px", borderRadius: "var(--radius-sm)", background: "rgba(255,255,255,0.08)", display: "flex", alignItems: "center", justifyContent: "center", color: "#fff", textDecoration: "none" }}>
                <Icon name={s.icon} size={18} stroke={s.icon === "tiktok" ? "none" : "#fff"} fill={s.icon === "tiktok" ? "#fff" : "none"} />
              </a>
            ))}
          </div>
          <a href={window.GOOGLE_REVIEWS_URL} target="_blank" rel="noopener noreferrer"
            style={{ display: "inline-flex", alignItems: "center", justifyContent: "center", marginTop: "18px", background: "rgba(200,149,68,0.14)", color: "#fff", border: "1px solid rgba(200,149,68,0.4)", borderRadius: "var(--radius-sm)", padding: "10px 14px", fontFamily: "var(--font-ui)", fontWeight: 700, fontSize: "13px", textDecoration: "none" }}>
            Read Google Reviews
          </a>
        </div>
      </div>
      <div style={{ borderTop: "1px solid rgba(255,255,255,0.1)" }}>
        <div style={{ maxWidth: "var(--container)", margin: "0 auto", padding: "20px var(--gutter)", display: "flex", justifyContent: "space-between", flexWrap: "wrap", gap: "10px", fontSize: "12.5px", color: "rgba(255,255,255,0.5)" }}>
          <span>© 2026 Homes by Jose Solis · La Rosa Realty</span>
          <span>Equal Housing Opportunity · Licensed in Florida</span>
        </div>
      </div>
    </footer>
  );
}

Object.assign(window, { NavBar, ContactCTA, SiteFooter, VideoTestimonialCard, VideoLightbox });

function VideoTestimonialCard({ t, onPlay, compact }) {
  const [hover, setHover] = React.useState(false);
  return (
    <figure
      onClick={() => onPlay(t)}
      onMouseEnter={() => setHover(true)}
      onMouseLeave={() => setHover(false)}
      style={{
        margin: compact ? 0 : "0 0 24px", breakInside: "avoid", cursor: "pointer",
        background: "var(--surface)", border: "1px solid var(--line)", borderRadius: "var(--radius-lg)",
        overflow: "hidden", boxShadow: hover ? "var(--shadow-lg)" : "var(--shadow-sm)",
        transform: hover ? "translateY(-4px)" : "none",
        transition: "transform var(--dur) var(--ease-out), box-shadow var(--dur) var(--ease-out)",
        fontFamily: "var(--font-ui)", display: "inline-block", width: "100%",
      }}
    >
      <div style={{ position: "relative", aspectRatio: "16 / 10", overflow: "hidden" }}>
        {t.src ? (
          <video src={t.src + "#t=0.1"} poster={t.poster} muted playsInline preload="metadata" tabIndex={-1}
            style={{ width: "100%", height: "100%", objectFit: "cover", display: "block", pointerEvents: "none", transition: "transform var(--dur-slow) var(--ease-out)", transform: hover ? "scale(1.05)" : "scale(1)" }} />
        ) : (
          <img src={t.poster} alt={t.name} style={{ width: "100%", height: "100%", objectFit: "cover", transition: "transform var(--dur-slow) var(--ease-out)", transform: hover ? "scale(1.05)" : "scale(1)" }} />
        )}
        <span style={{ position: "absolute", inset: 0, background: "linear-gradient(180deg, rgba(12,26,51,0.05) 0%, rgba(12,26,51,0.55) 100%)" }} />
        {/* Play button */}
        <span style={{ position: "absolute", top: "50%", left: "50%", transform: `translate(-50%,-50%) scale(${hover ? 1.08 : 1})`, transition: "transform var(--dur) var(--ease-out)", width: "62px", height: "62px", borderRadius: "var(--radius-pill)", background: "rgba(255,255,255,0.94)", display: "flex", alignItems: "center", justifyContent: "center", boxShadow: "var(--shadow-lg)" }}>
          <svg width="22" height="22" viewBox="0 0 24 24" aria-hidden="true"><path d="M8 5.5v13l11-6.5z" fill="var(--navy-700)" /></svg>
        </span>
        {/* Duration */}
        {t.duration ? (
          <span style={{ position: "absolute", bottom: "12px", right: "12px", background: "rgba(12,26,51,0.78)", color: "#fff", fontSize: "12px", fontWeight: 600, letterSpacing: "0.02em", padding: "4px 9px", borderRadius: "var(--radius-xs)", display: "flex", alignItems: "center", gap: "6px" }}>
            <svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="var(--gold-400)" strokeWidth="2" aria-hidden="true"><circle cx="12" cy="12" r="9" /><path d="M12 8v4l3 2" strokeLinecap="round" /></svg>
            {t.duration}
          </span>
        ) : null}
        {/* Type badge */}
        {t.type ? (
          <span style={{ position: "absolute", top: "12px", left: "12px", background: "var(--gold-500)", color: "var(--text-on-accent)", fontSize: "10.5px", fontWeight: 700, letterSpacing: "0.06em", textTransform: "uppercase", padding: "5px 10px", borderRadius: "var(--radius-pill)" }}>{t.type} Story</span>
        ) : null}
      </div>
      <figcaption style={{ padding: compact ? "20px" : "22px" }}>
        <div style={{ display: "flex", alignItems: "center", gap: "12px" }}>
          <span style={{ width: "40px", height: "40px", borderRadius: "var(--radius-pill)", background: "var(--navy-700)", color: "#fff", display: "flex", alignItems: "center", justifyContent: "center", fontWeight: 700, fontSize: "15px", flex: "none" }}>{t.name.trim()[0]}</span>
          <span>
            <span style={{ display: "block", fontWeight: 700, fontSize: "14.5px", color: "var(--navy-700)" }}>{t.name}</span>
            {t.city ? <span style={{ display: "block", fontSize: "13px", color: "var(--slate-400)", marginTop: "2px" }}>{t.city}</span> : null}
          </span>
        </div>
      </figcaption>
    </figure>
  );
}

function VideoLightbox({ video, onClose }) {
  React.useEffect(() => {
    const onKey = (e) => { if (e.key === "Escape") onClose(); };
    window.addEventListener("keydown", onKey);
    return () => window.removeEventListener("keydown", onKey);
  }, [onClose]);
  if (!video) return null;
  return (
    <div onClick={onClose} className="lightbox" style={{ position: "fixed", inset: 0, zIndex: 200, background: "rgba(8,16,30,0.82)", backdropFilter: "blur(6px)", display: "flex", alignItems: "center", justifyContent: "center", padding: "32px" }}>
      <div onClick={(e) => e.stopPropagation()} style={{ width: "min(900px, 100%)", background: "var(--navy-900)", borderRadius: "var(--radius-lg)", overflow: "hidden", boxShadow: "var(--shadow-xl)" }}>
        <div style={{ position: "relative", background: "#000", display: "flex", alignItems: "center", justifyContent: "center", ...(video.src ? {} : { aspectRatio: "16 / 9" }) }}>
          {video.src ? (
            <video src={video.src} poster={video.poster} controls autoPlay playsInline style={{ display: "block", maxWidth: "100%", maxHeight: "78vh", objectFit: "contain", background: "#000" }} />
          ) : (
            <React.Fragment>
              <img src={video.poster} alt={video.name} style={{ width: "100%", height: "100%", objectFit: "cover", opacity: 0.55 }} />
              <div style={{ position: "absolute", inset: 0, display: "flex", flexDirection: "column", alignItems: "center", justifyContent: "center", textAlign: "center", padding: "24px", color: "#fff", fontFamily: "var(--font-ui)" }}>
                <span style={{ width: "72px", height: "72px", borderRadius: "var(--radius-pill)", background: "rgba(255,255,255,0.94)", display: "flex", alignItems: "center", justifyContent: "center", marginBottom: "18px", boxShadow: "var(--shadow-lg)" }}>
                  <svg width="26" height="26" viewBox="0 0 24 24" aria-hidden="true"><path d="M8 5.5v13l11-6.5z" fill="var(--navy-700)" /></svg>
                </span>
                <div style={{ fontFamily: "var(--font-display)", fontSize: "21px", fontWeight: 600 }}>{video.name}'s video testimonial</div>
                <div style={{ fontSize: "13.5px", color: "rgba(255,255,255,0.7)", marginTop: "8px", maxWidth: "420px", lineHeight: 1.5 }}>Add the video file to play it here. Drop an MP4 path into this testimonial's <code style={{ color: "var(--gold-400)" }}>src</code> field in data.jsx.</div>
              </div>
            </React.Fragment>
          )}
        </div>
        <div style={{ display: "flex", alignItems: "center", justifyContent: "space-between", padding: "18px 22px", gap: "16px" }}>
          <div style={{ fontFamily: "var(--font-ui)", color: "#fff" }}>
            <div style={{ fontWeight: 700, fontSize: "15px" }}>{video.name}</div>
            <div style={{ fontSize: "13px", color: "rgba(255,255,255,0.6)", marginTop: "2px" }}>{[video.city, video.type, video.duration].filter(Boolean).join(" · ")}</div>
          </div>
          <button onClick={onClose} style={{ background: "rgba(255,255,255,0.1)", border: "none", borderRadius: "var(--radius-sm)", width: "40px", height: "40px", display: "flex", alignItems: "center", justifyContent: "center", cursor: "pointer", color: "#fff", flex: "none" }}>
            <svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" aria-hidden="true"><path d="M18 6 6 18M6 6l12 12" /></svg>
          </button>
        </div>
      </div>
    </div>
  );
}
