const DS = window.SunsetEditorialDesignSystem_54097c;
const { Button, Badge, Card, Input, TextArea, Tabs, StatCell, FeatureTile, Testimonial, SunsetStripe, SiteFooter, CtaBanner, TopNav, CodeBlock } = DS;

const PROFILE = {
  name: 'Harsh Kumar',
  role: 'Software Engineer',
  roles: ['Software Engineer', 'Full-Stack Developer', 'AI/ML Engineer', 'CS Undergraduate'],
  tagline: 'Final-year Mathematics & Computing student building full-stack AI platforms — multi-agent systems, RAG pipelines, and the backend services that carry them.',
  location: 'Amethi, Uttar Pradesh, India',
  email: 'officialharsh147@gmail.com',
  wordmark: 'HARSH_',
  resumeUrl: 'assets/Harsh_Kumar_Resume.pdf',
  formEndpoint: 'https://formspree.io/f/xwleodzv',
  socials: [
    { label: 'GitHub', icon: 'Github', href: 'https://github.com/Harsh-Kumar14' },
    { label: 'LinkedIn', icon: 'Linkedin', href: 'https://www.linkedin.com/in/harshkumar147/' },
    { label: 'LeetCode', icon: 'Code2', href: 'https://leetcode.com/u/HarshKumar14/' },
    { label: 'CodeChef', icon: 'Trophy', href: 'https://www.codechef.com/users/harshkumar14' },
    { label: 'Codeforces', icon: 'Swords', href: 'https://codeforces.com/profile/hraj98097' }
  ]
};

const ROUTES = [
  { path: '/', label: 'Home' }, { path: '/about', label: 'About' }, { path: '/skills', label: 'Skills' },
  { path: '/projects', label: 'Projects' }, { path: '/experience', label: 'Experience' },
  { path: '/education', label: 'Education' }, { path: '/contact', label: 'Contact' }
];

const HIGHLIGHTS = [
  { k: 'Focus', v: 'Multi-agent AI systems' }, { k: 'Stack', v: 'MERN · Python · LangChain' },
  { k: 'Open to', v: 'SDE / SWE roles' }, { k: 'Based in', v: 'India' }
];

const STATS = [
  { value: 3, suffix: '', label: 'Major projects shipped' },
  { value: 700, suffix: '+', label: 'Problems solved' },
  { value: 5, suffix: '+', label: 'Contests organized' },
  { value: 9, suffix: '', label: 'DSA contest rank (Algo University)' }
];

const SKILL_GROUPS = [
  { name: 'Languages', icon: 'Terminal', skills: [['Python', 88], ['C++', 85], ['JavaScript', 84], ['C', 78]], chips: ['HTML', 'MATLAB', 'SQL'] },
  { name: 'Web Technologies', icon: 'Layers', skills: [['React.js', 86], ['Node.js', 84], ['Express.js', 80], ['MongoDB', 78]], chips: ['MySQL', 'Redis'] },
  { name: 'AI & Backend', icon: 'Brain', skills: [['LangChain / LangGraph', 84], ['RAG Pipelines', 82], ['REST APIs & JWT', 85], ['scikit-learn', 70]], chips: ['Gemini API', 'Qdrant', 'NumPy', 'Pandas'] },
  { name: 'Tools & OS', icon: 'Wrench', skills: [['Git & GitHub', 90], ['Docker', 78], ['Postman', 82], ['Jupyter Notebook', 80]], chips: ['LaTeX', 'AWS'] }
];

