/** * Content Settings - module-level settings for Content Generator. * Follows the EmailSettings pattern: TabPanel inside a Card. */ import { useState, useEffect, useCallback } from '@wordpress/element'; import { __, sprintf } from '@wordpress/i18n'; import { Button, TextControl, 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 TONES = [ { label: 'Professional', value: 'professional' }, { label: 'Casual', value: 'casual' }, { label: 'Friendly', value: 'friendly' }, { label: 'Authoritative', value: 'authoritative' }, { label: 'Humorous', value: 'humorous' }, { label: 'Formal', value: 'formal' }, { label: 'Conversational', value: 'conversational' }, ]; const LANGUAGES = [ { label: 'English', value: 'en' }, { label: 'Bengali', value: 'bn' }, { label: 'Spanish', value: 'es' }, { label: 'French', value: 'fr' }, { label: 'German', value: 'de' }, { label: 'Hindi', value: 'hi' }, { label: 'Arabic', value: 'ar' }, { label: 'Portuguese', value: 'pt' }, { label: 'Chinese', value: 'zh' }, { label: 'Japanese', value: 'ja' }, { label: 'Korean', value: 'ko' }, { label: 'Russian', value: 'ru' }, { label: 'Italian', value: 'it' }, { label: 'Dutch', value: 'nl' }, { label: 'Turkish', value: 'tr' }, { label: 'Indonesian', value: 'id' }, { label: 'Vietnamese', value: 'vi' }, { label: 'Thai', value: 'th' }, { label: 'Polish', value: 'pl' }, { label: 'Swedish', value: 'sv' }, { label: 'Urdu', value: 'ur' }, { label: 'Malay', value: 'ms' }, ]; const POST_STATUSES = [ { label: 'Draft', value: 'draft' }, { label: 'Publish', value: 'publish' }, { label: 'Pending Review', value: 'pending' }, { label: 'Private', value: 'private' }, ]; const TABS = [ { name: 'generation', title: __( 'Generation', 'ai-marketing-expert' ) }, { name: 'publishing', title: __( 'Publishing', 'ai-marketing-expert' ) }, { name: 'images', title: __( 'Images', 'ai-marketing-expert' ) }, ]; const STOCK_PROVIDERS = [ { label: 'Pexels', value: 'pexels' }, { label: 'Pixabay', value: 'pixabay' }, ]; const INLINE_IMAGE_COUNTS = [ { label: __( 'None', 'ai-marketing-expert' ), value: '0' }, { label: __( '1 image', 'ai-marketing-expert' ), value: '1' }, { label: __( '2 images', 'ai-marketing-expert' ), value: '2' }, { label: __( '3 images', 'ai-marketing-expert' ), value: '3' }, ]; const INLINE_IMAGE_SIZES = [ { label: __( 'Medium (300px)', 'ai-marketing-expert' ), value: 'medium' }, { label: __( 'Medium Large (768px)', 'ai-marketing-expert' ), value: 'medium_large' }, { label: __( 'Large (1024px)', 'ai-marketing-expert' ), value: 'large' }, { label: __( 'Full Size', 'ai-marketing-expert' ), value: 'full' }, ]; const IMAGE_ORIENTATIONS = [ { label: __( 'Landscape (recommended)', 'ai-marketing-expert' ), value: 'landscape' }, { label: __( 'Any orientation', 'ai-marketing-expert' ), value: 'any' }, ]; const IMAGE_REUSE_OPTIONS = [ { label: __( '30 days', 'ai-marketing-expert' ), value: '30' }, { label: __( '60 days (recommended)', 'ai-marketing-expert' ), value: '60' }, { label: __( '90 days', 'ai-marketing-expert' ), value: '90' }, { label: __( 'Allow repeats', 'ai-marketing-expert' ), value: '0' }, ]; const ContentSettings = ( { initialTab } ) => { const { get, post, loading, error, clearError } = useApi(); const [ settings, setSettings ] = useState( null ); const [ taxonomies, setTaxonomies ] = useState( { categories: [], post_types: [] } ); const [ saving, setSaving ] = useState( false ); const [ success, setSuccess ] = useState( '' ); const fetchSettings = useCallback( async () => { try { const [ res, taxRes ] = await Promise.all( [ get( '/content/settings' ), get( '/content/wp-taxonomies' ), ] ); setSettings( res ); setTaxonomies( taxRes || { categories: [], post_types: [] } ); } catch ( e ) { // silent } }, [ get ] ); useEffect( () => { fetchSettings(); }, [ fetchSettings ] ); const handleSave = async () => { setSaving( true ); setSuccess( '' ); try { const res = await post( '/content/settings', settings ); setSettings( res.settings || settings ); setSuccess( __( 'Settings saved.', 'ai-marketing-expert' ) ); } catch ( e ) { toast( e.message, 'error' ); } finally { setSaving( false ); } }; if ( loading && ! settings ) { return ; } if ( ! settings ) return null; const setField = ( key, value ) => { setSettings( ( prev ) => ( { ...prev, [ key ]: value } ) ); }; const postTypeOptions = ( taxonomies.post_types || [] ).map( ( postType ) => ( { label: postType.label, value: postType.name, } ) ); const categoryOptions = [ { label: __( 'No default category', 'ai-marketing-expert' ), value: '0' }, ...( taxonomies.categories || [] ).map( ( category ) => ( { label: category.name, value: String( category.id ), } ) ), ]; return (
{ error && } { success && setSuccess( '' ) } /> }

{ __( 'Content Settings', 'ai-marketing-expert' ) }

{ loading ? : { ( tab ) => { if ( tab.name === 'generation' ) { return (
setField( 'default_tone', v ) } __nextHasNoMarginBottom /> setField( 'default_language', v ) } __nextHasNoMarginBottom /> setField( 'default_word_count', parseInt( v ) || 1000 ) } __nextHasNoMarginBottom />

{ __( 'Automation & Content Intelligence', 'ai-marketing-expert' ) }

{ __( 'Configure automated post-generation enhancements and publishing intelligence.', 'ai-marketing-expert' ) }

setField( 'auto_seo_optimize', v ) } />
setField( 'auto_generate_meta', v ) } />
setField( 'auto_generate_excerpt', v ) } />
setField( 'auto_internal_links', v ) } />
); } if ( tab.name === 'publishing' ) { return (
setField( 'default_post_type', v ) } __nextHasNoMarginBottom /> setField( 'default_post_status', v ) } __nextHasNoMarginBottom /> setField( 'default_category_id', parseInt( v, 10 ) || 0 ) } __nextHasNoMarginBottom />
); } if ( tab.name === 'images' ) { const activeProvider = settings.stock_provider || 'pexels'; const providerName = activeProvider === 'pixabay' ? 'Pixabay' : 'Pexels'; const hasKey = activeProvider === 'pixabay' ? !! settings.has_pixabay_key : !! settings.has_pexels_key; const anyKey = !! settings.has_pexels_key || !! settings.has_pixabay_key; return (
{ __( 'Stock Photo API Keys Moved to Global Settings', 'ai-marketing-expert' ) } { hasKey ? sprintf( __( '✓ %s Key Active', 'ai-marketing-expert' ), providerName ) : __( 'Key Not Set', 'ai-marketing-expert' ) }

{ __( 'Pexels & Pixabay API keys are now managed in Global Settings so you can use free stock photos universally across Content Generator, Social Media (Instagram, Facebook, LinkedIn, X), and other modules. Your existing saved keys remain intact.', 'ai-marketing-expert' ) }

setField( 'inline_images', parseInt( v, 10 ) || 0 ) } __nextHasNoMarginBottom /> setField( 'inline_image_size', v ) } __nextHasNoMarginBottom /> setField( 'image_orientation', v ) } __nextHasNoMarginBottom /> setField( 'image_reuse_days', parseInt( v, 10 ) || 0 ) } __nextHasNoMarginBottom />
); } return null; } }
}
); }; export default ContentSettings;