"use client"; import { ShieldAlert } from "lucide-react"; import { usePathname } from "next/navigation"; import { useRef, useState } from "react"; import { useFormStatus } from "react-dom"; import { Badge } from "@/components/ui/badge"; import { Checkbox } from "@/components/ui/checkbox"; import { cn } from "@/lib/utils"; type SidebarMaintenanceControlProps = { action: (formData: FormData) => Promise; initialEnabled: boolean; label: string; }; type SidebarMaintenanceFieldProps = Omit< SidebarMaintenanceControlProps, "action" | "initialEnabled" > & { enabled: boolean; onToggle: (checked: boolean) => void; }; function SidebarMaintenanceField({ enabled, label, onToggle, }: SidebarMaintenanceFieldProps) { const { pending } = useFormStatus(); return ( <> onToggle(checked === true)} className="sr-only" /> ); } export function SidebarMaintenanceControl({ action, initialEnabled, label, }: SidebarMaintenanceControlProps) { const formRef = useRef(null); const enabledInputRef = useRef(null); const pathname = usePathname(); const [enabled, setEnabled] = useState(initialEnabled); return (