// ════════════════════════════════════════════════════════════════
// RECRUITER VIEW — plain-language, recruiter-friendly portfolio.
// Same facts as the developer theme, translated out of engineer-speak.
// ════════════════════════════════════════════════════════════════

function recScrollTo(id) {
  const el = document.getElementById(id);
  if (!el) return;
  const y = el.getBoundingClientRect().top + window.scrollY - 80;
  window.scrollTo({ top: y, behavior: 'smooth' });
}

// simple stroke icons (standard UI iconography)
const Ico = {
  layers: (p) => <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.8" strokeLinecap="round" strokeLinejoin="round" {...p}><path d="M12 2 2 7l10 5 10-5-10-5Z"/><path d="m2 17 10 5 10-5"/><path d="m2 12 10 5 10-5"/></svg>,
  card: (p) => <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.8" strokeLinecap="round" strokeLinejoin="round" {...p}><rect x="2" y="5" width="20" height="14" rx="2.5"/><path d="M2 10h20"/></svg>,
  rocket: (p) => <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.8" strokeLinecap="round" strokeLinejoin="round" {...p}><path d="M4.5 16.5c-1.5 1.3-2 5-2 5s3.7-.5 5-2c.7-.8.7-2 0-2.8a2 2 0 0 0-3 0Z"/><path d="M12 15 9 12a11 11 0 0 1 6-8c2.6 0 4 1.4 4 4a11 11 0 0 1-8 6Z"/><path d="M15 9a1 1 0 1 0 0-2 1 1 0 0 0 0 2Z"/></svg>,
  check: (p) => <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" {...p}><path d="M20 6 9 17l-5-5"/></svg>,
  spark: (p) => <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.8" strokeLinecap="round" strokeLinejoin="round" {...p}><path d="M12 3v4M12 17v4M3 12h4M17 12h4M5.6 5.6l2.8 2.8M15.6 15.6l2.8 2.8M18.4 5.6l-2.8 2.8M8.4 15.6l-2.8 2.8"/></svg>,
  arrow: (p) => <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" {...p}><path d="M5 12h14M13 6l6 6-6 6"/></svg>,
  ext: (p) => <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" {...p}><path d="M7 17 17 7M9 7h8v8"/></svg>,
  mail: (p) => <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.8" strokeLinecap="round" strokeLinejoin="round" {...p}><rect x="2.5" y="4.5" width="19" height="15" rx="2.5"/><path d="m3 6 9 6 9-6"/></svg>,
};

// ─── theme switch (top, always visible) ─────────────────────────────
function ThemeSwitch({ theme, setTheme, showHint }) {
  const isRec = theme === 'recruiter';
  return (
    <React.Fragment>
      <div className="theme-switch" role="tablist" aria-label="Choose a view">
        <span
          className="theme-switch__knob"
          style={{ left: isRec ? 4 : '50%', width: 'calc(50% - 4px)' }}
        />
        <button
          role="tab"
          aria-selected={isRec}
          className={`theme-switch__seg ${isRec ? 'theme-switch__seg--active' : ''}`}
          onClick={() => setTheme('recruiter')}
        >
          {Ico.spark()}
          <span>Light</span>
        </button>
        <button
          role="tab"
          aria-selected={!isRec}
          className={`theme-switch__seg ${!isRec ? 'theme-switch__seg--active' : ''}`}
          onClick={() => setTheme('developer')}
        >
          <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round"><path d="m8 8-4 4 4 4M16 8l4 4-4 4M13 5l-2 14"/></svg>
          <span>Terminal</span>
        </button>
      </div>
      {showHint && (
        <div className="theme-switch__hint">
          {isRec ? 'Switch to Terminal view ↗' : 'Switch to Light view ↗'}
        </div>
      )}
    </React.Fragment>
  );
}

// ─── top bar ────────────────────────────────────────────────────────
function RecTop() {
  const links = [
    ['work', 'My work'],
    ['experience', 'Experience'],
    ['skills', 'Strengths'],
    ['about', 'About'],
  ];
  return (
    <header className="rec-top">
      <div className="rec-top__inner">
        <a className="rec-top__brand" href="#top" onClick={(e) => { e.preventDefault(); window.scrollTo({ top: 0, behavior: 'smooth' }); }}>
          <span className="rec-top__mark">T</span>
          Thwin Zan
        </a>
        <nav className="rec-top__nav">
          {links.map(([id, label]) => (
            <a key={id} href={`#${id}`} onClick={(e) => { e.preventDefault(); recScrollTo(id); }}>{label}</a>
          ))}
          <a className="rec-top__cta" href="mailto:hi@devtzan.com">
            {Ico.mail()} Get in touch
          </a>
        </nav>
      </div>
    </header>
  );
}

