/* global React */
const { useState, useEffect, useRef } = React;

const GOOGLE_REVIEWS_URL = "https://www.google.com/search?q=the+trader+daddy+trading+academy+nyc#lrd=0x89c259a9e9b1b83b:0x0,1";

function GoogleBadge({ style }) {
  return (
    <a
      href={GOOGLE_REVIEWS_URL}
      target="_blank"
      rel="noopener noreferrer"
      style={{ display: "inline-flex", alignItems: "center", gap: 12, padding: "10px 16px",
               border: "1px solid var(--line)", borderRadius: 999, background: "var(--bg-1)",
               textDecoration: "none", flexShrink: 0, ...style }}
    >
      <div>
        <div style={{ display: "flex", gap: 6, alignItems: "center" }}>
          <span style={{ color: "#fbbc05", fontSize: 13, letterSpacing: "0.04em" }}>★★★★★</span>
          <span style={{ color: "var(--ink-0)", fontSize: 12, fontWeight: 600, whiteSpace: "nowrap" }}>#1 Trading Academy in NYC</span>
        </div>
        <div className="t-mono" style={{ fontSize: 10, color: "var(--ink-3)", marginTop: 3 }}>
          56 Google reviews · Rated by Google AI · 13 years
        </div>
      </div>
      <svg width="18" height="18" viewBox="0 0 24 24" aria-label="Google">
        <path d="M22.56 12.25c0-.78-.07-1.53-.2-2.25H12v4.26h5.92c-.26 1.37-1.04 2.53-2.21 3.31v2.77h3.57c2.08-1.92 3.28-4.74 3.28-8.09z" fill="#4285F4"/>
        <path d="M12 23c2.97 0 5.46-.98 7.28-2.66l-3.57-2.77c-.98.66-2.23 1.06-3.71 1.06-2.86 0-5.29-1.93-6.16-4.53H2.18v2.84C3.99 20.53 7.7 23 12 23z" fill="#34A853"/>
        <path d="M5.84 14.09c-.22-.66-.35-1.36-.35-2.09s.13-1.43.35-2.09V7.07H2.18C1.43 8.55 1 10.22 1 12s.43 3.45 1.18 4.93l2.85-2.22.81-.62z" fill="#FBBC05"/>
        <path d="M12 5.38c1.62 0 3.06.56 4.21 1.64l3.15-3.15C17.45 2.09 14.97 1 12 1 7.7 1 3.99 3.47 2.18 7.07l3.66 2.84c.87-2.6 3.3-4.53 6.16-4.53z" fill="#EA4335"/>
      </svg>
    </a>
  );
}

/* ============================================================
   SOCIAL ICONS — real SVG paths
   ============================================================ */
