import { Search } from "lucide-react"; import { useMemo, useState } from "react"; import { Link, useNavigate } from "react-router-dom"; import { Button, ErrorNote, Field, Input, Panel, Spinner, Textarea, Waveform, useCatalog } from "../components/ui"; import { api, type Session } from "../lib/api"; import { useAuth } from "../lib/auth"; import { useI18n } from "../lib/i18n"; const LEVELS = ["intern", "junior", "mid", "senior", "lead"] as const; const TYPES = ["mixed", "technical", "behavioral", "hr", "case"] as const; export default function NewInterview() { const { t, lang } = useI18n(); const { profile } = useAuth(); const catalog = useCatalog(); const nav = useNavigate(); const [track, setTrack] = useState(profile?.target_track || "data_engineering"); const [query, setQuery] = useState(""); const [level, setLevel] = useState("junior"); const [itype, setType] = useState("mixed"); const [count, setCount] = useState(6); const [fbLang, setFbLang] = useState<"en" | "ar">(lang); const [role, setRole] = useState(""); const [cv, setCv] = useState(""); const [jd, setJd] = useState(""); const [useCv, setUseCv] = useState(!!profile?.has_cv); const [recordSelf, setRecordSelf] = useState(false); const [busy, setBusy] = useState(false); const [error, setError] = useState(null); const groups = useMemo(() => { const q = query.trim().toLowerCase(); const list = (catalog?.tracks ?? []).filter((x) => !q || x.en.toLowerCase().includes(q) || x.ar.includes(q)); return ["tech", "design", "business", "other"].map((g) => ({ g, items: list.filter((x) => x.group === g) })).filter((x) => x.items.length); }, [catalog, query]); const start = async () => { setBusy(true); setError(null); try { const s = await api.post("/sessions", { track, level, interview_type: itype, count, custom_role: role, cv_text: useCv ? "" : cv, jd_text: jd, language: fbLang, use_cv: useCv, record_video: recordSelf }); nav(`/app/interview/${s.id}`); } catch (e: any) { setError(e.message); setBusy(false); } }; if (busy) return (

{t("preparing")}

); if (!catalog) return ; const chip = (active: boolean) => `rounded-xl border px-3.5 py-2 text-sm text-start transition-colors ${active ? "border-nile bg-nile-soft font-medium text-nile-deep" : "border-line bg-surface text-ink hover:border-nile"}`; return (

{t("new_title")}

setQuery(e.target.value)} placeholder={t("search_tracks")} className="ps-9" aria-label={t("search_tracks")} />
}>
{groups.map(({ g, items }) => (

{t(`g_${g}` as "g_tech")}

{items.map((x) => ( ))}
))}
{LEVELS.map((l) => )}
setCount(+e.target.value)} className="flex-1 accent-[var(--color-nile)]" aria-label={t("count")} /> {count}
{TYPES.map((ty) => ( ))}
setRole(e.target.value)} placeholder={t("custom_role_ph")} />