// ─── hero ───────────────────────────────────────────────────────────
function RecHero() {
  return (
    <section className="rec-hero" id="top">
      <div>
        <span className="rec-hero__avail"><span className="dot" />Open to new roles · Available June 2026</span>
        <h1>I build software that<br />people <em>rely on</em> every day.</h1>
        <p className="rec-hero__sub">
          I'm Thwin Zan — a software engineer who designs, builds, and launches
          complete web products from start to finish. I've worked on payment
          systems used by millions of people, and I build and run my own
          products on the side.
        </p>
        <div className="rec-hero__ctas">
          <a className="btn-rec btn-rec--primary" href="#work" onClick={(e) => { e.preventDefault(); recScrollTo('work'); }}>
            See my work {Ico.arrow()}
          </a>
          <a className="btn-rec btn-rec--ghost" href="mailto:hi@devtzan.com">
            {Ico.mail()} Email me
          </a>
        </div>
      </div>
      <div className="rec-hero__media">
        <image-slot
          id="rec-portrait"
          class="rec-hero__portrait"
          shape="rounded"
          radius="20"
          placeholder="Drop a friendly portrait photo"
        ></image-slot>
        <div className="rec-hero__card">
          <div className="rec-hero__card-k">Currently</div>
          <div className="rec-hero__card-v">Software Engineer at Capital One</div>
        </div>
      </div>
    </section>
  );
}

// ─── trust strip ────────────────────────────────────────────────────
function RecTrust() {
  return (
    <div className="rec-trust">
      <span className="rec-trust__label">Trusted to build at</span>
      <div className="rec-trust__logos">
        <span className="rec-trust__logo">Capital One</span>
        <span className="rec-trust__logo">United Wholesale Mortgage</span>
      </div>
    </div>
  );
}

// ─── what I do ──────────────────────────────────────────────────────
function RecDo() {
  const items = [
    { n: 'i', ico: Ico.layers, h: 'Build complete products', p: 'From the first idea to the finished website, I handle the whole thing — what you see on screen, the behind-the-scenes logic, and everything in between.' },
    { n: 'ii', ico: Ico.card, h: 'Make payments work', p: 'I specialise in the tricky, important parts like taking payments online — making sure money moves safely and correctly, every single time.' },
    { n: 'iii', ico: Ico.rocket, h: 'Ship real, working software', p: "I don't just make demos. I launch products that real people and businesses use today — and I keep them running smoothly." },
  ];
  return (
    <section className="rec-block" id="services">
      <div className="rec-block__head" data-reveal>
        <span className="rec-eyebrow">What I do</span>
        <h2 className="rec-h2">In plain English, here's how I help.</h2>
      </div>
      <div className="rec-do">
        {items.map((it, i) => (
          <article className="rec-do__card" key={it.h} data-reveal style={{ transitionDelay: `${i * 80}ms` }}>
            <div className="rec-do__num">{it.n}</div>
            <div className="rec-do__ico">{it.ico()}</div>
            <h3>{it.h}</h3>
            <p>{it.p}</p>
          </article>
        ))}
      </div>
    </section>
  );
}

