"use client"; import { useEffect, useState, type ReactNode } from "react"; import { ArrowDownToLineIcon, BookOpenIcon, ClockIcon, CpuIcon, GaugeIcon, InfoIcon, LandmarkIcon, LanguagesIcon, SparklesIcon, SquareArrowRightEnterIcon, } from "lucide-react"; import { Dialog, DialogContent, DialogTitle, DialogTrigger } from "@/components/ui/dialog"; import { Button } from "@/components/ui/button"; import { Progress, ProgressLabel } from "@/components/ui/progress"; import { Separator } from "@/components/ui/separator"; import { getUsage } from "@/lib/api"; import { cn, formatNumber, formatTimestamp } from "@/lib/utils"; import type { CollocationsResult, DictionaryResult, ExamplesResult, Fetched, Source, TranslationResult, UsageResult, } from "@/types/api"; import { useLocale, useTranslations } from "next-intl"; interface PropertyDialogProps { response: Fetched | null; definition?: Fetched | null; examples?: Fetched | null; collocations?: Fetched | null; } function PropertyRow({ icon, label, value }: { icon: ReactNode; label: string; value?: string | null }) { const tc = useTranslations("Common"); return (
{icon}

{label}

{value || tc("dash")}

); } function PropertySection({ icon, title, children }: { icon: ReactNode; title: string; children: ReactNode }) { return (
{icon}

{title}

{children}
); } function UsageBar({ label, used, limit }: { label: string; used: number; limit: number }) { const locale = useLocale(); const percent = limit > 0 ? Math.min(100, (used / limit) * 100) : 0; return ( = 90 && "**:data-[slot=progress-indicator]:bg-destructive")} > {label}
{formatNumber(used, locale)} / {formatNumber(limit, locale)}
); } function UsageSection() { const t = useTranslations("Properties"); const [usage, setUsage] = useState(null); const [failed, setFailed] = useState(false); useEffect(() => { let cancelled = false; getUsage() .then((data) => { if (!cancelled) setUsage(data); }) .catch((err) => { console.error("Usage lookup failed:", err); if (!cancelled) setFailed(true); }); return () => { cancelled = true; }; }, []); return (

{t("usage")}

{failed &&

{t("usageUnavailable")}

} {!failed && !usage && (

{t("loadingUsage")}

)} {usage && (
{usage.deepl ? ( ) : (

{t("deeplUnavailable")}

)}
{t("requestsThisMonth", { count: usage.ai.requests })}
)}
); } export function PropertyDialog({ response, definition, examples, collocations }: PropertyDialogProps) { const t = useTranslations("Properties"); const tc = useTranslations("Common"); const locale = useLocale(); const sourceValue = (source: Source) => source === "provider" ? tc("provider") : tc("cache"); return ( } /> {t("title")}
{response && ( } title={t("translate")}> } label={tc("source")} value={sourceValue(response.source)} /> } label={tc("provider")} value={response.provider} /> {response.model && ( } label={tc("model")} value={response.model} /> )} } label={tc("generated")} value={formatTimestamp(response.generated_at, locale)} /> } label={tc("fetched")} value={formatTimestamp(response.fetched_at, locale)} /> )} {definition && ( } title={t("definition")}> } label={tc("source")} value={sourceValue(definition.source)} /> } label={tc("provider")} value={definition.provider} /> {definition.model && ( } label={tc("model")} value={definition.model} /> )} } label={tc("generated")} value={formatTimestamp(definition.generated_at, locale)} /> } label={tc("fetched")} value={formatTimestamp(definition.fetched_at, locale)} /> )} {examples && ( } title={t("examples")}> } label={tc("source")} value={sourceValue(examples.source)} /> } label={tc("provider")} value={examples.provider} /> {examples.model && ( } label={tc("model")} value={examples.model} /> )} } label={tc("generated")} value={formatTimestamp(examples.generated_at, locale)} /> } label={tc("fetched")} value={formatTimestamp(examples.fetched_at, locale)} /> )} {collocations && ( } title={t("collocations")}> } label={tc("source")} value={sourceValue(collocations.source)} /> } label={tc("provider")} value={collocations.provider} /> {collocations.model && ( } label={tc("model")} value={collocations.model} /> )} } label={tc("generated")} value={formatTimestamp(collocations.generated_at, locale)} /> } label={tc("fetched")} value={formatTimestamp(collocations.fetched_at, locale)} /> )}
); }