import { useState, useRef, useEffect } from "react"; const API_URL = import.meta.env.VITE_API_URL || "https://happy4040-mock-technical-interviewer.hf.space"; function Markdown({ text }) { const html = (text || "") .replace(/\*\*(.+?)\*\*/g, "$1") .replace(/\*(.+?)\*/g, "$1") .replace(/`{3}[\w]*\n?([\s\S]*?)`{3}/g, "
$1
") .replace(/`([^`]+)`/g, "$1") .replace(/^### (.+)$/gm, "

$1

") .replace(/^## (.+)$/gm, "

$1

") .replace(/^# (.+)$/gm, "

$1

") .replace(/^---$/gm, "
") .replace(/^\* (.+)$/gm, "
  • $1
  • ") .replace(/\n\n/g, "

    ") .replace(/\n/g, "
    "); return

    ${html}

    ` }} />; } function Whiteboard({ onCapture }) { const canvasRef = useRef(null); const drawing = useRef(false); const lastPos = useRef(null); const [color, setColor] = useState("#f0f4ff"); const [lineWidth, setLineWidth] = useState(3); const [eraser, setEraser] = useState(false); const getPos = (e, canvas) => { const rect = canvas.getBoundingClientRect(); const scaleX = canvas.width / rect.width; const scaleY = canvas.height / rect.height; if (e.touches) return { x: (e.touches[0].clientX - rect.left) * scaleX, y: (e.touches[0].clientY - rect.top) * scaleY }; return { x: (e.clientX - rect.left) * scaleX, y: (e.clientY - rect.top) * scaleY }; }; const startDraw = (e) => { e.preventDefault(); drawing.current = true; lastPos.current = getPos(e, canvasRef.current); }; const draw = (e) => { e.preventDefault(); if (!drawing.current) return; const canvas = canvasRef.current; const ctx = canvas.getContext("2d"); const pos = getPos(e, canvas); ctx.beginPath(); ctx.moveTo(lastPos.current.x, lastPos.current.y); ctx.lineTo(pos.x, pos.y); ctx.strokeStyle = eraser ? "#0e1117" : color; ctx.lineWidth = eraser ? 20 : lineWidth; ctx.lineCap = "round"; ctx.lineJoin = "round"; ctx.stroke(); lastPos.current = pos; }; const stopDraw = () => { drawing.current = false; }; const clear = () => { const canvas = canvasRef.current; const ctx = canvas.getContext("2d"); ctx.fillStyle = "#0e1117"; ctx.fillRect(0, 0, canvas.width, canvas.height); }; useEffect(() => { clear(); }, []); const capture = () => { const b64 = canvasRef.current.toDataURL("image/png").split(",")[1]; onCapture(b64); }; return (
    Whiteboard
    {["#f0f4ff","#7ee8a2","#ffd166","#ef476f","#06d6a0","#ffffff"].map(c => (
    setLineWidth(+e.target.value)} className="size-slider" title="Brush size" />
    ); } function Message({ role, text }) { return (
    {role === "ai" ? "AI" : "You"}
    {role === "ai" ? :

    {text}

    }
    ); } function CodeEditor({ value, onChange }) { return (
    Python