// ─── featured work ──────────────────────────────────────────────────
function RecFeatured() {
  const points = [
    'Every restaurant gets its own branded website',
    'Customers browse the menu and pay in a few taps',
    'Payments go directly and securely to each restaurant',
    'Designed, built, and launched entirely by me',
  ];
  return (
    <section className="rec-block" id="work">
      <div className="rec-block__head" data-reveal>
        <span className="rec-eyebrow">Featured work · Live online</span>
        <h2 className="rec-h2">An online ordering website for restaurants.</h2>
      </div>
      <div className="rec-feat" data-reveal>
        <div className="rec-feat__copy">
          <div className="rec-feat__title">Fork &amp; Merge</div>
          <p className="rec-feat__desc">
            I designed and built a complete platform that lets restaurants take
            orders and payments online. Each restaurant gets its own branded
            website, and the money goes straight to them — safely and
            automatically. It's live and in use today.
          </p>
          <ul className="rec-feat__list">
            {points.map((p) => (
              <li key={p}>{Ico.check()}<span>{p}</span></li>
            ))}
          </ul>
          <div className="rec-feat__cta">
            <a className="btn-rec btn-rec--primary" href="https://food.devtzan.com" target="_blank" rel="noreferrer">
              Visit the live website {Ico.ext()}
            </a>
          </div>
        </div>
        <div className="rec-feat__preview">
          <div className="rec-browser">
            <div className="rec-browser__bar">
              <span className="rec-browser__dot" />
              <span className="rec-browser__dot" />
              <span className="rec-browser__dot" />
              <span className="rec-browser__url">🔒 food.devtzan.com</span>
            </div>
            <div className="rec-browser__body">
              <Storefront />
            </div>
          </div>
        </div>
      </div>
    </section>
  );
}

// ─── experience ─────────────────────────────────────────────────────
function RecExperience() {
  const rows = [
    {
      when: '2024 — Now', co: 'Capital One', role: 'Software Engineer · Card & Payments',
      blurb: "I help build the systems that process credit and debit card payments for millions of customers — the technology that quietly makes every purchase work, and that people only notice when it doesn't.",
    },
    {
      when: '2023 — 2024', co: 'United Wholesale Mortgage', role: 'Software Engineer · Employee Platform',
      blurb: 'I built internal tools and a company platform used every day by thousands of employees, owning each feature from idea to finished product.',
    },
  ];
  return (
    <section className="rec-block" id="experience">
      <div className="rec-block__head" data-reveal>
        <span className="rec-eyebrow">Experience</span>
        <h2 className="rec-h2">Where I've done the work.</h2>
      </div>
      <div className="rec-exp">
        {rows.map((r) => (
          <div className="rec-exp__row" key={r.co} data-reveal>
            <div className="rec-exp__when">{r.when}</div>
            <div>
              <h3 className="rec-exp__co">{r.co}</h3>
              <div className="rec-exp__role">{r.role}</div>
              <p className="rec-exp__blurb">{r.blurb}</p>
            </div>
          </div>
        ))}
      </div>
    </section>
  );
}

// ─── strengths + tools ──────────────────────────────────────────────
function RecSkills() {
  const strengths = [
    ['Builds the whole thing', 'Comfortable across the entire product — design, the screens people see, and the engine behind them.'],
    ['Handles the high-stakes parts', "Years of experience with payments and money movement, where mistakes aren't an option."],
    ['Moves fast, finishes', 'Big-company discipline paired with the speed of someone who ships their own products.'],
    ['Makes complex feel simple', 'Turns complicated technology into something clear and easy to use.'],
  ];
  const tools = ['Web development', 'Online payments', 'Databases', 'Cloud hosting', 'Security & login', 'Email systems', 'TypeScript', 'React'];
  return (
    <section className="rec-block" id="skills">
      <div className="rec-block__head" data-reveal>
        <span className="rec-eyebrow">Strengths</span>
        <h2 className="rec-h2">What I bring to a team.</h2>
      </div>
      <div className="rec-skills">
        <div className="rec-skills__group" data-reveal>
          <div className="rec-strength">
            {strengths.map(([b, s]) => (
              <div className="rec-strength__item" key={b}>
                {Ico.check()}
                <span><b>{b}.</b> {s}</span>
              </div>
            ))}
          </div>
        </div>
        <div className="rec-skills__group" data-reveal style={{ transitionDelay: '90ms' }}>
          <h3>Areas &amp; tools I work with</h3>
          <div className="rec-tools">
            {tools.map((t) => <span className="rec-tool" key={t}>{t}</span>)}
          </div>
          <p className="rec-tools__note">Happy to go deeper on any of these — just ask.</p>
        </div>
      </div>
    </section>
  );
}