const PROJECTS = [
  {
    title: 'AI Agent Platform', category: 'Full-stack', featured: true, year: '2026',
    blurb: 'Production-grade, full-stack multi-agent AI platform on the MERN stack with a microservices backend, orchestrating autonomous agents via LangGraph and LangChain.',
    detail: 'Architected a production-grade, full-stack multi-agent AI platform on the MERN stack with a microservices backend (auth, chat, agent, and API gateway services), orchestrating autonomous agents via LangGraph and LangChain with tool-calling and streaming responses. Engineered a RAG pipeline using Qdrant vector search and Redis caching to power document upload, processing, and context-aware answers, cutting repeat-query latency significantly. Secured REST APIs with JWT auth, containerized all services via Docker Compose, and deployed the stack to AWS with a scalable, modular folder structure.',
    tech: ['MERN', 'LangGraph', 'LangChain', 'Qdrant', 'Redis', 'Docker', 'AWS', 'JWT'],
    metrics: [['Architecture', 'Microservices'], ['Deployment', 'Docker + AWS']],
    github: 'https://github.com/Harsh-Kumar14/gpt_rag_frontend', demo: 'https://gpt-rag-frontend.vercel.app/'
  },
  {
    title: 'Syntax-Sage', category: 'AI / Dev Tools', featured: true, year: '2025',
    blurb: 'AI-powered code reviewer that identifies and fixes syntax and logical errors using the Gemini API, cutting debugging time by 40%.',
    detail: 'Built Syntax-Sage, an AI-powered code reviewer that identifies and fixes syntax and logical errors using the Gemini API, reducing debugging time by 40%. Designed a scalable MERN stack application with real-time code feedback and automated corrections, tested across 200+ code snippets. Enhanced developer productivity by integrating AI-driven debugging into a seamless React–Node.js workflow.',
    tech: ['MERN', 'Gemini API', 'React', 'Node.js'],
    metrics: [['Debugging time cut', '40%'], ['Snippets tested', '200+']],
    github: 'https://github.com/Harsh-Kumar14/Syntax_sage', demo: 'https://syntax-sage-frontendd.vercel.app/'
  },
  {
    title: 'Resume-Analyzer', category: 'AI / ML', featured: true, year: '2026',
    blurb: 'AI-powered resume analyzer that scores candidate-job fit and generates ATS-optimization guidance using Gemini AI.',
    detail: 'Built an AI-powered Resume Analyzer that evaluates candidate-job fit by comparing resumes with job descriptions, delivering a quantified alignment score and detailed insights. Used Gemini AI, pdf-parse, Zod validation, and Puppeteer to extract resume content, evaluate role fit, identify skill gaps, and generate personalized interview guidance. Implemented intelligent resume-enhancement features, providing actionable suggestions to optimize resumes for ATS and improve chances of selection.',
    tech: ['Gemini AI', 'pdf-parse', 'Zod', 'Puppeteer', 'Node.js'],
    metrics: [['Output', 'Fit score + insights'], ['Extraction', 'PDF parsing']],
    github: 'https://github.com/Harsh-Kumar14/genai', demo: 'https://genai-jet-beta.vercel.app/'
  }
];

const EXPERIENCE = [
  {
    title: 'Product Intern', company: 'Pollux Engineering Private Limited', dates: 'May 2026 — Jul 2026', kind: 'Internship (Remote)',
    bullets: [
      'Drove product growth and business-development initiatives for an AI-driven e-commerce platform, running product deep-dives and target-audience research to sharpen positioning.',
      'Executed LinkedIn outreach and cold-email campaigns while maintaining project documentation and collaborating with mentors on market-research and CRM workflows.'
    ]
  },
  {
    title: 'Competitive Programming Co-head', company: 'Geek for Geek', dates: '2024 — Present', kind: 'Leadership',
    bullets: [
      'Organized 5+ coding contests with 300+ participants, boosting engagement in competitive programming initiatives.'
    ]
  }
];

const EDUCATION = [
  {
    degree: 'B.Tech. in Mathematics and Computing', school: 'Rajiv Gandhi Institute of Petroleum Technology, Jais, Amethi', year: '2023 — 2027', note: 'CGPA: 8.35 / 10',
    courses: ['Linear Algebra', 'Stochastic Processes', 'Complex Analysis', 'Number Theory', 'Numerical Methods', 'Statistical Methods', 'Computational PDE', 'Data Structures', 'Algorithms', 'OS', 'DBMS', 'Gen-AI', 'SQL', 'OOPS']
  },
  { degree: 'Senior Secondary', school: 'CBSE Board', year: '2022', note: 'Percentage: 84.5%', courses: [] },
  { degree: 'Secondary', school: 'CBSE Board', year: '2020', note: 'Percentage: 80%', courses: [] }
];

const CERTS = [
  { name: 'Amazon ML Summer School 2026', issuer: 'Selected from 100,000+ applicants', year: '2026' },
  { name: 'Rank 9 — DSA Contest', issuer: 'Algo University', year: 'Feb 2026' },
  { name: '700+ Problems Solved', issuer: 'LeetCode · CodeChef · Codeforces', year: 'Ongoing' }
];

/* ---- hooks & primitives ---- */
const reduced = () => window.matchMedia('(prefers-reduced-motion: reduce)').matches;

/* Fail-open reveal: content becomes visible if the observer is unavailable,
   never reports, or the element is already on screen at mount. */
