import { createRoot } from 'react-dom/client';
import { SlotFillProvider } from '@wordpress/components';

import ABTests from './ABTests';

/**
 * Render site analytics
 */
document.addEventListener(
	'DOMContentLoaded',
	() => {
		const el = document.getElementById( 'growthstack-ab' );
		if ( el ) {
			const args = JSON.parse( el.dataset.args || '{}' );
			const root = createRoot( el );
			root.render(
				<SlotFillProvider>
					<ABTests assetsFolder={ args.assetsFolder } upgradeUrl={ args.upgradeUrl } />
				</SlotFillProvider>
			);
		}
	},
	false
);
