import React from "react";
import { configure } from "mobx";
import ReactDOM from "react-dom/client";
import {
  createBrowserRouter,
  RouterProvider,
} from "react-router-dom";
import RootStore from "@/stores/Root";
import { StoreContext } from '@/stores/StoreContext';
import "@/assets/global.css";
import App from "@/views/App";
import Standlone from "@/views/Standlone";
import Login from "@/views/Login";
import Logout from "@/views/Logout";
import Index from "@/views/index";
import ErrorPage from "@/components/ErrorPage";
import ReservationNewest from "@/views/reservation/Newest";
import ReservationDetail from "@/views/reservation/Detail";
import ChangePassword from "@/views/account/ChangePassword";
import AccountProfile from "@/views/account/Profile";
import AccountManagement from "@/views/account/Management";
import FeedbackIndex from "@/views/feedback/Index";
import FeedbackDetail from "@/views/feedback/Detail";
import FeedbackCustomerDetail from "@/views/feedback/CustomerDetail";
import ReportIndex from "@/views/report/Index";
import NoticeIndex from "@/views/notice/Index";
import NoticeDetail from "@/views/notice/Detail";
import InvoiceIndex from "@/views/invoice/Index";
import InvoiceDetail from "@/views/invoice/Detail";
import InvoicePaid from "@/views/invoice/Paid";
import InvoicePaidDetail from "@/views/invoice/PaidDetail";
import Airticket from "@/views/airticket/Index";
import ProductsIndex from '@/views/products/Index';
import ProductsDetail from '@/views/products/Detail';
import ProductsAudit from '@/views/products/Audit';

import './i18n';

configure({
  useProxies: "ifavailable",
  enforceActions: "observed",
  computedRequiresReaction: true,
  observableRequiresReaction: false,
  reactionRequiresObservable: true,
  disableErrorBoundaries: process.env.NODE_ENV == "production"
});

const router = createBrowserRouter([
  {
    path: "/",
    element: <App />,
    errorElement: <ErrorPage />,
    children: [
      { index: true, element: <Index /> },
      { path: "reservation/newest", element: <ReservationNewest />},
      { path: "reservation/:reservationId", element: <ReservationDetail />},
      { path: "account/change-password", element: <ChangePassword />},
      { path: "account/profile", element: <AccountProfile />},
      { path: "account/management", element: <AccountManagement />},
      { path: "feedback", element: <FeedbackIndex />},
      { path: "feedback/:GRI_SN/:CII_SN/:RefNo", element: <FeedbackCustomerDetail />},
      { path: "feedback/:GRI_SN/:RefNo", element: <FeedbackDetail />},
      { path: "report", element: <ReportIndex />},
      { path: "notice", element: <NoticeIndex />},
      { path: "notice/:CCP_BLID", element: <NoticeDetail />},
      { path: "invoice",element:<InvoiceIndex />},
      { path: "invoice/detail/:GMDSN/:GSN",element:<InvoiceDetail />},
      { path: "invoice/paid",element:<InvoicePaid />},
      { path: "invoice/paid/detail/:flid",element:<InvoicePaidDetail />},
      { path: "airticket",element:<Airticket />},
      { path: "products",element:<ProductsIndex />},
      { path: "products/:travel_agency_id/audit",element:<ProductsAudit />},
      { path: "products/:travel_agency_id",element:<ProductsDetail />},
    ]
  },
  {
    element: <Standlone />,
    children: [
      { path: "/login", element: <Login /> },
      { path: "/logout", element: <Logout /> },
    ]
  }
]);

const rootStore = new RootStore();

ReactDOM.createRoot(document.getElementById("root")).render(
  //<React.StrictMode>
    <StoreContext.Provider value={rootStore}>
      <RouterProvider
        router={router}
        fallbackElement={() => <div>Loading...</div>}
      />
    </StoreContext.Provider>
  //</React.StrictMode>
);
