/**
 * Formipay Admin - React Application Entry Point
 */

import { render } from '@wordpress/element';
import App from './components/App';

// Mount the React app to all available mount points
const mountApps = () => {
    const mountPoints = document.querySelectorAll('[data-formipay-mount]');

    mountPoints.forEach((mountPoint) => {
        const page = mountPoint.dataset.formipayMount;
        const initialData = window.formipayAdmin?.[page] || {};

        render(
            <App page={page} initialData={initialData} />,
            mountPoint
        );
    });
};

// Initialize when DOM is ready
if (document.readyState === 'loading') {
    document.addEventListener('DOMContentLoaded', mountApps);
} else {
    mountApps();
}
