import { useEffect, useState } from "react"; import { useTranslation } from "react-i18next"; import { Link, useNavigate } from "react-router-dom"; import { Plus, BookOpen, Play, Pencil, Trash2 } from "lucide-react"; import { worldsApi, sessionsApi } from "@/api"; import type { World } from "@/types"; import { Button } from "@/components/ui/Button"; import { Card, CardBody } from "@/components/ui/Card"; export function DashboardPage() { const { t } = useTranslation(); const navigate = useNavigate(); const [worlds, setWorlds] = useState([]); const [loading, setLoading] = useState(true); const [error, setError] = useState(""); const load = async () => { try { setLoading(true); const ws = await worldsApi.list(); setWorlds(ws); } catch (err: any) { setError(err.response?.data?.detail || t("errors.unknown")); } finally { setLoading(false); } }; useEffect(() => { load(); }, []); const handleDelete = async (id: string) => { if (!confirm(t("common.delete") + "?")) return; try { await worldsApi.delete(id); await load(); } catch (err: any) { setError(err.response?.data?.detail || t("errors.unknown")); } }; const handlePlay = async (world: World) => { try { const session = await sessionsApi.create(world.id); navigate(`/sessions/${session.id}`); } catch (err: any) { setError(err.response?.data?.detail || t("errors.unknown")); } }; return (

{t("worlds.title")}

{error &&

{error}

} {loading ? (

{t("common.loading")}

) : worlds.length === 0 ? (

{t("worlds.empty")}

) : (
{worlds.map((w) => (

{w.name}

{w.language.toUpperCase()} {w.current_time && ( · {w.current_time} )}

{w.definition?.setting_description?.slice(0, 160) || "—"}

{w.status === "draft" ? ( ) : ( )}
))}
)}
); } function StatusBadge({ status, t }: { status: string; t: any }) { const colors: Record = { draft: "bg-yellow-500/10 text-yellow-400 border-yellow-500/30", ready: "bg-blue-500/10 text-blue-400 border-blue-500/30", active: "bg-green-500/10 text-green-400 border-green-500/30", archived: "bg-ink-500/10 text-ink-400 border-ink-500/30", }; const labels: Record = { draft: t("worlds.status_draft"), ready: t("worlds.status_ready"), active: t("worlds.status_active"), archived: t("worlds.status_archived"), }; return ( {labels[status] || status} ); }