import React, { useState, useEffect } from 'react'; import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card"; import { Input } from "@/components/ui/input"; import { Label } from "@/components/ui/label"; import { Button } from "@/components/ui/button"; import { Textarea } from "@/components/ui/textarea"; import { Switch } from "@/components/ui/switch"; import { RadioGroup, RadioGroupItem } from "@/components/ui/radio-group"; import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select"; import { __ } from '@wordpress/i18n'; import { HexColorPicker } from "react-colorful"; import { Sketch } from '@uiw/react-color'; const ChatWidgetSettings = ({ settings, updateSettings }) => { const handleMediaUpload = (field) => { // Create WordPress media uploader const mediaUploader = wp.media({ title: __('Select Image', 'aisk-ai-chat'), button: { text: __('Use this image', 'aisk-ai-chat') }, multiple: false }); mediaUploader.on('select', function () { const attachment = mediaUploader.state().get('selection').first().toJSON(); updateSettings('chatwidget', field, attachment.url); }); mediaUploader.open(); }; // Local state for rolling messages textarea const [rollingMessagesInput, setRollingMessagesInput] = useState(settings.chatwidget.rolling_messages?.join('\n') || ''); // Keep local state in sync if settings change externally useEffect(() => { setRollingMessagesInput(settings.chatwidget.rolling_messages?.join('\n') || ''); }, [settings.chatwidget.rolling_messages]); return ( {__('Chat Widget Settings', 'aisk-ai-chat')} {__('Customize the appearance and behavior of your chat widget', 'aisk-ai-chat')}
updateSettings('chatwidget', 'bubble_type', value)} className="grid grid-cols-2 gap-4" >
{/* Message Settings based on type */} {settings.chatwidget.bubble_type === 'rolling' ? (