/* Shared site chrome — nav, footer, buttons, cards */

const { useState, useEffect, useRef, useMemo } = React;

// ─────────────────────────────────────────────────────────────────────
// Hummingbird mark
function Hummingbird({ size = 36, className = "", style = {} }) {
  return (
    <svg width={size} height={size} viewBox="0 0 64 64" fill="none"
      stroke="currentColor" strokeWidth="1.4" strokeLinejoin="round" strokeLinecap="round"
      className={className} style={style}>
      <path d="M8 16 L20 8 L28 18 L18 26 Z" />
      <path d="M18 26 L28 18 L40 22 L34 32 Z" />
      <path d="M34 32 L40 22 L54 28 L46 38 Z" />
      <path d="M46 38 L54 28 L58 40 L50 46 Z" />
      <path d="M18 26 L34 32 L46 38 L50 46 L40 52 L26 44 L20 36 Z" />
      <path d="M20 36 L26 44 L18 50" />
      <path d="M26 44 L40 52 L36 58" />
      <circle cx="12" cy="13" r="1.6" fill="currentColor" stroke="none" />
    </svg>
  );
}

// ─────────────────────────────────────────────────────────────────────
// Top nav
function NavBar({ active = "home", basePath = "" }) {
  const [open, setOpen] = useState(false);
  const links = [
    ["Home", "index.html", "home"],
    ["About", "about.html", "about"],
    ["Services", "services.html", "services"],
    ["Portfolio", "portfolio.html", "portfolio"],
    ["Blog", "blog.html", "blog"],
    ["CV", "cv.html", "cv"],
    ["Connect", "connect.html", "connect"],
  ];
  return (
    <header className={"rr-nav" + (open ? " is-open" : "")}>
      <a className="rr-nav-brand" href={basePath + "index.html"}>
        <img src="assets/ricardo-logo.png" alt="ricardo ruiz" className="rr-nav-logo" />
      </a>
      <nav className="rr-nav-links">
        {links.map(([label, href, key]) => (
          <a key={key} href={basePath + href}
            className={"rr-nav-link" + (active === key ? " is-active" : "")}
            onClick={() => {
              const m = typeof window !== "undefined" && window.__mako;
              if (m) {
                m.addBreadcrumb({
                  category: "navigation",
                  message: `open ${label}`,
                  level: "info",
                  data: { href: basePath + href, active: key },
                });
              }
            }}>
            {label}
          </a>
        ))}
      </nav>
      <a className="rr-nav-cta" href={basePath + "connect.html"}>
        <span className="rr-dot" /> available
      </a>
      <button type="button" className="rr-nav-toggle"
        aria-label={open ? "Close menu" : "Open menu"}
        aria-expanded={open}
        onClick={() => setOpen(o => !o)}>
        <span /><span /><span />
      </button>
    </header>
  );
}

// ─────────────────────────────────────────────────────────────────────
// Footer (matches the purple slab from screenshots, but evolved)
function Footer({ basePath = "" }) {
  return (
    <footer className="rr-footer">
      <div className="rr-footer-body">
        <div className="rr-footer-grid">
          <div className="rr-footer-id">
            <div className="rr-footer-avatar">
              <img src="assets/avatar-photo.jpg" alt="Ricardo Ruiz" />
            </div>
            <div>
              <div className="rr-footer-name">Ricardo Ruiz</div>
              <div className="rr-footer-tag">
                Your friendly neighborhood Agentic Engineer,<br/>
                specializing in agentic & mobile development.
              </div>
              <div className="rr-footer-social">
                <a href="https://github.com/ruizrica" aria-label="GitHub">
                  <svg width="18" height="18" viewBox="0 0 24 24" fill="currentColor"><path d="M12 .3a12 12 0 00-3.8 23.4c.6.1.8-.3.8-.6v-2.2c-3.3.7-4-1.4-4-1.4-.5-1.4-1.3-1.7-1.3-1.7-1-.7.1-.7.1-.7 1.2.1 1.8 1.2 1.8 1.2 1.1 1.8 2.8 1.3 3.5 1 .1-.8.4-1.3.8-1.6-2.7-.3-5.5-1.3-5.5-5.9 0-1.3.5-2.4 1.2-3.2-.1-.3-.5-1.5.1-3.2 0 0 1-.3 3.3 1.2a11.5 11.5 0 016 0c2.3-1.5 3.3-1.2 3.3-1.2.6 1.7.2 2.9.1 3.2.8.8 1.2 1.9 1.2 3.2 0 4.6-2.8 5.6-5.5 5.9.4.4.8 1.1.8 2.2v3.3c0 .3.2.7.8.6A12 12 0 0012 .3" /></svg>
                </a>
                <a href="https://www.linkedin.com/in/ricardo-ruiz-31301537/" aria-label="LinkedIn">
                  <svg width="18" height="18" viewBox="0 0 24 24" fill="currentColor"><path d="M20.5 2h-17A1.5 1.5 0 002 3.5v17A1.5 1.5 0 003.5 22h17a1.5 1.5 0 001.5-1.5v-17A1.5 1.5 0 0020.5 2zM8 19H5v-9h3v9zM6.5 8.7a1.7 1.7 0 110-3.5 1.7 1.7 0 010 3.5zM19 19h-3v-4.7c0-1.1 0-2.5-1.5-2.5s-1.7 1.2-1.7 2.4V19h-3v-9h2.9v1.2h0c.4-.8 1.4-1.5 2.8-1.5 3 0 3.6 2 3.6 4.5V19z" /></svg>
                </a>
              </div>
            </div>
          </div>
          <div className="rr-footer-cta-col">
            <a className="rr-footer-cta" href={basePath + "connect.html"}>LETS CONNECT &nbsp; →</a>
            <div className="rr-footer-loc">
              <div>
                <div className="rr-footer-loc-label">BASED OUT OF:</div>
                <div className="rr-footer-loc-place">ORANGE COUNTY, CALIFORNIA</div>
              </div>
            </div>
          </div>
        </div>
        <div className="rr-footer-bottom">
          <div className="rr-mono rr-text-dim">© 2026 Ricardo Ruiz. All rights reserved.</div>
          <div className="rr-mono rr-text-dim">v3.0.0 — built with claude · deployed on cloudflare</div>
        </div>
      </div>
    </footer>
  );
}

// ─────────────────────────────────────────────────────────────────────
// Buttons
function Button({ children, variant = "primary", as = "button", href, onClick, icon, ...rest }) {
  const cls = "rr-btn rr-btn-" + variant;
  if (as === "a" || href) {
    return <a className={cls} href={href} onClick={onClick} {...rest}>{children}{icon}</a>;
  }
  return <button className={cls} onClick={onClick} {...rest}>{children}{icon}</button>;
}

// ─────────────────────────────────────────────────────────────────────
// Section header (for marketing pages)
function SectionHeader({ kicker, title, sub }) {
  return (
    <div className="rr-section-header">
      {kicker && <div className="rr-kicker">// {kicker}</div>}
      <h2 className="rr-section-title">{title}</h2>
      {sub && <p className="rr-section-sub">{sub}</p>}
    </div>
  );
}

// ─────────────────────────────────────────────────────────────────────
// Tag chip
function Tag({ children, accent }) {
  return <span className={"rr-tag" + (accent ? " is-accent" : "")}>{children}</span>;
}

// Export
Object.assign(window, {
  Hummingbird, NavBar, Footer, Button, SectionHeader, Tag
});
