import { createRoot } from 'react-dom/client';
import Forms from './Forms';
import Notice from '../shared/Notice';

/**
 * Render site forms.
 */
document.addEventListener(
	'DOMContentLoaded',
	() => {
		const el = document.getElementById( 'growthstack-forms' );
		if ( el ) {
			const args = JSON.parse( el.dataset.args || '{}' );
			const root = createRoot( el );
			root.render(
				<>
					<Forms
						forms={ args.forms }
						endpoints={ args.endpoints }
						lianaAutomationEnabled={ args.lianaAutomationEnabled }
						lianaAutomationSettingsUrl={
							args.lianaAutomationSettingsUrl
						}
						lianaMailerEnabled={ args.lianaMailerEnabled }
						lianaMailerSettingsUrl={ args.lianaMailerSettingsUrl }
					/>
					<Notice />
				</>
			);
		}
	},
	false
);
