/**
* Chatbot Settings - module-level settings with TabPanel.
*/
import { useState, useEffect, useCallback } from '@wordpress/element';
import { __ } from '@wordpress/i18n';
import { Button, TextControl, TextareaControl, SelectControl, ToggleControl, TabPanel, Spinner } from '@aime/wp-components';
import useApi from '../../../../hooks/useApi';
import Card from '../../../common/Card';
import Loader from '../../../common/Loader';
import Notice from '../../../common/Notice';
import { toast } from '../../../common/Toast';
const TABS = [
{ name: 'general', title: __( 'General', 'ai-marketing-expert' ) },
{ name: 'behavior', title: __( 'Behavior', 'ai-marketing-expert' ) },
{ name: 'notifications', title: __( 'Notifications', 'ai-marketing-expert' ) },
{ name: 'privacy', title: __( 'Privacy & GDPR', 'ai-marketing-expert' ) },
];
const THEME_OPTIONS = [
{ label: 'Default (Indigo)', value: 'default' },
{ label: 'Modern (Dark)', value: 'modern' },
{ label: 'Minimal (Green)', value: 'minimal' },
];
const parseNumber = ( value, fallback, allowZero = false ) => {
const parsed = parseInt( value, 10 );
if ( Number.isNaN( parsed ) ) return fallback;
if ( allowZero ) return Math.max( 0, parsed );
return Math.max( 1, parsed );
};
const Settings = () => {
const { get, post, loading, error, clearError } = useApi();
const [ settings, setSettings ] = useState( null );
const [ saving, setSaving ] = useState( false );
const [ success, setSuccess ] = useState( '' );
const fetchSettings = useCallback( async () => {
try {
const res = await get( '/chatbot/settings' );
setSettings( res );
} catch ( e ) {
// silent
}
}, [ get ] );
useEffect( () => {
fetchSettings();
}, [ fetchSettings ] );
const handleSave = async () => {
setSaving( true );
setSuccess( '' );
try {
const res = await post( '/chatbot/settings', settings );
if ( res?.settings ) {
setSettings( res.settings );
}
setSuccess( __( 'Settings saved.', 'ai-marketing-expert' ) );
} catch ( e ) {
toast( e.message, 'error' );
} finally {
setSaving( false );
}
};
if ( loading && ! settings ) {
return