import { __ } from '@wordpress/i18n'; import { SelectControl } from '@wordpress/components'; import Toggle from '../../shared/Toggle'; type AutomationTogglerFieldsProps = { channelOptions: Array< { label: string; value: string } >; cookieConsentPluginActive: boolean; onInputChange: ( name: string, value: string | boolean ) => void; step: number; values: { pbr: string | false; formsend: string | false; login: string | false; woocommerce: string | false; consent?: string | false; }; }; export default function AutomationTogglerFields( props: AutomationTogglerFieldsProps ) { const { channelOptions, cookieConsentPluginActive, onInputChange, step, values } = props; const togglerSelectCn = step === 3 ? 'gs-select-control hidden' : 'gs-select-control'; const togglerSegmentCn = step === 0 ? 'gs-field-segment' : 'gs-field-segment gs-field-segment--nostyle'; const handleTogglerChange = ( key: string, event: React.ChangeEvent< HTMLInputElement > ) => { const { checked } = event.target; if ( checked ) { return onInputChange( key, 'default' ); } return onInputChange( key, false ); }; return ( <>

{ __( 'Choose events you want to track', 'liana-with-growthstack' ) }

handleTogglerChange( 'channel_pbr', value ) } /> { values.pbr && ( onInputChange( 'channel_pbr', value ) } options={ channelOptions } value={ values.pbr } variant="minimal" /> ) }
handleTogglerChange( 'channel_formsend', value ) } /> { values.formsend && ( onInputChange( 'channel_formsend', value ) } options={ channelOptions } value={ values.formsend } variant="minimal" /> ) }
handleTogglerChange( 'channel_login', value ) } /> { values.login && ( onInputChange( 'channel_login', value ) } options={ channelOptions } value={ values.login } variant="minimal" hidden={ true } /> ) }
handleTogglerChange( 'channel_woocommerce', value ) } /> { values.woocommerce && ( onInputChange( 'channel_woocommerce', value ) } options={ channelOptions } value={ values.woocommerce } variant="minimal" /> ) }

{ __( 'Cookie consent', 'liana-with-growthstack' ) }

onInputChange( 'channel_consent', value || false ) } disabled={ cookieConsentPluginActive } options={ [ { value: '', label: __( 'None', 'liana-with-growthstack' ) }, { value: 'cookiebot', label: __( 'Cookiebot', 'liana-with-growthstack' ) }, { value: 'cookiehub', label: __( 'CookieHub', 'liana-with-growthstack' ) }, ] } variant="minimal" />

{ __( 'When a provider is selected, the tracking script is loaded only after the user consents to the Marketing cookie category.', 'liana-with-growthstack' ) }

); }