import '@fontsource/roboto/300.css';
import '@fontsource/roboto/400.css';
import '@fontsource/roboto/500.css';
import '@fontsource/roboto/700.css';
import { observer } from 'mobx-react-lite';
import Button from "@mui/material/Button";
import CssBaseline from "@mui/material/CssBaseline";
import React from 'react';
import { render } from 'react-dom';

import { StoreProvider, useStore } from './components/StoreProvider';
import { ThemeProvider } from './components/ThemeProvider';
import { exposeToReduxDevtools } from './devTools';
import { createAndConnectRootStore } from './stores/RootStore';

const isDevelopment = import.meta.env.MODE === 'development';

const store = createAndConnectRootStore(window.sophieRenderer);

if (isDevelopment) {
  exposeToReduxDevtools(store);
}

const Example = observer(() => {
  const { shared: { clickCount } } = useStore();

  return (
    <Button
      variant="contained"
      onClick={() => store.buttonClick()}
    >
      Hello Sophie! {clickCount}
    </Button>
  );
});

function Root(): JSX.Element {
  return (
    <React.StrictMode>
      <StoreProvider store={store}>
        <ThemeProvider>
          <CssBaseline enableColorScheme />
          <Example />
        </ThemeProvider>
      </StoreProvider>
    </React.StrictMode>
  );
}

render(<Root />, document.querySelector('#app'));
