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

// ───────── Icons ─────────
const Icon = {
  GitHub: (p) => (
    <svg viewBox="0 0 24 24" width="16" height="16" fill="currentColor" {...p}>
      <path d="M12 .5C5.65.5.5 5.65.5 12c0 5.08 3.29 9.39 7.86 10.91.58.1.79-.25.79-.56 0-.28-.01-1.02-.02-2-3.2.7-3.87-1.54-3.87-1.54-.52-1.33-1.28-1.69-1.28-1.69-1.05-.71.08-.7.08-.7 1.16.08 1.77 1.19 1.77 1.19 1.03 1.76 2.7 1.25 3.36.96.1-.75.4-1.25.73-1.54-2.55-.29-5.24-1.28-5.24-5.69 0-1.26.45-2.29 1.18-3.1-.12-.29-.51-1.46.11-3.04 0 0 .97-.31 3.18 1.18a11.04 11.04 0 0 1 5.79 0c2.21-1.49 3.18-1.18 3.18-1.18.62 1.58.23 2.75.11 3.04.74.81 1.18 1.84 1.18 3.1 0 4.42-2.69 5.4-5.25 5.68.41.36.78 1.06.78 2.14 0 1.55-.01 2.8-.01 3.18 0 .31.21.67.8.56C20.21 21.39 23.5 17.08 23.5 12 23.5 5.65 18.35.5 12 .5Z"/>
    </svg>
  ),
  LinkedIn: (p) => (
    <svg viewBox="0 0 24 24" width="16" height="16" fill="currentColor" {...p}>
      <path d="M20.45 20.45h-3.55v-5.57c0-1.33-.03-3.04-1.85-3.04-1.86 0-2.14 1.45-2.14 2.94v5.67H9.36V9h3.41v1.56h.05c.48-.9 1.64-1.85 3.37-1.85 3.6 0 4.27 2.37 4.27 5.46v6.28ZM5.34 7.43a2.06 2.06 0 1 1 0-4.12 2.06 2.06 0 0 1 0 4.12ZM7.12 20.45H3.56V9h3.56v11.45ZM22.22 0H1.77C.79 0 0 .77 0 1.72v20.56C0 23.23.79 24 1.77 24h20.45C23.21 24 24 23.23 24 22.28V1.72C24 .77 23.21 0 22.22 0Z"/>
    </svg>
  ),
  Arrow: (p) => (
    <svg viewBox="0 0 24 24" width="14" height="14" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" {...p}>
      <path d="M7 17 17 7M9 7h8v8"/>
    </svg>
  ),
  Terminal: (p) => (
    <svg viewBox="0 0 24 24" width="22" height="22" fill="none" stroke="currentColor" strokeWidth="1.8" strokeLinecap="round" strokeLinejoin="round" {...p}>
      <rect x="3" y="4" width="18" height="16" rx="2"/>
      <path d="m7 9 3 3-3 3M13 15h4"/>
    </svg>
  ),
  Disc: (p) => (
    <svg viewBox="0 0 24 24" width="22" height="22" fill="none" stroke="currentColor" strokeWidth="1.8" {...p}>
      <circle cx="12" cy="12" r="9"/>
      <circle cx="12" cy="12" r="3"/>
    </svg>
  ),
  Play: (p) => (
    <svg viewBox="0 0 24 24" width="22" height="22" fill="currentColor" {...p}>
      <path d="M5 3.5v17a1 1 0 0 0 1.55.83l13-8.5a1 1 0 0 0 0-1.66l-13-8.5A1 1 0 0 0 5 3.5Z"/>
    </svg>
  ),
};

// ───────── Reveal-on-scroll observer ─────────
function useReveal() {
  useEffect(() => {
    const els = document.querySelectorAll('.reveal');
    const io = new IntersectionObserver((entries) => {
      entries.forEach((e) => {
        if (e.isIntersecting) {
          e.target.classList.add('in');
          io.unobserve(e.target);
        }
      });
    }, { threshold: 0.12 });
    els.forEach((el) => io.observe(el));
    return () => io.disconnect();
  }, []);
}

// ───────── Parallax disabled ─────────
function useParallax() {}

// ───────── Card hover spotlight ─────────
function ProjCard({ icon, title, sub, desc, status, statusKind, tags, href }) {
  const ref = useRef(null);
  const onMove = (e) => {
    const r = ref.current.getBoundingClientRect();
    ref.current.style.setProperty('--mx', `${e.clientX - r.left}px`);
    ref.current.style.setProperty('--my', `${e.clientY - r.top}px`);
  };
  return (
    <a ref={ref} href={href || '#'} target={href ? "_blank" : undefined} rel="noreferrer"
       className="proj-card reveal" onMouseMove={onMove}>
      <div className="proj-head">
        <div className="proj-icon">{icon}</div>
        <span className={`proj-status status-${statusKind}`}>{status}</span>
      </div>
      <div className="proj-title">{title}</div>
      <div className="proj-sub">{sub}</div>
      <p className="proj-desc">{desc}</p>
      <div className="proj-foot">
        <div className="proj-tags">{tags.map((t) => <span key={t}>{t}</span>).reduce((p, c, i) => i ? [...p, <span key={`s${i}`} style={{opacity:0.3}}>·</span>, c] : [c], [])}</div>
        <span className="proj-link">
          {href ? "View on GitHub" : "Coming soon"} <Icon.Arrow/>
        </span>
      </div>
    </a>
  );
}

