import { usePage } from "@inertiajs/react"; import { type ReactNode } from "react"; import type React from "react"; import { Label } from "@/components/ui/label"; import { Switch } from "@/components/ui/switch"; import InputError from "@/front/Components/cookie/InputError"; import { cn } from "@/lib/utils"; interface CookieSwitchProps { name: string; checked?: boolean; description?: string | React.ReactNode; label?: ReactNode | string; className?: string; inputClassName?: string; required?: boolean; disabled?: boolean; parentErrors?: Record | null; setData: (name: string, value: boolean) => void; labelClassName?: string; descClassName?: string; title?: string; } export default function CookieSwitch({ name, checked, description, label, className = "", inputClassName = "", required = false, disabled = false, parentErrors = null, descClassName = "text-xs", labelClassName = "text-sm", title = name, setData, }: CookieSwitchProps) { const { errors } = usePage().props; const localErrors = parentErrors ?? errors; return (
{label && ( )} {description && (

{description}

)}
{ setData(name, value); }} required={required} checked={checked} disabled={disabled} className={cn(inputClassName, { "border-destructive/50": localErrors[name], })} />
); }