/*!
 * BTHLabs HomeHub - Frontend Application (https://bthlabs.pl/)
 * Copyright 2021-present BTHLabs
 * Apache License Version 2.0
 */

import 'regenerator-runtime/runtime.js';

import {Rango, RangoApp} from '@bthlabs/rango';
import React from 'react';
import ReactDOM from 'react-dom';
import {documentTitleMiddlewareFactory} from 'redux-doctitle';

import 'react-grid-layout/css/styles.css';
import 'react-resizable/css/styles.css';
import 'scss/app.scss';

import {StateDataSource} from 'src/main/dataSources';
import * as MainApp from './main';

export const App = (settings) => {
  settings.INSTALLED_APPS = [
    MainApp, ...settings.INSTALLED_APPS,
  ];

  const documentTitleMiddleware = documentTitleMiddlewareFactory([
    'BTHLabs HomeHub',
  ]);

  settings.REDUX_MIDDLEWARES = [
    ...settings.REDUX_MIDDLEWARES, documentTitleMiddleware,
  ];

  const app = new Rango(settings);
  StateDataSource.setOfflineMode(settings.OFFLINE_MODE);
  ReactDOM.render(
    <MainApp.ErrorBoundaryView>
      <RangoApp app={app}>
        <MainApp.AppView />
      </RangoApp>
    </MainApp.ErrorBoundaryView>,
    document.getElementById('root')
  );
};
