import * as Sentry from "@sentry/react";
//import "antd/dist/antd.css";
import "antd/dist/antd.less";
import Dinero from "dinero.js";
import React from "react";
import ReactDOM from "react-dom";
import { Provider } from "react-redux";
import { BrowserRouter } from "react-router-dom";
import { PersistGate } from "redux-persist/integration/react";
import AppContainer from "./App/App.container";
import LoadingSpinner from "./components/loading-spinner/loading-spinner.component";
import "./index.css";
import { persistor, store } from "./redux/store";
import reportWebVitals from "./reportWebVitals";
import "./translations/i18n";
import "./utils/CleanAxios";

// Dinero.defaultCurrency = "CAD";
// Dinero.globalLocale = "en-CA";
Dinero.globalRoundingMode = "HALF_EVEN";

if (process.env.NODE_ENV !== "development") {
  Sentry.init({
    dsn: "https://fd7e89369b6b4bdc9c6c4c9f22fa4ee4@o492140.ingest.sentry.io/5651027",
    ignoreErrors: [
      "ResizeObserver loop",
      "Module specifier, 'fs' does not start",
      "Module specifier, 'zlib' does not start with",
    ],
    integrations: [
      // new Integrations.BrowserTracing(),
      // new Sentry.Integrations.Breadcrumbs({ console: true }),
    ],
    environment: process.env.NODE_ENV,
    // We recommend adjusting this value in production, or using tracesSampler
    // for finer control
    //  tracesSampleRate: 0.5,
  });
}

ReactDOM.render(
  <Provider store={store}>
    <BrowserRouter>
      <PersistGate
        loading={<LoadingSpinner message="Restoring your settings..." />}
        persistor={persistor}
      >
        <AppContainer />
      </PersistGate>
    </BrowserRouter>
  </Provider>,
  document.getElementById("root")
);

// const onServiceWorkerUpdate = (registration) => {
//   console.log("onServiceWorkerUpdate", registration);

//   const btn = (
//     <Space flex>
//       <Button
//         onClick={async () => {
//           window.open("https://imex-online.noticeable.news/", "_blank");
//         }}
//       >
//         {i18n.t("general.actions.viewreleasenotes")}
//       </Button>
//       <Button
//         type="primary"
//         onClick={async () => {
//           if (registration && registration.waiting) {
//             await registration.unregister();
//             // Makes Workbox call skipWaiting()
//             registration.waiting.postMessage({ type: "SKIP_WAITING" });
//             // Once the service worker is unregistered, we can reload the page to let
//             // the browser download a fresh copy of our app (invalidating the cache)
//             window.location.reload();
//           }
//         }}
//       >
//         {i18n.t("general.actions.refresh")}
//       </Button>
//     </Space>
//   );
//   notification.open({
//     icon: <AlertOutlined />,
//     message: i18n.t("general.messages.newversiontitle"),
//     description: i18n.t("general.messages.newversionmessage"),
//     duration: 0,
//     btn,
//     key: "updateavailable",
//   });
// };

// serviceWorkerRegistration.register({ onUpdate: onServiceWorkerUpdate });
reportWebVitals();
