import { __ } from '@wordpress/i18n'; import { getElement } from '../fields/FieldRegistry'; /** * Right panel — campaign-level settings when nothing is selected, * or schema-driven element settings when an element is selected. * * Element settings controls are generated from the PHP settingsSchema * (localized via betterPaymentCampaignData.elements), so adding a new * control to PHP automatically adds it here without touching this file. */ export default function SettingsPanel( { meta, layout, selectedElementId, selectedColumnId, dispatch } ) { let selectedElement = null; if ( selectedElementId && layout?.columns ) { for ( const col of layout.columns ) { const found = col.elements.find( ( el ) => el.id === selectedElementId ); if ( found ) { selectedElement = found; break; } } } if ( selectedElement ) { const def = getElement( selectedElement.type ); return (

{ def?.label || __( 'Element Settings', 'better-payment' ) }

); } return (

{ __( 'Campaign Settings', 'better-payment' ) }

); } // ── Schema-driven element settings ──────────────────────────────────────────── function ElementSettings( { element, columnId, schema, meta, dispatch } ) { const updateElement = ( patch ) => dispatch( { type: 'UPDATE_ELEMENT_SETTINGS', elementId: element.id, settings: patch } ); const updateMeta = ( patch ) => dispatch( { type: 'UPDATE_META', payload: patch } ); const s = element.settings || {}; if ( schema.length === 0 ) { return

{ __( 'No settings for this element.', 'better-payment' ) }

; } return (
{ schema.map( ( control ) => { const isMeta = !! control.metaKey; const value = isMeta ? ( meta?.[ control.metaKey ] ?? '' ) : s[ control.key ]; const onChange = isMeta ? ( val ) => updateMeta( { [ control.metaKey ]: val } ) : ( val ) => updateElement( { [ control.key ]: val } ); return ( ); } ) }
); } const ALIGN_OPTIONS = [ { value: 'left', title: 'Align left', icon: ( ), }, { value: 'center', title: 'Align center', icon: ( ), }, { value: 'right', title: 'Align right', icon: ( ), }, ]; function SettingsControl( { control, value, onChange } ) { const { key, label, type, placeholder, min, max, rows, options } = control; const resolvedPlaceholder = placeholder || ''; return (
{ type !== 'toggle' && ( ) } { type === 'align' && (
{ ALIGN_OPTIONS.map( ( opt ) => ( ) ) }
) } { type === 'text' && ( onChange( e.target.value ) } /> ) } { type === 'number' && ( onChange( parseInt( e.target.value, 10 ) ) } /> ) } { type === 'color' && ( onChange( e.target.value ) } /> ) } { type === 'toggle' && ( ) } { type === 'select' && ( ) } { type === 'textarea' && (