"use client"; import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger, } from "@/components/ui/tooltip"; import { cn } from "@/lib/utils"; import { useState } from "react"; import { judge } from "@/actions/judge"; import { Button } from "@/components/ui/button"; import { useProblem } from "@/hooks/use-problem"; import { useDockviewStore } from "@/stores/dockview"; import { LoaderCircleIcon, PlayIcon } from "lucide-react"; import { showStatusToast } from "@/hooks/show-status-toast"; interface RunCodeProps { className?: string; } export function RunCode({ className, ...props }: RunCodeProps) { const { api } = useDockviewStore(); const { currentLang, editor, problemId } = useProblem(); const [isLoading, setIsLoading] = useState(false); const handleJudge = async () => { if (!editor) return; const code = editor.getValue() || ""; setIsLoading(true); try { const result = await judge(currentLang, code, problemId); showStatusToast({ status: result.status }); const panel = api?.getPanel("Submissions"); if (panel && !panel.api.isActive) { panel.api.setActive(); } } catch (error) { console.error("Error occurred while judging the code:"); console.error(error); } finally { setIsLoading(false); } }; return ( Run Code ); }