import { useState } from 'react'; import { __ } from '@wordpress/i18n'; import { toast } from 'sonner'; import { Switch } from '../ui/switch'; import { PluginSettings, savePluginSettings } from '../../api'; interface ConvertToWebPProps { settings: PluginSettings | null; onSave?: () => void; } export default function ConvertToWebP({ settings, onSave }: ConvertToWebPProps) { const [saving, setSaving] = useState(false); const [webpOnUpload, setWebpOnUpload] = useState( settings?.webp_on_upload ?? false, ); const [webpSingleConvert, setWebpSingleConvert] = useState( settings?.webp_single_convert ?? false, ); const handleSave = async () => { setSaving(true); try { await savePluginSettings({ webp_on_upload: webpOnUpload, webp_single_convert: webpSingleConvert, }); toast.success(__('Settings saved successfully.', 'image-sizes')); onSave?.(); } catch { toast.error(__('Failed to save settings.', 'image-sizes')); } finally { setSaving(false); } }; const handleReset = () => { setWebpOnUpload(false); setWebpSingleConvert(false); toast.success(__('Settings reset successfully.', 'image-sizes')); }; return (
{__('Automatically convert images to WebP when they are uploaded.', 'image-sizes')}
{__('Convert individual images to WebP directly from the media library.', 'image-sizes')}