import { createRoot } from '@wordpress/element';
import apiFetch from '@wordpress/api-fetch';
import App from './App';

document.addEventListener( 'DOMContentLoaded', () => {
	const boot = window.wuppiSettingsBoot;
	const mount = document.getElementById( 'wuppi-settings-app' );

	if ( ! mount ) {
		return;
	}

	if ( boot && boot.restNonce ) {
		apiFetch.use( apiFetch.createNonceMiddleware( boot.restNonce ) );
	}

	mount.removeAttribute( 'data-loading' );
	mount.innerHTML = '';

	const root = createRoot( mount );
	root.render( <App /> );
} );
