"use client"; import { Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle, } from "@/components/ui/dialog"; import { useState } from "react"; import { useTranslations } from "next-intl"; import { Label } from "@/components/ui/label"; import { Button } from "@/components/ui/button"; import { analyzeComplexity } from "@/app/actions/analyze"; import { AnalyzeComplexityResponse } from "@/types/complexity"; import { LoaderCircleIcon, WandSparklesIcon } from "lucide-react"; interface AnalyzeButtonProps { value: string; } export const AnalyzeButton = ({ value }: AnalyzeButtonProps) => { const t = useTranslations("WorkspaceEditorHeader.AnalyzeButton"); const [open, setOpen] = useState(false); const [complexity, setComplexity] = useState(null); const [error, setError] = useState(null); const [isLoading, setIsLoading] = useState(false); const handleClick = async () => { setError(null); setIsLoading(true); try { const complexity = await analyzeComplexity(value); setComplexity(complexity); setOpen(true); } catch (error) { console.error("Error analyzing complexity:", error); setComplexity(null); setError(t("Error")); setOpen(true); } finally { setIsLoading(false); } }; return ( <> {t("ComplexityAnalysis")} {error ? ( {error} ) : ( {t("TimeComplexity")} {complexity?.time} {t("SpaceComplexity")} {complexity?.space} )} ); };