const SocialIcons = {
  IG: () => (
    <svg width="16" height="16" viewBox="0 0 24 24" fill="currentColor">
      <path d="M12 2.163c3.204 0 3.584.012 4.85.07 3.252.148 4.771 1.691 4.919 4.919.058 1.265.069 1.645.069 4.849 0 3.205-.012 3.584-.069 4.849-.149 3.225-1.664 4.771-4.919 4.919-1.266.058-1.644.07-4.85.07-3.204 0-3.584-.012-4.849-.07-3.26-.149-4.771-1.699-4.919-4.92-.058-1.265-.07-1.644-.07-4.849 0-3.204.013-3.583.07-4.849.149-3.227 1.664-4.771 4.919-4.919 1.266-.057 1.645-.069 4.849-.069zm0-2.163c-3.259 0-3.667.014-4.947.072-4.358.2-6.78 2.618-6.98 6.98-.059 1.281-.073 1.689-.073 4.948 0 3.259.014 3.668.072 4.948.2 4.358 2.618 6.78 6.98 6.98 1.281.058 1.689.072 4.948.072 3.259 0 3.668-.014 4.948-.072 4.354-.2 6.782-2.618 6.979-6.98.059-1.28.073-1.689.073-4.948 0-3.259-.014-3.667-.072-4.947-.196-4.354-2.617-6.78-6.979-6.98-1.281-.059-1.69-.073-4.949-.073zm0 5.838c-3.403 0-6.162 2.759-6.162 6.162s2.759 6.163 6.162 6.163 6.162-2.759 6.162-6.163c0-3.403-2.759-6.162-6.162-6.162zm0 10.162c-2.209 0-4-1.79-4-4 0-2.209 1.791-4 4-4s4 1.791 4 4c0 2.21-1.791 4-4 4zm6.406-11.845c-.796 0-1.441.645-1.441 1.44s.645 1.44 1.441 1.44c.795 0 1.439-.645 1.439-1.44s-.644-1.44-1.439-1.44z"/>
    </svg>
  ),
  X: () => (
    <svg width="15" height="15" viewBox="0 0 24 24" fill="currentColor">
      <path d="M18.244 2.25h3.308l-7.227 8.26 8.502 11.24H16.17l-4.714-6.231-5.401 6.231H2.748l7.73-8.835L1.254 2.25H8.08l4.259 5.63L18.244 2.25zm-1.161 17.52h1.833L7.084 4.126H5.117z"/>
    </svg>
  ),
  YT: () => (
    <svg width="17" height="17" viewBox="0 0 24 24" fill="currentColor">
      <path d="M23.498 6.186a3.016 3.016 0 0 0-2.122-2.136C19.505 3.545 12 3.545 12 3.545s-7.505 0-9.377.505A3.017 3.017 0 0 0 .502 6.186C0 8.07 0 12 0 12s0 3.93.502 5.814a3.016 3.016 0 0 0 2.122 2.136c1.871.505 9.376.505 9.376.505s7.505 0 9.377-.505a3.015 3.015 0 0 0 2.122-2.136C24 15.93 24 12 24 12s0-3.93-.502-5.814zM9.545 15.568V8.432L15.818 12l-6.273 3.568z"/>
    </svg>
  ),
  LI: () => (
    <svg width="16" height="16" viewBox="0 0 24 24" fill="currentColor">
      <path d="M20.447 20.452h-3.554v-5.569c0-1.328-.027-3.037-1.852-3.037-1.853 0-2.136 1.445-2.136 2.939v5.667H9.351V9h3.414v1.561h.046c.477-.9 1.637-1.85 3.37-1.85 3.601 0 4.267 2.37 4.267 5.455v6.286zM5.337 7.433a2.062 2.062 0 0 1-2.063-2.065 2.064 2.064 0 1 1 2.063 2.065zm1.782 13.019H3.555V9h3.564v11.452zM22.225 0H1.771C.792 0 0 .774 0 1.729v20.542C0 23.227.792 24 1.771 24h20.451C23.2 24 24 23.227 24 22.271V1.729C24 .774 23.2 0 22.222 0h.003z"/>
    </svg>
  ),
  WA: () => (
    <svg width="16" height="16" viewBox="0 0 24 24" fill="currentColor">
      <path d="M17.472 14.382c-.297-.149-1.758-.867-2.03-.967-.273-.099-.471-.148-.67.15-.197.297-.767.966-.94 1.164-.173.199-.347.223-.644.075-.297-.15-1.255-.463-2.39-1.475-.883-.788-1.48-1.761-1.653-2.059-.173-.297-.018-.458.13-.606.134-.133.298-.347.446-.52.149-.174.198-.298.298-.497.099-.198.05-.371-.025-.52-.075-.149-.669-1.612-.916-2.207-.242-.579-.487-.5-.669-.51-.173-.008-.371-.01-.57-.01-.198 0-.52.074-.792.372-.272.297-1.04 1.016-1.04 2.479 0 1.462 1.065 2.875 1.213 3.074.149.198 2.096 3.2 5.077 4.487.709.306 1.262.489 1.694.625.712.227 1.36.195 1.871.118.571-.085 1.758-.719 2.006-1.413.248-.694.248-1.289.173-1.413-.074-.124-.272-.198-.57-.347m-5.421 7.403h-.004a9.87 9.87 0 0 1-5.031-1.378l-.361-.214-3.741.982.998-3.648-.235-.374a9.86 9.86 0 0 1-1.51-5.26c.001-5.45 4.436-9.884 9.888-9.884 2.64 0 5.122 1.03 6.988 2.898a9.825 9.825 0 0 1 2.893 6.994c-.003 5.45-4.437 9.884-9.885 9.884m8.413-18.297A11.815 11.815 0 0 0 12.05 0C5.495 0 .16 5.335.157 11.892c0 2.096.547 4.142 1.588 5.945L.057 24l6.305-1.654a11.882 11.882 0 0 0 5.683 1.448h.005c6.554 0 11.89-5.335 11.893-11.893a11.821 11.821 0 0 0-3.48-8.413z"/>
    </svg>
  ),
};

