const { useState, useEffect } = React;

const PROJECTS = [
  {
    id: "jarvis",
    title: "⚡ JARVIS — AI Voice & Desktop OS",
    category: "Full-Stack",
    desc: "Futuristic desktop voice operating assistant for macOS featuring hands-free speech recognition, Gemini AI reasoning, and live hardware telemetry.",
    problem: "Desktop multitasking requires constant manual window and app switching. Hooking AI directly to native OS actions creates serious risks of accidental destructive operations.",
    solution: "Engineered a voice loop with Gemini AI, real-time WebSocket telemetry (CPU/RAM), and an explicit Security Confirmation Gateway intercepting destructive system actions.",
    tags: ["TypeScript", "React 18", "Node.js", "Express", "WebSockets", "Gemini AI", "Tailwind CSS"],
    repo: "https://github.com/Anirbank33/jarvis-ai-assistant",
    demo: null
  },
  {
    id: "wardline",
    title: "🏥 Wardline — Clinical Ward Queue & Census Tracker",
    category: "Full-Stack",
    desc: "Calm, high-density hospital floor operations command center for charge nurses to monitor live bed occupancy and patient admission flow.",
    problem: "Hospital staff struggle with bloated, sluggish legacy EHR interfaces during shift handovers, creating bottlenecks in triage queues and bed turnover.",
    solution: "Built a pnpm monorepo with contract-first OpenAPI 3.0 codegen driving auto-generated typed React Query hooks and runtime Zod validation schemas.",
    tags: ["TypeScript", "React 18", "Vite", "Express", "Zod", "OpenAPI 3.0", "pnpm"],
    repo: "https://github.com/Anirbank33/medical-department-tracker",
    demo: null
  },
  {
    id: "rest-engine",
    title: "🚀 Document REST API & Microservice Engine",
    category: "Backend",
    desc: "Production-shaped RESTful API service implementing clean layered architecture, atomic file locks, and automated integration test coverage.",
    problem: "REST microservices frequently suffer from inconsistent HTTP status code semantics, missing payload validation, and race conditions during concurrent file writes.",
    solution: "Architected a 5-layer service (routes → controllers → services → store → middleware) with serialized file locks, per-IP rate limiting, and 16 passing automated tests.",
    tags: ["Node.js", "Express.js", "JavaScript", "Supertest", "node:test", "Clean Architecture"],
    repo: "https://github.com/Anirbank33/backend-demo",
    demo: null
  },
  {
    id: "telemetry",
    title: "📊 GitHub Activity Telemetry Dashboard",
    category: "Frontend",
    desc: "Zero-dependency multi-year engineering velocity dashboard visualizing 5-year commit trends and heatmaps via GitHub GraphQL API.",
    problem: "GitHub's native contribution heatmap is locked to a single rolling year and lacks multi-year comparative analytics and auto-theming for embedding.",
    solution: "Crafted a lightweight client using HTML5 Canvas and CSS variables to render 5-year contribution velocity graphs with dynamic OS dark/light theme switching.",
    tags: ["JavaScript", "HTML5 Canvas", "CSS Custom Properties", "GitHub GraphQL API"],
    repo: "https://github.com/Anirbank33/github-activity-2021-2026",
    demo: "https://anirbank33.github.io/github-activity-2021-2026/"
  },
  {
    id: "audio-studio",
    title: "🎵 90s Web Audio Studio & Player",
    category: "Frontend",
    desc: "Interactive retro web audio streaming player featuring dynamic waveform canvas rendering and responsive playback queuing.",
    problem: "Web music applications often lack responsive visual waveform feedback and low-latency client-side audio controls without heavy external libraries.",
    solution: "Leveraged native Web Audio API to decode and visualize audio frequencies in real-time with custom playlist state and glassmorphic UI.",
    tags: ["JavaScript", "Web Audio API", "HTML5", "CSS3 Glassmorphism"],
    repo: "https://github.com/Anirbank33/Cool-tracks-form-90-s",
    demo: null
  }
];

const SKILLS = [
  { name: "TypeScript", type: "Languages" },
  { name: "JavaScript (ES6+)", type: "Languages" },
  { name: "HTML5 & Modern CSS", type: "Languages" },
  { name: "React 18", type: "Frontend" },
  { name: "Vite", type: "Frontend" },
  { name: "Tailwind CSS", type: "Frontend" },
  { name: "DOM Manipulation", type: "Frontend" },
  { name: "Node.js", type: "Backend" },
  { name: "Express.js", type: "Backend" },
  { name: "RESTful API Design", type: "Backend" },
  { name: "WebSockets", type: "Backend" },
  { name: "OpenAPI 3.0 & Zod", type: "Backend" },
  { name: "Layered Architecture", type: "Backend" },
  { name: "Supertest & node:test", type: "Testing" },
  { name: "Git & GitHub Pages", type: "Tools" },
  { name: "pnpm / npm Workspaces", type: "Tools" }
];