// ───────── Typed tagline ─────────
function TypedTagline() {
  const phrases = [
    "Building tools for developers.",
    "Shipping useful software.",
    "Making things that work."
  ];
  const [i, setI] = useState(0);
  const [txt, setTxt] = useState("");
  const [del, setDel] = useState(false);

  useEffect(() => {
    const cur = phrases[i];
    let t;
    if (!del && txt.length < cur.length) {
      t = setTimeout(() => setTxt(cur.slice(0, txt.length + 1)), 38);
    } else if (!del && txt.length === cur.length) {
      t = setTimeout(() => setDel(true), 2400);
    } else if (del && txt.length > 0) {
      t = setTimeout(() => setTxt(cur.slice(0, txt.length - 1)), 18);
    } else {
      t = setTimeout(() => { setDel(false); setI((i + 1) % phrases.length); }, 220);
    }
    return () => clearTimeout(t);
  }, [txt, del, i]);

  return (
    <span className="accent" style={{minHeight:'1em', display:'inline-block'}}>
      {txt}<span className="cursor"></span>
    </span>
  );
}

// ───────── Main App ─────────
function App() {
  useReveal();
  useParallax();

  return (
    <>
      {/* Nav */}
      <nav className="nav">
        <div className="shell nav-inner">
          <a href="#top" aria-label="Cir0cuit home">
            <img src="assets/cir0cuit-light.svg" alt="Cir0cuit" className="logo"/>
          </a>
          <div className="nav-links">
            <a href="#devtoys">DevToys</a>
            <a href="#projects">Projects</a>
            <a href="blog.html">Blog</a>
          </div>
          <a className="gh-btn" href="https://github.com/Cir0cuit" target="_blank" rel="noreferrer">
            <Icon.GitHub/> GitHub
          </a>
        </div>
      </nav>

      <main id="top">
        {/* HERO */}
        <section className="hero shell">
          <div className="hero-logo-wrap reveal reveal-1">
            <img src="assets/cir0cuit-light.svg" alt="Cir0cuit" className="hero-logo"/>
          </div>

          <div className="hero-actions reveal reveal-3">
            <a className="btn btn-primary" href="#devtoys">
              See what's shipping <Icon.Arrow/>
            </a>
            <a className="btn btn-ghost" href="https://github.com/Cir0cuit" target="_blank" rel="noreferrer">
              <Icon.GitHub/> @Cir0cuit
            </a>
          </div>


        </section>

        {/* COMING SOON */}
        <section className="section shell" id="devtoys">
          <div className="reveal">
            <div className="section-eyebrow">// 01 — Coming soon</div>
          </div>
          <div className="devtoys reveal">
            <div style={{position:'relative', zIndex:1}}>
              <span className="devtoys-tag">
                <span className="dot"></span> Releasing soon · Google Play
              </span>
              <h3>
                <span className="accent">DevToys</span> — the developer<br/>
                Swiss-army knife.
              </h3>
              <p>
                A single Android app aggregating 33+ everyday utilities — formatters,
                converters, generators, encoders. Offline-first, no ads, no telemetry.
                The toolbox that should already be on your phone.
              </p>
              <div className="devtoys-meta">
              </div>
              <a className="gp-badge" href="#" onClick={(e) => e.preventDefault()}>
                <img src="assets/google-play.svg" width="28" height="28" alt="Google Play"/>
                <span className="gp-text">
                  <span className="gp-small">Coming soon on</span>
                  <span className="gp-big">Google Play</span>
                </span>
              </a>
            </div>

            <div className="devtoys-visual">
              <div className="devtoys-orbit"></div>
              <div className="devtoys-orbit-2"></div>
              <div className="devtoys-icon-frame">
                <img src="assets/devtoys.png" alt="DevToys app icon"/>
              </div>
            </div>
          </div>
        </section>

        {/* PROJECTS */}
        <section className="section shell" id="projects">
          <div className="reveal">
            <div className="section-eyebrow">// 02 — Selected work</div>
          </div>

          <div className="projects-grid">
            <ProjCard
              icon={<img src="assets/devtoys.png" alt=""/>}
              title="DevToys"
              sub="Android · Kotlin · Releasing Q2 2026"
              desc="33+ developer utilities in one offline app — formatters, converters, generators, encoders. Built for quick reach when you don't want to open six websites."
              status="Coming soon"
              statusKind="soon"
              tags={["Android", "Kotlin", "Offline-first"]}
            />
            <ProjCard
              icon={<Icon.Disc/>}
              title="VEIM"
              sub="Ventoy Easy ISO Manager · Python"
              desc="Automates checking, downloading and organizing Linux ISOs on a Ventoy USB drive. Supports 20+ distros with resume-capable downloads, a fast-scan update checker, and a clean dark-mode UI."
              status="Live"
              statusKind="live"
              tags={["Python", "GUI", "Ventoy"]}
              href="https://github.com/Cir0cuit/VEIM"
            />
            <ProjCard
              icon={<Icon.Terminal/>}
              title="Shift Reporting Tool"
              sub="JavaScript · Internal tooling"
              desc="A focused report-generation tool for shift handoffs — structured input, consistent output. The kind of thing you build once and use every day."
              status="Live"
              statusKind="live"
              tags={["JavaScript", "Reporting"]}
              href="https://github.com/Cir0cuit/Shift-Reporting-Tool"
            />
            <ProjCard
              icon={<Icon.Play/>}
              title="PS Script Collection"
              sub="PowerShell · Operations"
              desc="A growing collection of PowerShell scripts I keep reaching for — automation, audits, day-to-day Windows admin. Steal what's useful."
              status="Live"
              statusKind="live"
              tags={["PowerShell", "Automation"]}
              href="https://github.com/Cir0cuit/PS-Script-Collection"
            />
          </div>
        </section>


      </main>
    </>
  );
}

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