"use client"; import prettyBytes from "pretty-bytes"; import { useTranslation } from "react-i18next"; import Card, { CardBody, CardHeader } from "@/lib/components/ui/Card"; import Spinner from "@/lib/components/ui/Spinner"; import { useUserData } from "@/lib/hooks/useUserData"; import { UserStats } from "@/lib/types/User"; import { BrainConsumption } from "./BrainConsumption"; import { DateComponent } from "./Date"; import BrainSpaceChart from "./Graphs/BrainSpaceChart"; import { RequestsPerDayChart } from "./Graphs/RequestsPerDayChart"; export const formatBrainSizeUsage = ( currentBrainSize: number, maxBrainSize: number ): string => { const sizeInUse = prettyBytes(maxBrainSize - currentBrainSize, { binary: true, }); const totalSize = prettyBytes(maxBrainSize - 0, { binary: true }); return `${sizeInUse} / ${totalSize}`; }; export const UserStatistics = (): JSX.Element => { const { userData }: { userData?: UserStats } = useUserData(); const { t } = useTranslation(["user"]); if (!userData) { return (
{t("fetching", { ns: "user" })}
); } const { current_brain_size, max_brain_size, date, requests_stats } = userData; return (

{t("brainUsage")}

{/* The last element corresponds to today's request_count */} {t("requestsCount", { count: requests_stats.at(-1)?.daily_requests_count, })}

{t("brainSize")}

{formatBrainSizeUsage(current_brain_size, max_brain_size)}

); }; export default UserStatistics;