// Header.jsx — sticky top nav, links + WhatsApp/Telegram

function Header() {
  const [open, setOpen] = useState(false);
  const [scrolled, setScrolled] = useState(false);
  useLucide();

  useEffect(() => {
    const onScroll = () => setScrolled(window.scrollY > 8);
    window.addEventListener("scroll", onScroll);
    return () => window.removeEventListener("scroll", onScroll);
  }, []);

  const links = [
    { label: "Services",     href: "#services" },
    { label: "How it works", href: "#how" },
    { label: "About",        href: "#about" },
    { label: "FAQs",         href: "#faqs" },
    { label: "Contact",      href: "#contact" },
  ];

  const SocialBtn = ({ icon, label, href, bg }) => (
    <a href={href} target="_blank" rel="noopener" title={label}
       style={{
         display: "inline-flex", alignItems: "center", gap: 8,
         padding: "9px 14px", borderRadius: 10,
         border: "1px solid var(--line)",
         background: "var(--white)",
         color: "var(--ink)",
         fontSize: 13, fontWeight: 600, textDecoration: "none",
         transition: "transform .12s var(--t-ease), border-color .15s var(--t-ease)",
       }}
       onMouseEnter={e => { e.currentTarget.style.transform = "translateY(-1px)"; e.currentTarget.style.borderColor = "var(--ink)"; }}
       onMouseLeave={e => { e.currentTarget.style.transform = "translateY(0)"; e.currentTarget.style.borderColor = "var(--line)"; }}>
      <span style={{ width: 20, height: 20, borderRadius: 5, background: bg,
                     display: "inline-flex", alignItems: "center", justifyContent: "center", color: "#fff" }}>
        <i data-lucide={icon} style={{ width: 12, height: 12, strokeWidth: 2.5 }}></i>
      </span>
      {label}
    </a>
  );

  return (
    <header style={{
      position: "relative", zIndex: 50,
      background: "rgba(255,255,255,0.92)",
      backdropFilter: "saturate(180%) blur(10px)",
      WebkitBackdropFilter: "saturate(180%) blur(10px)",
      borderBottom: "1px solid var(--line)",
      transition: "border-color .2s",
    }}>
      <div style={{
        maxWidth: 1200, margin: "0 auto", padding: "14px 32px",
        display: "flex", alignItems: "center", justifyContent: "space-between", gap: 24,
      }}>
        <a href="#top" style={{ display: "block" }}><Logo height={28} /></a>

        <nav style={{ display: "flex", alignItems: "center", gap: 28 }} className="hide-mobile">
          {links.map(l => (
            <a key={l.label} href={l.href}
               style={{ fontSize: 14, fontWeight: 500, color: "var(--ink-soft)",
                        textDecoration: "none", transition: "color .12s" }}
               onMouseEnter={e => e.currentTarget.style.color = "var(--ink)"}
               onMouseLeave={e => e.currentTarget.style.color = "var(--ink-soft)"}>
              {l.label}
            </a>
          ))}
        </nav>

        <div style={{ display: "flex", alignItems: "center", gap: 10 }} className="hide-mobile">
          <SocialBtn icon="message-circle" label="WhatsApp" href="https://wa.me/447572367442" bg="#25D366" />
          <SocialBtn icon="send" label="Telegram" href="https://t.me/mikhailtruf" bg="#229ED9" />
        </div>

        <button onClick={() => setOpen(!open)} className="show-mobile" style={{
          background: "transparent", border: "1px solid var(--line)", borderRadius: 10,
          padding: 8, cursor: "pointer",
        }}>
          <i data-lucide={open ? "x" : "menu"} style={{ width: 20, height: 20 }}></i>
        </button>
      </div>

      {open && (
        <div className="show-mobile" style={{
          padding: "12px 24px 20px", borderTop: "1px solid var(--line)", background: "#fff",
          flexDirection: "column", gap: 4,
        }}>
          {links.map(l => (
            <a key={l.label} href={l.href} onClick={() => setOpen(false)}
               style={{
                 padding: "12px 4px", fontSize: 16, color: "var(--ink)",
                 textDecoration: "none", borderBottom: "1px solid var(--line-2)",
                 display: "block",
               }}>{l.label}</a>
          ))}
          <div style={{ marginTop: 16, display: "flex", gap: 10 }}>
            <SocialBtn icon="message-circle" label="WhatsApp" href="https://wa.me/447572367442" bg="#25D366" />
            <SocialBtn icon="send" label="Telegram" href="https://t.me/mikhailtruf" bg="#229ED9" />
          </div>
        </div>
      )}
    </header>
  );
}
window.Header = Header;
