"use client"; import { useState } from "react"; import { useRouter } from "next/navigation"; import { motion } from "framer-motion"; import { Code2, Bug, ScanSearch, Building2, Loader2, ArrowRight, } from "lucide-react"; import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue, } from "@/components/ui/select"; import { Button } from "@/components/ui/button"; import { apiClient, type CodingProblemType, type CodingDifficulty, type CodingLanguage, } from "@/lib/api-client"; const CODING_COLOR = "var(--color-coding)"; const PROBLEM_TYPES: { id: CodingProblemType; label: string; blurb: string; icon: React.ReactNode; }[] = [ { id: "code-creation", label: "Code Creation", blurb: "Write a function from scratch to pass a hidden test suite.", icon: , }, { id: "debugging", label: "Complex Debugging", blurb: "Find and fix the bug so all tests go green.", icon: , }, { id: "code-review", label: "Code Review (AI output)", blurb: "Review AI-generated code and identify its issues — there may be none.", icon: , }, { id: "architecture", label: "Architecture Discussion", blurb: "Reason about a system design question, graded against a rubric.", icon: , }, ]; const DIFFICULTY_LABELS: Record = { easy: "Easy", medium: "Medium", hard: "Hard", }; const LANGUAGES: { id: CodingLanguage; label: string }[] = [ { id: "javascript", label: "JavaScript" }, { id: "typescript", label: "TypeScript" }, { id: "python", label: "Python" }, { id: "go", label: "Go" }, ]; export default function CodingPage() { const router = useRouter(); const [type, setType] = useState("code-creation"); const [difficulty, setDifficulty] = useState("easy"); const [language, setLanguage] = useState("javascript"); const [loading, setLoading] = useState(false); const [error, setError] = useState(null); const isExecutable = type === "code-creation" || type === "debugging"; const langExecutes = language === "javascript" || language === "typescript"; async function handleGenerate() { setLoading(true); setError(null); try { const res = await apiClient.generateCodingProblem({ type, difficulty, language }); // Hand the generated problem to the problem page via sessionStorage. sessionStorage.setItem("coding:problem", JSON.stringify(res)); router.push("/coding/problem"); } catch (e) { setError( e instanceof Error ? e.message : "Failed to generate a problem set. Please try again.", ); setLoading(false); } } return (

Coding Training

Keep your engineering fundamentals sharp — write, debug, review, and design.

{/* Problem type */}
{PROBLEM_TYPES.map((t) => { const active = type === t.id; return ( ); })}
{/* Difficulty + language */}
{isExecutable && !langExecutes && (

Live sandbox execution supports JavaScript & TypeScript. For {LANGUAGES.find((l) => l.id === language)?.label}, you'll still get a problem but auto-grading requires an executable language.

)} {error && (

{error}

)}
); }