'use client' import { useState } from 'react' import { Switch } from '@/components/ui/switch' import { Label } from '@/components/ui/label' import { Loader2, Check, X } from 'lucide-react' import { cn } from '@/lib/utils' import { toast } from 'sonner' import { useLanguage } from '@/lib/i18n' interface SettingToggleProps { label: string description?: string checked: boolean onChange: (checked: boolean) => Promise disabled?: boolean } export function SettingToggle({ label, description, checked, onChange, disabled }: SettingToggleProps) { const { t } = useLanguage() const [isLoading, setIsLoading] = useState(false) const [error, setError] = useState(false) const handleChange = async (newChecked: boolean) => { setIsLoading(true) setError(false) try { await onChange(newChecked) toast.success(t('toast.saved')) } catch (err) { console.error('Error updating setting:', err) setError(true) toast.error(t('toast.saveFailed')) } finally { setIsLoading(false) } } return (
{description && (

{description}

)}
{isLoading && } {!isLoading && !error && checked && } {!isLoading && !error && !checked && }
) }