import React, {useEffect, useState, useContext} from 'react';
import intl from 'react-intl-universal';
import locales from "./locales/locales";
import './App.css';
import {useAppSelector} from "./store/hooks";
import {selectChangeLangAndCss} from "./store/ChangeLangAndCss";
import {createBrowserRouter, RouterProvider,} from "react-router-dom";

import ErrorPage from "./page/ErrorPage";
import MainP from "./page/MainP/MainP";
import MainE from "./page/MainE/MainE";
import MainQ from "./page/MainQ/MainQ";
import SwitchAll from "./page/AutoSwitch/SwitchAll";
import SwitchLine from "./page/AutoSwitch/SwitchLine";
import {MyObservable} from "./context/MyObservable";
import {Observable} from "@babylonjs/core";
import {selectGlassStatus} from "./store/ProductionMonitoringEntity";

// const LOCALES_LIST = [
//   {
//     label: "English",
//     value: "en-US",
//   },
//   {
//     label: "简体中文",
//     value: "zh-CN",
//   },
// ];

const onGlassObservable = new Observable();

function App() {
  const thisLineGlassStatus = useAppSelector(selectGlassStatus)
  onGlassObservable.notifyObservers(thisLineGlassStatus)

  const Locale = useAppSelector(selectChangeLangAndCss).Locale;

  const setCurrentLocale = (currentLocale: string) => {
    intl.init({
      currentLocale,
      locales: locales,
    }).then(() => {
      console.log('Language Changed to ' + currentLocale);
    });
  };

  setCurrentLocale(Locale);

  const router = createBrowserRouter([
    {
      path: "/",
      element: <MainP/>,
      errorElement: <ErrorPage/>
    },
    {
      path: "/P",
      element: <MainP/>,
      errorElement: <ErrorPage/>
    },
    {
      path: "/Q",
      element: <MainQ/>,
      errorElement: <ErrorPage/>
    },
    {
      path: "/E/:LineID?",
      element: <MainE/>,
      errorElement: <ErrorPage/>
    },
    ///////////////////////////////////////////////////////////////////////////
    {
      path: "/SA",
      element: <SwitchAll/>,
      errorElement: <ErrorPage/>
    },
    {
      path: "/SL/:LineID?",
      element: <SwitchLine/>,
      errorElement: <ErrorPage/>
    },
  ]);

  return (
    <MyObservable.Provider value={onGlassObservable}>
      <div className="background">
        <RouterProvider router={router}/>
      </div>
    </MyObservable.Provider>
  );
}

export default App;
