import React from 'react';
import { render } from 'react-dom';

interface ICustomerWindow extends Window {
  _autoRenderPage: boolean;
  pageConfig: {
    [pageName: string]: Record<string, any>;
  };
}

export const registerPage = (Page, pageName = '') => {
  const myWindow: ICustomerWindow = window as any;
  // eslint-disable-next-line no-underscore-dangle
  if (process?.env?.NODE_ENV !== 'production' && myWindow._autoRenderPage === true) {
    const pageProps = myWindow.pageConfig?.[pageName] || {};
    render(
      <Page {...pageProps} />, document.getElementById('container')
    );
  }
}
