import { useState } from 'react'; import { __ } from '@wordpress/i18n'; import { toast } from 'sonner'; import { Switch } from '../ui/switch'; import { Facebook, Linkedin } from 'lucide-react'; import { PluginSettings, savePluginSettings } from '../../api'; interface SocialPlatform { key: string; label: string; description: string; checked: boolean; iconBg: string; icon: React.ReactNode; } interface SocialShareImageProps { settings: PluginSettings | null; onSave?: () => void; } export default function SocialShareImage({ settings, onSave }: SocialShareImageProps) { const [saving, setSaving] = useState(false); const [facebook, setFacebook] = useState(settings?.social_facebook ?? false); const [linkedin, setLinkedin] = useState(settings?.social_linkedin ?? false); const [twitter, setTwitter] = useState(settings?.social_twitter ?? false); const [pinterest, setPinterest] = useState( settings?.social_pinterest ?? false, ); const handleSocialToggle = (platform: string, checked: boolean) => { const stateMap: Record void> = { facebook: setFacebook, linkedin: setLinkedin, twitter: setTwitter, pinterest: setPinterest, }; stateMap[platform](checked); }; const handleSave = async () => { setSaving(true); try { await savePluginSettings({ social_facebook: facebook, social_linkedin: linkedin, social_twitter: twitter, social_pinterest: pinterest, }); toast.success(__('Settings saved successfully.', 'image-sizes')); onSave?.(); } catch { toast.error(__('Failed to save settings.', 'image-sizes')); } finally { setSaving(false); } }; const handleReset = () => { setFacebook(false); setLinkedin(false); setTwitter(false); setPinterest(false); toast.success(__('Settings reset successfully.', 'image-sizes')); }; const socialPlatforms: SocialPlatform[] = [ { key: 'facebook', label: __('Facebook', 'image-sizes'), description: __('Generate optimized share images for Facebook posts', 'image-sizes'), checked: facebook, iconBg: 'bg-[#EFF6FF]', icon: , }, { key: 'linkedin', label: __('LinkedIn', 'image-sizes'), description: __('Create professional share images for LinkedIn', 'image-sizes'), checked: linkedin, iconBg: 'bg-[#EAF8FF]', icon: , }, { key: 'twitter', label: __('Twitter', 'image-sizes'), description: __('Optimize share images for Twitter cards', 'image-sizes'), checked: twitter, iconBg: 'bg-[#F0F0F0]', icon: ( ), }, { key: 'pinterest', label: __('Pinterest', 'image-sizes'), description: __('Generate Pinterest-optimized pin images', 'image-sizes'), checked: pinterest, iconBg: 'bg-[#FFF0F1]', icon: ( ), }, ]; return (
{socialPlatforms.map((platform) => (
{platform.icon}

{platform.label}

{platform.description}

handleSocialToggle(platform.key, checked) } />
))}
); }