function useInView(options) {
  const ref = React.useRef(null);
  const [seen, setSeen] = React.useState(false);
  React.useEffect(() => {
    const el = ref.current;
    if (!el) { setSeen(true); return; }
    if (reduced() || typeof IntersectionObserver === 'undefined') { setSeen(true); return; }
    let done = false;
    const show = () => { if (!done) { done = true; setSeen(true); } };
    const r = el.getBoundingClientRect();
    if (r.top < window.innerHeight && r.bottom > 0) show();
    const io = new IntersectionObserver(es => { if (es.some(e => e.isIntersecting)) { show(); io.disconnect(); } }, { threshold: 0, rootMargin: '0px 0px -8% 0px', ...options });
    io.observe(el);
    const onScroll = () => {
      const b = el.getBoundingClientRect();
      if (b.top < window.innerHeight * 0.92 && b.bottom > 0) { show(); window.removeEventListener('scroll', onScroll); }
    };
    window.addEventListener('scroll', onScroll, { passive: true });
    const t = setTimeout(() => { if (el.getBoundingClientRect().top < window.innerHeight * 1.2) show(); }, 700);
    return () => { clearTimeout(t); io.disconnect(); window.removeEventListener('scroll', onScroll); };
  }, []);
  return [ref, seen];
}

function Reveal({ delay = 0, as = 'div', children, style, ...rest }) {
  const [ref, seen] = useInView();
  const Tag = as;
  return <Tag ref={ref} className={'pf-reveal' + (seen ? ' is-in' : '')} style={{ transitionDelay: delay + 'ms', ...style }} {...rest}>{children}</Tag>;
}

function Icon({ name, size = 18, color = 'currentColor', style }) {
  const ref = React.useRef(null);
  React.useEffect(() => {
    const node = window.lucide && window.lucide[name];
    if (!ref.current || !node) return;
    ref.current.innerHTML = '';
    ref.current.appendChild(window.lucide.createElement(node));
    const svg = ref.current.firstChild;
    if (svg) { svg.setAttribute('width', size); svg.setAttribute('height', size); svg.style.display = 'block'; }
  }, [name, size]);
  return <span ref={ref} aria-hidden="true" style={{ display: 'inline-flex', color, ...style }} />;
}

function Kbd({ children }) { return <kbd className="pf-kbd">{children}</kbd>; }

function Eyebrow({ children, style }) {
  return <span style={{ font: 'var(--type-micro-uppercase)', letterSpacing: 'var(--tracking-eyebrow)', textTransform: 'uppercase', color: 'var(--steel)', whiteSpace: 'nowrap', ...style }}>{children}</span>;
}

function PageHead({ eyebrow, title, lede }) {
  return (
    <header style={{ display: 'grid', gap: 'var(--space-md)', maxWidth: '46ch', marginBottom: 'var(--space-section-sm)' }}>
      <Reveal as="div"><Eyebrow>{eyebrow}</Eyebrow></Reveal>
      <Reveal as="h1" delay={70} style={{ font: 'var(--type-heading-1)', letterSpacing: 'var(--tracking-heading-1)', color: 'var(--ink)', margin: 0, textWrap: 'pretty' }}>{title}</Reveal>
      {lede && <Reveal as="p" delay={140} style={{ font: 'var(--type-subtitle)', color: 'var(--slate)', margin: 0 }}>{lede}</Reveal>}
    </header>
  );
}

function Section({ children, style, ...rest }) {
  return <section className="pf-wrap" style={{ paddingBlock: 'var(--space-section-lg)', ...style }} {...rest}>{children}</section>;
}

function SocialRow({ size = 18, style }) {
  return (
    <div style={{ display: 'flex', gap: 'var(--space-sm)', flexWrap: 'wrap', ...style }}>
      {PROFILE.socials.map(s => (
        <a key={s.label} href={s.href} target="_blank" rel="noopener noreferrer" className="pf-lift" aria-label={s.label} style={{
          display: 'inline-flex', alignItems: 'center', gap: 'var(--space-xs)', font: 'var(--type-body-sm-medium)',
          color: 'var(--ink)', textDecoration: 'none', background: 'var(--canvas)', border: '1px solid var(--hairline)',
          borderRadius: 'var(--radius-md)', padding: '9px 14px'
        }}><Icon name={s.icon} size={size} />{s.label}</a>
      ))}
    </div>
  );
}

Object.assign(window, { DS, Button, Badge, Card, Input, TextArea, Tabs, StatCell, FeatureTile, Testimonial, SunsetStripe, SiteFooter, CtaBanner, TopNav, CodeBlock, PROFILE, ROUTES, HIGHLIGHTS, STATS, SKILL_GROUPS, PROJECTS, EXPERIENCE, EDUCATION, CERTS, useInView, Reveal, Icon, Eyebrow, Kbd, PageHead, Section, SocialRow, reduced });
