import React from 'react';
import ReactDom from 'react-dom';

import App from './app';
import { keycloak } from './__data__/const';

export default () => <App/>;

const start = async () => {
  // onLoad: 'check-sso',
// silentCheckSsoRedirectUri: `${location.origin}/silent-check-sso.html`
  try {
      const authenticated = await keycloak.init({ onLoad: 'login-required' });
      console.log(`User is ${authenticated ? 'authenticated' : 'not authenticated'}`);
  } catch (error) {
      console.error('Failed to initialize adapter:', error);
  }
}

start();

export const mount = (Сomponent) => {
    ReactDom.render(
        <Сomponent/>,
        document.getElementById('app')
    );

    if(module.hot) {
        module.hot.accept('./app', ()=> {
            ReactDom.render(
                <App/>,
                document.getElementById('app')
            );
        })
    }
};

export const unmount = () => {
    ReactDom.unmountComponentAtNode(document.getElementById('app'));
};

