// Content rendered inside each window.

const PROJECTS = [

  {
    name: "Hand-Tracking Synthesizer",
    year: "2026",
    tags: ["python", "ML", "Max/MSP", "wekinator", "course project"],
    blurb: "Camera-based musical instrument that turns finger movement into sustained sine-wave tones",
    link: "#",
  },
  {
    name: "Dis-Chord-CS4222",
    year: "2026",
    tags: ["java", "java swing", "course project"],
    blurb: "A musical instrument built with Java Swing for CS4222 module. Dating app for chords.",
    link: "https://github.com/flayd73/Dis-Chord-CS4222-Project",
  },
  {
    name: "F1-Reaction-Timer-for-STM32-Blue-Pill",
    year: "2025",
    tags: ["Arduino", "STM32", "C++"],
    blurb: "An F1 style reaction timer using an STM32 \"Blue Pill\", 5 Red LEDs and an OLED screen made with the Arduino IDE",
    link: "https://github.com/flayd73/F1-Reaction-Timer-for-STM32-Blue-Pill-",
  },
];

function ProjectsContent() {
  return (
    <div style={{padding: "20px 24px"}}>
      <div style={{fontSize: 11, color: "var(--muted)", marginBottom: 14, textTransform: "uppercase", letterSpacing: ".1em"}}>
        ~/projects · {PROJECTS.length} items
      </div>
      <div style={{display: "grid", gap: 0}}>
        {PROJECTS.map((p, i) => (
          <a key={p.name} href={p.link}
            style={{
              display: "grid",
              gridTemplateColumns: "1fr auto",
              gap: 12,
              padding: "14px 0",
              borderTop: i === 0 ? "1px solid var(--ink)" : "none",
              borderBottom: "1px solid var(--ink)",
              textDecoration: "none",
              cursor: "pointer",
            }}
            onMouseEnter={e => e.currentTarget.style.background = "var(--paper-2)"}
            onMouseLeave={e => e.currentTarget.style.background = "transparent"}
          >
            <div>
              <div style={{display: "flex", alignItems: "baseline", gap: 10, marginBottom: 4}}>
                <span style={{fontWeight: 600, fontSize: 14}}>{p.name}</span>
                <span style={{color: "var(--muted)", fontSize: 11}}>—— {p.year}</span>
              </div>
              <div style={{color: "var(--ink-2)", fontSize: 12, marginBottom: 6}}>{p.blurb}</div>
              <div style={{display: "flex", gap: 6, flexWrap: "wrap"}}>
                {p.tags.map(t => (
                  <span key={t} style={{
                    fontSize: 10, padding: "2px 6px",
                    border: "1px solid var(--ink)",
                    background: "var(--paper)",
                    textTransform: "uppercase", letterSpacing: ".05em",
                  }}>{t}</span>
                ))}
              </div>
            </div>
            <div style={{alignSelf: "center", fontSize: 18}}>→</div>
          </a>
        ))}
      </div>
    </div>
  );
}

function ReadmeContent() {
  return (
    <div style={{padding: "20px 24px", maxWidth: 560}}>
      <pre style={{margin: 0, fontFamily: "inherit", fontSize: 13, whiteSpace: "pre-wrap", lineHeight: 1.7}}>
{`# README.md

> last updated: 05/26

## who

i'm Fahamid. i build small,
sometimes-useful things.

## stack

things I reach for first:
  - java
  - python
  - html/css/js when i'm feeling poetic

## interests

distributed systems, dev tools, generative
art, command-line ergonomics, and the exact
shade of warm grey on this page.

## currently

[x] graduating
`}
      </pre>
    </div>
  );
}

