<script>
  import "./TailwindStyles.svelte";
  import "toastify-js/src/toastify.css";
  import "gridjs/dist/theme/mermaid.css";
  import { Route, router } from "tinro";
  router.subscribe((routeInfo) => {
    window.scrollTo(0, 0);
  });
  if (config.prefersHashRouting) {
    if (config.prefersHashRouting === true) {
      router.useHashNavigation();
    }
  }
  import localForage from "localforage";
  import { addMessages, init, getLocaleFromNavigator } from "svelte-i18n";
  import en from "./locales/en.json";
  import de from "./locales/de.json";
  addMessages("en", en);
  addMessages("de", de);
  init({
    fallbackLocale: "en",
    initialLocale: getLocaleFromNavigator(),
  });
  localForage.config({
    name: "lfk_admin",
    version: 1.0,
    storeName: "lfk_admin",
    description: "LfK! admin dashbaord",
  });
  //
  import Login from "./components/Login.svelte";
  import Dashboard from "./components/Dashboard.svelte";
  import store from "./store.js";
  import ForgotPassword from "./components/ForgotPassword.svelte";
  import MainDashContent from "./components/MainDashContent.svelte";
  import Users from "./components/Users.svelte";
  import About from "./components/About.svelte";
  import Settings from "./components/Settings.svelte";
  import Transition from "./components/Transition.svelte";
  import Orgs from "./components/Orgs.svelte";
  import Runners from "./components/Runners.svelte";
  import Footer from "./components/Footer.svelte";
  import TracksOverview from "./components/TracksOverview.svelte";
  import OrgDetail from "./components/OrgDetail.svelte";
  import Teams from "./components/Teams.svelte";
  import { OpenAPI } from "@odit/lfk-client-js";
  import UserDetail from "./components/UserDetail.svelte";
  OpenAPI.BASE = config.baseurl;
  import { register as registerSW } from "./swmodule";
  import TeamDetail from "./components/TeamDetail.svelte";
  import RunnerDetail from "./components/RunnerDetail.svelte";
  store.init();
  registerSW();
</script>

<Route>
  {#if $router.path === '/forgot_password'}
    <Route path="/forgot_password">
      <ForgotPassword />
    </Route>
  {:else if $router.path === '/about'}
    <Route path="/about">
      <About />
    </Route>
  {:else if $store.isLoggedIn}
    <Dashboard>
      <Transition>
        <Route path="/">
          <MainDashContent />
        </Route>
        <Route path="/users/*">
          <Route path="/">
            <Users />
          </Route>
          <Route path="/:userid" let:params>
            <UserDetail {params} />
          </Route>
        </Route>
        <Route path="/tracks/*">
          <Route path="/">
            <TracksOverview />
          </Route>
          <Route path="/:trackid" let:params />
        </Route>
        <Route path="/runners/*">
          <Route path="/">
            <Runners />
          </Route>
          <Route path="/:runnerid" let:params>
            <RunnerDetail {params} />
          </Route>
        </Route>
        <Route path="/teams/*">
          <Route path="/">
            <Teams />
          </Route>
          <Route path="/:teamid" let:params>
            <TeamDetail {params} />
          </Route>
        </Route>
        <Route path="/orgs/*">
          <Route path="/">
            <Orgs />
          </Route>
          <Route path="/:orgid" let:params>
            <OrgDetail {params} />
          </Route>
        </Route>
        <Route path="/about">
          <About />
        </Route>
        <Route path="/settings">
          <Settings />
        </Route>
      </Transition>
      <Footer />
    </Dashboard>
  {:else}
    <Login />
  {/if}
</Route>