// ─── about ──────────────────────────────────────────────────────────
function RecAbout() {
  return (
    <section className="rec-block" id="about">
      <div className="rec-about">
        <blockquote className="rec-about__quote" data-reveal>
          &ldquo;I love building things that are <span className="clay">genuinely useful</span> — and making complicated technology feel simple.&rdquo;
        </blockquote>
        <div className="rec-about__body" data-reveal style={{ transitionDelay: '90ms' }}>
          <p>
            I've had the chance to work at large companies on systems used by
            millions of people, and I also build and run my own products on the
            side — from the first sketch all the way to a live, paying website.
          </p>
          <p>
            That mix gives me both the discipline of big-company engineering and
            the speed and ownership of someone used to shipping on their own. I
            care about the details that make software dependable, and about
            keeping the experience simple for the people using it.
          </p>
        </div>
      </div>
    </section>
  );
}

// ─── contact ────────────────────────────────────────────────────────
function RecContact() {
  return (
    <section className="rec-block rec-block--tight" id="contact">
      <div className="rec-contact" data-reveal>
        <span className="rec-eyebrow">Let's talk</span>
        <h2>Looking for someone who can build it<br />and ship it? Let's chat.</h2>
        <p>
          I'm currently open to new opportunities. The best way to reach me is by
          email — I'd genuinely love to hear from you.
        </p>
        <div className="rec-contact__ctas">
          <a className="btn-light btn-light--primary" href="mailto:hi@devtzan.com">{Ico.mail()} hi@devtzan.com</a>
          <a className="btn-light btn-light--ghost" href="https://linkedin.com/in/thwinzan" target="_blank" rel="noreferrer">LinkedIn {Ico.ext()}</a>
          <a className="btn-light btn-light--ghost" href="https://github.com/devtzan" target="_blank" rel="noreferrer">See my code {Ico.ext()}</a>
        </div>
      </div>
    </section>
  );
}

function RecFooter() {
  return (
    <footer className="rec-foot">
      <span>© {new Date().getFullYear()} Thwin Zan · Software Engineer</span>
      <span>
        <a href="mailto:hi@devtzan.com">Email</a> · <a href="https://linkedin.com/in/thwinzan" target="_blank" rel="noreferrer">LinkedIn</a> · <a href="https://github.com/devtzan" target="_blank" rel="noreferrer">GitHub</a>
      </span>
    </footer>
  );
}

// ─── recruiter view assembly + scroll reveal ────────────────────────
function RecruiterView() {
  React.useEffect(() => {
    const root = document.querySelector('.rec');
    if (!root) return;
    const els = [...document.querySelectorAll('.rec [data-reveal]')];
    if (!els.length) return;

    const reveal = (el) => el.classList.add('is-in');
    const inView = (el) => {
      const r = el.getBoundingClientRect();
      return r.top < window.innerHeight * 0.92 && r.bottom > 0;
    };

    // turn on the hidden start-state, then immediately reveal whatever is
    // already on screen so the first paint animates in (not stuck hidden).
    root.setAttribute('data-anim', 'on');
    requestAnimationFrame(() => els.forEach((el) => { if (inView(el)) reveal(el); }));

    let io = null;
    if ('IntersectionObserver' in window) {
      io = new IntersectionObserver((entries) => {
        entries.forEach((e) => { if (e.isIntersecting) { reveal(e.target); io.unobserve(e.target); } });
      }, { threshold: 0.12, rootMargin: '0px 0px -8% 0px' });
      els.forEach((el) => io.observe(el));
    }

    // belt-and-suspenders: a scroll listener reveals anything entering view,
    // in case the observer is unreliable in the host environment.
    const onScroll = () => {
      let remaining = false;
      els.forEach((el) => {
        if (el.classList.contains('is-in')) return;
        if (inView(el)) reveal(el); else remaining = true;
      });
      if (!remaining) window.removeEventListener('scroll', onScroll);
    };
    window.addEventListener('scroll', onScroll, { passive: true });

    // final safety net: never leave anything hidden
    const safety = setTimeout(() => els.forEach(reveal), 4500);

    return () => { if (io) io.disconnect(); window.removeEventListener('scroll', onScroll); clearTimeout(safety); };
  }, []);

  return (
    <React.Fragment>
      <RecTop />
      <main className="rec">
        <RecHero />
        <RecTrust />
        <RecDo />
        <RecFeatured />
        <RecExperience />
        <RecSkills />
        <RecAbout />
        <RecContact />
        <RecFooter />
      </main>
    </React.Fragment>
  );
}

Object.assign(window, { ThemeSwitch, RecruiterView });