function ResumeContent() {
  const Row = ({when, what, where, what2}) => (
    <div style={{
      display: "grid",
      gridTemplateColumns: "110px 1fr",
      gap: 16,
      padding: "10px 0",
      borderTop: "1px dashed var(--ink)",
    }}>
      <div style={{color: "var(--muted)", fontSize: 11}}>{when}</div>
      <div>
        <div style={{fontWeight: 600}}>{what}</div>
        <div style={{color: "var(--ink-2)", fontSize: 12}}>{where}</div>
        {what2 && <div style={{color: "var(--ink-2)", fontSize: 12, marginTop: 2}}>{what2}</div>}
      </div>
    </div>
  );
  return (
    <div style={{padding: "20px 24px"}}>
      <div style={{
        display: "flex", justifyContent: "space-between", alignItems: "baseline",
        marginBottom: 14, paddingBottom: 10, borderBottom: "2px solid var(--ink)",
      }}>
        <div>
          <div style={{fontSize: 18, fontWeight: 700, letterSpacing: "-.01em"}}>FAHAMID HYDER</div>
          <div style={{fontSize: 11, color: "var(--muted)"}}>Student · @flayd73</div>
        </div>
        <div style={{fontSize: 10, color: "var(--muted)", textAlign: "right"}}>
          fahamidhyder@gmail.com<br/>
          github.com/flayd73
        </div>
      </div>

      <a href="resume.pdf" download="Fahamid_Hyder_Resume.pdf"
        style={{
          display: "inline-flex", alignItems: "center", gap: 8,
          padding: "8px 14px",
          marginBottom: 18,
          border: "1.5px solid var(--ink)",
          background: "var(--accent)",
          color: "var(--paper)",
          fontWeight: 600, fontSize: 12,
          textDecoration: "none",
          boxShadow: "3px 3px 0 var(--ink)",
          cursor: "pointer",
        }}
        onMouseEnter={e => { e.currentTarget.style.transform = "translate(-1px,-1px)"; e.currentTarget.style.boxShadow = "4px 4px 0 var(--ink)"; }}
        onMouseLeave={e => { e.currentTarget.style.transform = "translate(0,0)"; e.currentTarget.style.boxShadow = "3px 3px 0 var(--ink)"; }}
      >
        <span style={{fontSize: 14, lineHeight: 1}}>↓</span>
        download resume.pdf
      </a>

      <div style={{fontSize: 10, textTransform: "uppercase", letterSpacing: ".15em", color: "var(--accent)", marginBottom: 4}}>// experience</div>
      <Row when="2025 Event" what="Steward" where="Sword Security - Galway Races" what2="Carreid out ticket checking, entry and exit management, and crowd control."/>
      <Row when="2025 — 2026" what="AI Contributor (Coding & Generalist)" where="Outlier AI" what2="Evaluate and refined LLM outputs through HITL feedback to improve model accuracy, reasoning, and safety."/>
      <Row when="2022 — 2024" what="Server - T/A Packager - Cashier" where="Santori Indian Cuisine" what2="Delivered excellent customer service in a fast-paced restaurant, managing orders, serving, and addressing inquiries."/>
      <Row when="2024 — 2025" what="Project Leader & Design Engineer" where="F1 in Schools" what2="Led a team as Project Leader and Design Engineer, managing all aspects of car design, branding, and technical development for the F1 in Schools National Finals."/>

      <div style={{fontSize: 10, textTransform: "uppercase", letterSpacing: ".15em", color: "var(--accent)", marginTop: 18, marginBottom: 4}}>// education</div>
      <Row when="2025 — 2029" what="BSc in Artificial Intelligence & Machine Learning" where="University of Limerick"/>
      <Row when="2022 — 2025" what="Leaving Certificate" where="St. Jarlath's College, Tuam"/>

      <div style={{fontSize: 10, textTransform: "uppercase", letterSpacing: ".15em", color: "var(--accent)", marginTop: 18, marginBottom: 4}}>// skills</div>
      <div style={{padding: "10px 0", borderTop: "1px dashed var(--ink)", display: "flex", gap: 6, flexWrap: "wrap"}}>
        {["Customer Service Excellence","Communication","Fluent English & Italian","Teamwork & Collaboration","Responsability & Reliability","Adaptability & Composure under pressure","Positive & Proactive Attitude","Problem Solving","Attention to Detail", "Python", "Linux"].map(s => (
          <span key={s} style={{fontSize: 10, padding: "3px 8px", border: "1px solid var(--ink)", textTransform: "lowercase"}}>{s}</span>
        ))}
      </div>
    </div>
  );
}