function App() {
  const [filter, setFilter] = useState("All");
  const [skillFilter, setSkillFilter] = useState("All");
  const [copied, setCopied] = useState(false);

  const filteredProjects = filter === "All" 
    ? PROJECTS 
    : PROJECTS.filter(p => p.category === filter);

  const filteredSkills = skillFilter === "All"
    ? SKILLS
    : SKILLS.filter(s => s.type === skillFilter);

  const copyEmail = () => {
    navigator.clipboard.writeText("anirbankar23@gmail.com");
    setCopied(true);
    setTimeout(() => setCopied(false), 2200);
  };

  return (
    <div className="container">
      {/* Navigation Header */}
      <header className="nav-header">
        <a href="#" className="nav-brand">
          anirban<span>.dev()</span>
        </a>
        <div className="status-pill">
          <span className="status-dot"></span>
          <span>Open to Remote Roles</span>
        </div>
      </header>

      {/* Hero Section */}
      <section className="sketch-box hero-section">
        <div className="avatar-frame">
          <picture>
            <source srcSet="assets/images/anirban-pixar-animated.webp" type="image/webp" />
            <img 
              src="assets/images/anirban-pixar-avatar.jpg" 
              alt="Anirban Kar — 3D Animated Avatar" 
              className="avatar-img"
              loading="eager"
            />
          </picture>
        </div>

        <div className="hero-content">
          <h1>Anirban Kar</h1>
          <div className="hero-subtitle">
            Software Engineer — Full-Stack &amp; Frontend (JavaScript &amp; TypeScript)
          </div>
          <p className="hero-bio">
            Passionate about building clean, performant web applications and type-safe REST APIs. 
            Focused on contract-first architecture (OpenAPI/Zod), modern React components, and 
            bulletproof layered Node.js backends. Ready for high-velocity remote engineering teams.
          </p>
          <div className="hero-actions">
            <a href="#projects" className="btn-sketch btn-primary">
              ⚡ Explore Projects
            </a>
            <a href="https://github.com/Anirbank33" target="_blank" rel="noreferrer" className="btn-sketch">
              📦 GitHub (20+ Repos)
            </a>
            <a href="https://www.linkedin.com/in/anirban-kar-23645414a/" target="_blank" rel="noreferrer" className="btn-sketch">
              💼 LinkedIn
            </a>
            <button onClick={copyEmail} className="btn-sketch">
              {copied ? "✓ Copied Email!" : "📬 Copy Email"}
            </button>
          </div>
        </div>
      </section>

      {/* Technical Skills Section */}
      <section id="skills">
        <div className="section-title">
          <span>// 01.</span> Technical Competencies
        </div>

        <div className="filter-tabs">
          {["All", "Languages", "Frontend", "Backend", "Testing", "Tools"].map(t => (
            <button 
              key={t}
              onClick={() => setSkillFilter(t)} 
              className={`tab-btn ${skillFilter === t ? "active" : ""}`}
            >
              {t}
            </button>
          ))}
        </div>

        <div className="sketch-box">
          <div className="skills-grid">
            {filteredSkills.map(s => (
              <span key={s.name} className="skill-tag">
                <span style={{ color: "#38bdf8" }}>▪</span> {s.name}
              </span>
            ))}
          </div>
        </div>
      </section>

      {/* Featured Projects Section */}
      <section id="projects">
        <div className="section-title">
          <span>// 02.</span> Featured Engineering Projects
        </div>

        <div className="filter-tabs">
          {["All", "Full-Stack", "Backend", "Frontend"].map(c => (
            <button 
              key={c}
              onClick={() => setFilter(c)} 
              className={`tab-btn ${filter === c ? "active" : ""}`}
            >
              {c} ({c === "All" ? PROJECTS.length : PROJECTS.filter(p => p.category === c).length})
            </button>
          ))}
        </div>

        <div className="projects-list">
          {filteredProjects.map(project => (
            <div key={project.id} className="project-card">
              <div className="project-header">
                <div className="project-title">{project.title}</div>
                <div className="project-links">
                  {project.demo && (
                    <a href={project.demo} target="_blank" rel="noreferrer">
                      ⚡ Live Demo ↗
                    </a>
                  )}
                  <a href={project.repo} target="_blank" rel="noreferrer">
                    📦 Source Code ↗
                  </a>
                </div>
              </div>

              <p className="project-desc">{project.desc}</p>

              <div className="project-problem-solution">
                <div className="problem-text">
                  <strong>Challenge Faced:</strong> {project.problem}
                </div>
                <div className="solution-text">
                  <strong>Technical Solution:</strong> {project.solution}
                </div>
              </div>

              <div className="project-tags">
                {project.tags.map(tag => (
                  <span key={tag} className="tag-mini">
                    {tag}
                  </span>
                ))}
              </div>
            </div>
          ))}
        </div>
      </section>

      {/* Contact Section */}
      <section id="contact">
        <div className="section-title">
          <span>// 03.</span> Connect &amp; Hire
        </div>

        <div className="sketch-box">
          <div className="contact-grid">
            <div className="contact-row">
              <span><strong>Email:</strong> anirbankar23@gmail.com</span>
              <button onClick={copyEmail} className="copy-btn">
                {copied ? "✓ Copied" : "Copy to Clipboard"}
              </button>
            </div>
            <div className="contact-row">
              <span><strong>LinkedIn Profile:</strong> Professional network &amp; recommendations</span>
              <a 
                href="https://www.linkedin.com/in/anirban-kar-23645414a/" 
                target="_blank" 
                rel="noreferrer" 
                className="contact-link"
              >
                Connect on LinkedIn ↗
              </a>
            </div>
            <div className="contact-row">
              <span><strong>GitHub Repositories:</strong> Code reviews, commit activity &amp; PRs</span>
              <a 
                href="https://github.com/Anirbank33" 
                target="_blank" 
                rel="noreferrer" 
                className="contact-link"
              >
                github.com/Anirbank33 ↗
              </a>
            </div>
          </div>
        </div>
      </section>

      {/* Footer */}
      <footer className="footer">
        Handcrafted with React 18, HTML5 &amp; Sketchy Dark CSS • Built for Remote Engineering Teams • 2026
      </footer>
    </div>
  );
}

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