/**
 * FindAstra module loader — a tiny classic script that programmatically
 * injects the real ES-module entry as a brand-new <script type="module">
 * element via document.createElement.
 *
 * Why: many third-party WP themes apply their own `script_loader_tag`
 * filter (at a later priority than any plugin can reliably outrun) that
 * forces `type="text/javascript"` on every enqueued script. That breaks
 * ES-module entries with the runtime error
 * "Uncaught SyntaxError: Cannot use import statement outside a module".
 *
 * A dynamically-created element is never seen by `script_loader_tag` —
 * the filter only fires on enqueued scripts. So this loader runs as a
 * harmless classic script, then mounts the actual module entry that
 * those themes can't touch.
 *
 * Entry points are listed in window.FindAstraConfig.assets.entries.
 */
( function () {
	var cfg = window.FindAstraConfig;
	if ( ! cfg || ! cfg.assets || ! cfg.assets.dist || ! cfg.assets.entries ) {
		return;
	}
	var distBase = String( cfg.assets.dist ).replace( /\/?$/, '/' );
	var ver      = encodeURIComponent( String( cfg.version || '' ) );
	var entries  = cfg.assets.entries;
	if ( ! entries.length ) {
		return;
	}
	for ( var i = 0; i < entries.length; i++ ) {
		var file = String( entries[ i ] );
		// Defensive: don't load anything that isn't one of ours.
		if ( ! /^[a-zA-Z0-9_-]+\.js$/.test( file ) ) {
			continue;
		}
		var s = document.createElement( 'script' );
		s.type = 'module';
		s.src  = distBase + file + ( ver ? '?ver=' + ver : '' );
		document.head.appendChild( s );
	}
} )();