function ContactContent() {
  const links = [
    { label: "email", value: "fahamidhyder@gmail.com", href: "mailto:fahamidhyder@gmail.com" },
    { label: "github", value: "github.com/flayd73", href: "https://github.com/flayd73" },
    { label: "linkedin", value: "linkedin.com/in/fahamid-hyder", href: "https://www.linkedin.com/in/fahamid-hyder-5772b2262/" },
  ];
  return (
    <div style={{padding: "20px 24px", maxWidth: 520}}>
      <div style={{fontSize: 11, color: "var(--muted)", marginBottom: 14, textTransform: "uppercase", letterSpacing: ".1em"}}>
        ~/contact · the inbox is open
      </div>
      <p style={{marginTop: 0, marginBottom: 18, lineHeight: 1.7}}>
        contact me about jobs, side projects, weird ideas, or just to say hi.
      </p>
      <div style={{display: "grid", gap: 0}}>
        {links.map((l, i) => (
          <a key={l.label} href={l.href} target="_blank" rel="noreferrer"
            style={{
              display: "grid", gridTemplateColumns: "90px 1fr auto", gap: 10,
              alignItems: "center",
              padding: "12px 0",
              borderTop: i === 0 ? "1px solid var(--ink)" : "none",
              borderBottom: "1px solid var(--ink)",
              textDecoration: "none", cursor: "pointer",
            }}
            onMouseEnter={e => e.currentTarget.style.color = "var(--accent)"}
            onMouseLeave={e => e.currentTarget.style.color = "var(--ink)"}
          >
            <span style={{fontSize: 10, textTransform: "uppercase", letterSpacing: ".15em", color: "var(--muted)"}}>{l.label}</span>
            <span style={{fontWeight: 500}}>{l.value}</span>
            <span>↗</span>
          </a>
        ))}
      </div>
      <div style={{marginTop: 20, padding: 12, border: "1px dashed var(--ink)", fontSize: 11, color: "var(--ink-2)", lineHeight: 1.6}}>
        <span style={{color: "var(--accent)"}}>$</span> response time: usually within a day
      </div>
    </div>
  );
}

function ExperimentsContent() {
  const [count, setCount] = React.useState(0);
  const [color, setColor] = React.useState("var(--accent)");
  const colors = ["#3f63ad", "#f0c43a", "#3a7d44", "#d94a1f", "#9333ea", "#1a1814"];
  return (
    <div style={{padding: "20px 24px"}}>
      <div style={{fontSize: 11, color: "var(--muted)", marginBottom: 14, textTransform: "uppercase", letterSpacing: ".1em"}}>
        ~/experiments · play with these
      </div>

      <div style={{padding: 14, border: "1px solid var(--ink)", marginBottom: 14, background: "var(--paper)"}}>
        <div style={{fontSize: 11, color: "var(--muted)", marginBottom: 10}}>// experiment_01.click_counter</div>
        <div style={{display: "flex", gap: 12, alignItems: "center"}}>
          <button onClick={() => setCount(c => c+1)}
            style={{
              padding: "10px 16px", border: "1px solid var(--ink)", background: color,
              color: "white", cursor: "pointer", boxShadow: "3px 3px 0 var(--ink)",
              fontWeight: 600,
            }}>
            click me
          </button>
          <span style={{fontSize: 24, fontWeight: 700}}>{count}</span>
          <span style={{fontSize: 11, color: "var(--muted)"}}>
            {count === 0 ? "still nothing" : count < 5 ? "a small commitment" : count < 15 ? "now we're cooking" : "okay you can stop"}
          </span>
        </div>
      </div>

      <div style={{padding: 14, border: "1px solid var(--ink)", marginBottom: 14}}>
        <div style={{fontSize: 11, color: "var(--muted)", marginBottom: 10}}>// experiment_02.color_swap</div>
        <div style={{display: "flex", gap: 8, flexWrap: "wrap"}}>
          {colors.map(c => (
            <button key={c} onClick={() => setColor(c)}
              style={{
                width: 32, height: 32, background: c, border: color === c ? "2px solid var(--ink)" : "1px solid var(--ink)",
                cursor: "pointer", padding: 0,
              }}/>
          ))}
        </div>
      </div>

      <div style={{padding: 14, border: "1px solid var(--ink)", marginBottom: 14}}>
        <div style={{fontSize: 11, color: "var(--muted)", marginBottom: 10}}>// experiment_03.ascii_weather</div>
        <pre style={{margin: 0, fontFamily: "VT323, monospace", fontSize: 18, lineHeight: 1, color: "var(--ink-2)"}}>
{`    \\ | /
   --(.)--    72°F · partly thinking
    / | \\    wind: light · mood: ok
   ~~~~~~`}
        </pre>
      </div>

      <div style={{fontSize: 11, color: "var(--muted)"}}>
        # more in the works. or maybe not. depends on the week.
      </div>
    </div>
  );
}

