import { $alerts, pb } from '@/lib/stores' import { useStore } from '@nanostores/react' import { Dialog, DialogTrigger, DialogContent, DialogDescription, DialogHeader, DialogTitle, } from '@/components/ui/dialog' import { BellIcon } from 'lucide-react' import { cn } from '@/lib/utils' import { Button } from '@/components/ui/button' import { Switch } from '@/components/ui/switch' import { AlertRecord, SystemRecord } from '@/types' import { lazy, Suspense, useMemo, useState } from 'react' import { toast } from './ui/use-toast' import { Link } from './router' const Slider = lazy(() => import('./ui/slider')) const failedUpdateToast = () => toast({ title: 'Failed to update alert', description: 'Please check logs for more details.', variant: 'destructive', }) export default function AlertsButton({ system }: { system: SystemRecord }) { const alerts = useStore($alerts) const active = useMemo(() => { return alerts.find((alert) => alert.system === system.id) }, [alerts, system]) const systemAlerts = useMemo(() => { return alerts.filter((alert) => alert.system === system.id) as AlertRecord[] }, [alerts, system]) return ( ) } function AlertStatus({ system, alerts }: { system: SystemRecord; alerts: AlertRecord[] }) { const [pendingChange, setPendingChange] = useState(false) const alert = useMemo(() => { return alerts.find((alert) => alert.name === 'Status') }, [alerts]) return ( ) } function AlertWithSlider({ system, alerts, name, title, description, }: { system: SystemRecord alerts: AlertRecord[] name: string title: string description: string }) { const [pendingChange, setPendingChange] = useState(false) const [liveValue, setLiveValue] = useState(50) const alert = useMemo(() => { const alert = alerts.find((alert) => alert.name === name) if (alert) { setLiveValue(alert.value) } return alert }, [alerts]) return (