function TradierBar() {
  const [hovered, setHovered] = React.useState(false);
  return (
    <div style={{
      width: "100%",
      background: "linear-gradient(100deg, oklch(22% 0.06 255) 0%, oklch(18% 0.08 250) 50%, oklch(20% 0.05 240) 100%)",
      borderBottom: "1px solid oklch(63% 0.20 255 / 0.25)",
      padding: "20px 32px",
      display: "flex",
      alignItems: "center",
      justifyContent: "center",
    }}>
      <div style={{
        display: "flex",
        flexDirection: "row",
        alignItems: "center",
        justifyContent: "center",
        gap: 28,
        flexWrap: "wrap",
      }}>
        {/* Tradier logo */}
        <div style={{ background: "oklch(97% 0.003 240)", borderRadius: 10, padding: "10px 20px", display: "inline-flex", alignItems: "center", flexShrink: 0 }}>
          <img src="media/tradier-logo.png" alt="Tradier" style={{ height: 44, width: "auto", display: "block" }} />
        </div>

        {/* Plus sign */}
        <span style={{ fontSize: 32, fontWeight: 300, color: "oklch(70% 0.12 255)", lineHeight: 1, flexShrink: 0 }}>+</span>

        {/* TraderDaddy logo */}
        <div style={{ background: "oklch(97% 0.003 240)", borderRadius: 10, padding: "10px 24px", display: "inline-flex", alignItems: "center", flexShrink: 0 }}>
          <img src="media/logo-main.png" alt="TraderDaddy" style={{ height: 64, width: "auto", display: "block" }} />
        </div>

        {/* Divider */}
        <div style={{ width: 1, height: 60, background: "oklch(63% 0.20 255 / 0.3)", flexShrink: 0 }}></div>

        {/* CTA */}
        <a
          href="https://trade.tradier.com/trader-daddy/"
          target="_blank"
          rel="noopener noreferrer"
          onMouseEnter={() => setHovered(true)}
          onMouseLeave={() => setHovered(false)}
          style={{
            display: "inline-flex",
            alignItems: "center",
            gap: 10,
            padding: "12px 28px",
            background: hovered ? "oklch(63% 0.20 255)" : "oklch(98% 0.005 240)",
            color: hovered ? "oklch(98% 0.005 240)" : "oklch(20% 0.04 255)",
            borderRadius: 999,
            fontSize: 14,
            fontWeight: 600,
            letterSpacing: "-0.01em",
            textDecoration: "none",
            whiteSpace: "nowrap",
            flexShrink: 0,
            boxShadow: hovered ? "0 8px 28px -6px oklch(63% 0.20 255 / 0.5)" : "0 4px 20px -4px oklch(0% 0 0 / 0.3)",
            transition: "all 0.2s ease",
            transform: hovered ? "translateY(-2px)" : "translateY(0)",
          }}
        >
          Open a Practice Account
          <svg width="14" height="14" viewBox="0 0 16 16" fill="none">
            <path d="M3 8H13M9 4l4 4-4 4" stroke="currentColor" strokeWidth="1.8" strokeLinecap="round" strokeLinejoin="round"/>
          </svg>
        </a>
      </div>
    </div>
  );
}

/* ============================================================
   NAV
   ============================================================ */
function Nav({ route, setRoute }) {
  const [menuOpen, setMenuOpen] = React.useState(false);
  const links = [
    ["home", "Home"],
    ["bootcamp", "Bootcamp"],
    ["indicator", "Indicator"],
    ["about", "About"],
    ["reviews", "Reviews"],
    ["contact", "Contact"],
  ];
  return (
    <>
      <header className="nav">
        <div className="container nav-inner">
        {/* Logo */}
        <a className="brand" onClick={(e) => { e.preventDefault(); setRoute("home"); setMenuOpen(false); }} href="#">
          <img src="media/logo-main.png" alt="TraderDaddy" style={{ height: 72, objectFit: "contain", display: "block" }} />
        </a>

        <nav className="nav-links">
          {links.map(([k, label]) => (
            <a
              key={k}
              href={"#" + k}
              className={"nav-link " + (route === k ? "active" : "")}
              onClick={(e) => { e.preventDefault(); setRoute(k); }}
            >
              {label}
            </a>
          ))}
        </nav>

        <div className="nav-cta">
          <a href="tel:18778280062" className="btn btn-quiet" style={{ fontSize: 13 }}>
            1-877-828-0062
          </a>
          <a href="#join" className="btn btn-primary" onClick={(e) => { e.preventDefault(); setRoute("contact"); }}>
            Get in touch
          </a>
          {/* Mobile hamburger */}
          <button className="nav-hamburger" onClick={() => setMenuOpen(!menuOpen)} aria-label="Menu">
            <span></span><span></span><span></span>
          </button>
        </div>
      </div>
      {/* Mobile menu */}
      {menuOpen && (
        <div className="nav-mobile">
          {links.map(([k, label]) => (
            <a
              key={k}
              href={"#" + k}
              className={"nav-mobile-link " + (route === k ? "active" : "")}
              onClick={(e) => { e.preventDefault(); setRoute(k); setMenuOpen(false); }}
            >
              {label}
            </a>
          ))}
        </div>
      )}
    </header>
    <TradierBar />
    </>
  );
}