function fmtTime(s) {
  if (!isFinite(s)) return "--:--";
  const m = Math.floor(s / 60);
  const r = Math.floor(s % 60);
  return `${m}:${String(r).padStart(2, "0")}`;
}

function MusicContent() {
  const [tracks, setTracks] = React.useState(null);   // null = loading
  const [error, setError] = React.useState(null);
  const [playing, setPlaying] = React.useState(0);
  const [isPlaying, setIsPlaying] = React.useState(false);
  const [cur, setCur] = React.useState(0);
  const [dur, setDur] = React.useState(0);
  const [vol, setVol] = React.useState(0.8);
  const audioRef = React.useRef(null);
  const seekRef = React.useRef(null);

  // Load track manifest
  React.useEffect(() => {
    fetch("audio/tracks.json", { cache: "no-cache" })
      .then(r => { if (!r.ok) throw new Error("tracks.json not found"); return r.json(); })
      .then(data => setTracks(Array.isArray(data) ? data : []))
      .catch(e => { setError(e.message); setTracks([]); });
  }, []);

  // Sync play/pause
  React.useEffect(() => {
    const a = audioRef.current;
    if (!a) return;
    if (isPlaying) {
      a.play().catch(() => setIsPlaying(false));
    } else {
      a.pause();
    }
  }, [isPlaying, playing]);

  // Volume sync
  React.useEffect(() => {
    if (audioRef.current) audioRef.current.volume = vol;
  }, [vol]);

  // When track changes, reset audio
  React.useEffect(() => {
    const a = audioRef.current;
    if (!a) return;
    setCur(0);
    a.load();
    if (isPlaying) a.play().catch(() => setIsPlaying(false));
  }, [playing]);

  const onSeek = (e) => {
    const a = audioRef.current;
    const bar = seekRef.current;
    if (!a || !bar || !dur) return;
    const rect = bar.getBoundingClientRect();
    const pct = Math.min(1, Math.max(0, (e.clientX - rect.left) / rect.width));
    a.currentTime = pct * dur;
    setCur(a.currentTime);
  };

  const next = () => { if (tracks?.length) setPlaying(p => (p + 1) % tracks.length); };
  const prev = () => { if (tracks?.length) setPlaying(p => (p - 1 + tracks.length) % tracks.length); };

  // Empty / loading / error states
  if (tracks === null) {
    return (
      <div style={{padding: "40px 24px", background: "var(--ink)", color: "#888", minHeight: "100%", textAlign: "center", fontSize: 12}}>
        loading mixtapes…
      </div>
    );
  }

  if (tracks.length === 0) {
    return (
      <div style={{padding: "30px 24px", background: "var(--ink)", color: "var(--paper)", minHeight: "100%"}}>
        <div style={{fontSize: 10, color: "#888", marginBottom: 14, textTransform: "uppercase", letterSpacing: ".15em"}}>
          ░░ no mixtapes yet ░░
        </div>
        <div style={{fontSize: 13, lineHeight: 1.7, color: "#bbb", marginBottom: 18}}>
          drop mp3 files into the <span style={{color: "var(--accent-2)"}}>audio/</span> folder, then add an
          entry to <span style={{color: "var(--accent-2)"}}>audio/tracks.json</span>:
        </div>
        <pre style={{
          margin: 0, padding: 14, background: "#0a0907", border: "1px solid #333",
          color: "#bbb", fontSize: 11, lineHeight: 1.6, fontFamily: "inherit", overflow: "auto",
        }}>
{`[
  {
    "title": "Tape Side A",
    "artist": "Various",
    "file": "side-a.mp3"
  }
]`}
        </pre>
        {error && (
          <div style={{marginTop: 14, fontSize: 11, color: "#a55"}}># {error}</div>
        )}
      </div>
    );
  }

  const t = tracks[playing] || tracks[0];
  const src = `audio/${t.file}`;
  const pct = dur ? (cur / dur) * 100 : 0;

  return (
    <div style={{padding: 0, background: "var(--ink)", color: "var(--paper)", minHeight: "100%"}}>
      <audio
        ref={audioRef}
        src={src}
        preload="metadata"
        onLoadedMetadata={(e) => setDur(e.currentTarget.duration || 0)}
        onTimeUpdate={(e) => setCur(e.currentTarget.currentTime || 0)}
        onEnded={() => next()}
        onError={() => setIsPlaying(false)}
      />

      {/* Player bar */}
      <div style={{padding: "16px 20px", borderBottom: "1px solid #333"}}>
        <div style={{fontSize: 10, color: "#888", marginBottom: 8, textTransform: "uppercase", letterSpacing: ".15em"}}>
          ░░ now playing ░░
        </div>
        <div style={{fontSize: 16, fontWeight: 600, marginBottom: 2}}>
          {t.title || t.file}
        </div>
        {t.artist && (
          <div style={{fontSize: 11, color: "#888", marginBottom: 12}}>{t.artist}</div>
        )}

        {/* Seek bar */}
        <div ref={seekRef} onClick={onSeek}
          style={{
            height: 8, background: "#333", marginTop: 10, marginBottom: 6,
            position: "relative", overflow: "hidden", cursor: dur ? "pointer" : "default",
          }}>
          <div style={{
            position: "absolute", left: 0, top: 0, bottom: 0,
            width: `${pct}%`,
            background: "var(--accent-2)",
            transition: "width .15s linear",
          }}/>
        </div>
        <div style={{display: "flex", justifyContent: "space-between", fontSize: 10, color: "#888", marginBottom: 12, fontVariantNumeric: "tabular-nums"}}>
          <span>{fmtTime(cur)}</span>
          <span>{fmtTime(dur)}</span>
        </div>

        <div style={{display: "flex", gap: 8, alignItems: "center"}}>
          <button onClick={prev}
            style={{padding: "6px 10px", border: "1px solid #555", background: "transparent", color: "var(--paper)", cursor: "pointer"}}>◀◀</button>
          <button onClick={() => setIsPlaying(p => !p)}
            style={{padding: "6px 14px", border: "1px solid var(--accent-2)", background: "var(--accent-2)", color: "var(--ink)", cursor: "pointer", fontWeight: 700}}>
            {isPlaying ? "❚❚ pause" : "▶ play"}
          </button>
          <button onClick={next}
            style={{padding: "6px 10px", border: "1px solid #555", background: "transparent", color: "var(--paper)", cursor: "pointer"}}>▶▶</button>
          <div style={{marginLeft: "auto", display: "flex", alignItems: "center", gap: 6}}>
            <span style={{fontSize: 10, color: "#888"}}>vol</span>
            <input type="range" min="0" max="1" step="0.01" value={vol}
              onChange={(e) => setVol(parseFloat(e.target.value))}
              style={{width: 70, accentColor: "var(--accent-2)"}}/>
          </div>
        </div>
      </div>

      {/* Tracklist */}
      <div>
        {tracks.map((tr, i) => (
          <button key={i} onClick={() => { setPlaying(i); setIsPlaying(true); }}
            style={{
              display: "grid", gridTemplateColumns: "40px 1fr auto",
              width: "100%", padding: "10px 20px", gap: 12, alignItems: "center",
              border: "none", borderBottom: "1px solid #2a2a2a",
              background: i === playing ? "#2a2a2a" : "transparent",
              color: i === playing ? "var(--accent-2)" : "var(--paper)",
              textAlign: "left", cursor: "pointer", fontFamily: "inherit", fontSize: 13,
            }}>
            <span style={{color: "#666", fontSize: 11}}>{String(i+1).padStart(2, "0")}</span>
            <span>
              {tr.title || tr.file}
              {tr.artist && <span style={{color: "#888"}}>  ·  {tr.artist}</span>}
            </span>
            <span style={{color: "#666", fontSize: 11}}>{i === playing && dur ? fmtTime(dur) : "—"}</span>
          </button>
        ))}
      </div>
    </div>
  );
}

window.Contents = {
  projects: ProjectsContent,
  readme: ReadmeContent,
  resume: ResumeContent,
  contact: ContactContent,
  experiments: ExperimentsContent,
  music: MusicContent,
};
