import { t } from "@lingui/core/macro" import { Trans, useLingui } from "@lingui/react/macro" import { useStore } from "@nanostores/react" import { XIcon } from "lucide-react" import React, { type JSX, memo, useCallback, useEffect, useState } from "react" import { $containerFilter, $maxValues } from "@/lib/stores" import { useIntersectionObserver } from "@/lib/use-intersection-observer" import { cn } from "@/lib/utils" import Spinner from "../../spinner" import { Button } from "../../ui/button" import { Card, CardDescription, CardHeader, CardTitle } from "../../ui/card" import { ChartAverage, ChartMax } from "../../ui/icons" import { Input } from "../../ui/input" import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "../../ui/select" export function FilterBar({ store = $containerFilter }: { store?: typeof $containerFilter }) { const storeValue = useStore(store) const [inputValue, setInputValue] = useState(storeValue) const { t } = useLingui() useEffect(() => { setInputValue(storeValue) }, [storeValue]) useEffect(() => { if (inputValue === storeValue) { return } const handle = window.setTimeout(() => store.set(inputValue), 80) return () => clearTimeout(handle) }, [inputValue, storeValue, store]) const handleChange = useCallback((e: React.ChangeEvent) => { const value = e.target.value setInputValue(value) }, []) const handleClear = useCallback(() => { setInputValue("") store.set("") }, [store]) return ( <> {inputValue && ( )} ) } export const SelectAvgMax = memo(({ max }: { max: boolean }) => { const Icon = max ? ChartMax : ChartAverage return ( ) }) export function ChartCard({ title, description, children, grid, empty, cornerEl, legend, className, }: { title: string description: string children: React.ReactNode grid?: boolean empty?: boolean cornerEl?: JSX.Element | null legend?: boolean className?: string }) { const { isIntersecting, ref } = useIntersectionObserver() return ( {title} {description} {cornerEl &&
{cornerEl}
}
{ } {isIntersecting && children}
) }