/* ============================================================
   FOOTER
   ============================================================ */
function Footer({ setRoute }) {
  return (
    <footer className="footer">
      <div className="container">
        <div className="footer-grid">
          <div className="footer-brand">
            <img src="media/logo-main.png" alt="TraderDaddy" style={{ height: 72, objectFit: "contain", marginBottom: 16 }} />
            <p className="t-body" style={{ color: "var(--ink-2)", maxWidth: 360, marginTop: 0 }}>
              A private community of traders, mentors, and Wall Street professionals — across Futures, Forex, Equities, and Crypto.
            </p>
            <div style={{ marginTop: 24, display: "grid", gap: 8 }}>
              <a href="tel:18778280062" className="t-mono" style={{ color: "var(--ink-0)", fontSize: 16 }}>1-877-828-0062</a>
              <div className="t-mono" style={{ fontSize: 12, color: "var(--ink-3)", lineHeight: 1.7 }}>
                433 5th Avenue, New York, NY<br/>
                50 Chestnut Street, Morristown, NJ
              </div>
            </div>
            <div style={{ marginTop: 20 }}>
              <GoogleBadge />
            </div>
            <div className="row gap-3" style={{ marginTop: 16 }}>
              {[
                { key: "IG",  href: "https://www.instagram.com/thetraderdaddy/", Icon: SocialIcons.IG,  label: "Instagram" },
                { key: "X",   href: "https://twitter.com/academytrading", Icon: SocialIcons.X,   label: "X / Twitter" },
                { key: "YT",  href: "https://www.youtube.com/channel/UCncNUQyL4LYd8Pf6KyajH4w", Icon: SocialIcons.YT,  label: "YouTube" },
                { key: "LI",  href: "https://www.linkedin.com/company/the-foreign-exchange-trading-acadamy", Icon: SocialIcons.LI,  label: "LinkedIn" },
                { key: "WA",  href: "https://chat.whatsapp.com/JeWfLbdxAaBDv3Mizs2d6Z", Icon: SocialIcons.WA,  label: "WhatsApp" },
              ].map(({ key, href, Icon, label }) => (
                <a key={key} href={href} className="social-chip" aria-label={label} target="_blank" rel="noopener noreferrer">
                  <Icon />
                </a>
              ))}
            </div>
          </div>

          {[
            ["Community", [["Bootcamp", "bootcamp"], ["Reviews", "reviews"], ["About", "about"], ["Contact", "contact"]]],
            ["Legal", [["Privacy Policy", "privacy"]]],
          ].map(([h, items]) => (
            <div key={h} className="footer-col">
              <div className="t-mono-label" style={{ marginBottom: 16 }}>{h}</div>
              <ul>
                {items.map(([label, k]) => (
                  <li key={label}>
                    <a href={"#" + k} onClick={(e) => { e.preventDefault(); setRoute(k); window.scrollTo(0, 0); }}>{label}</a>
                  </li>
                ))}
              </ul>
            </div>
          ))}
        </div>

        <div className="footer-bottom">
          <div className="t-mono" style={{ fontSize: 12, color: "var(--ink-3)" }}>
            © 2026 TRADERDADDY LLC — All rights reserved
          </div>
          <div className="t-mono" style={{ fontSize: 11, color: "var(--ink-3)", maxWidth: 720, textAlign: "right" }}>
            Disclaimer: This company does not provide financial or investment advice. <a href="#privacy" onClick={(e) => { e.preventDefault(); setRoute("privacy"); window.scrollTo(0, 0); }} style={{ color: "var(--ink-2)", textDecoration: "underline" }}>See full disclaimer</a>. All sales are final.
          </div>
        </div>
      </div>
    </footer>
  );
}

window.GoogleBadge = GoogleBadge;
window.TradierBar = TradierBar;
window.Nav = Nav;
window.Footer = Footer;
