<script>
  import { apikey, api_endpoint, lang, clear, laptime_track } from "./store.js";
  import { addMessages, init } from "svelte-i18n";
  import en from "./locales/en.json";
  import de from "./locales/de.json";
  addMessages("en", en);
  addMessages("en-US", en);
  addMessages("de", de);
  addMessages("de-DE", de);
  //
  import Beamershow from "./Beamershow.svelte";
  import Login from "./Login.svelte";
  import Settings from "./Settings.svelte";
  export let settings_open = false;
  $: is_configured = $apikey?.length === 44 && $api_endpoint?.includes("://");
  // &&
  // $laptime_track != 0 &&
  // $laptime_track != null;
  init({
    fallbackLocale: "en-US",
    initialLocale: $lang,
  });
  $: command = "";
  (() => {
    document.onkeydown = (e) => {
      e = e || window.event;
      if (e.key === "Escape") {
        modal_open = false;
      }
      // if (e.keyCode === 13) {
      //   if (createbtnenabled === true) {
      //     createbtnenabled = false;
      //     submit();
      //   }
      // }
      if (command === "" && e.key === "c") {
        command = "c";
      } else if (command === "c" && e.key === "n") {
        command += "n";
      } else if (command === "cn" && e.key === "f") {
        settings_open = true;
        command = "";
      } else {
        command = "";
      }
    };
  })();
  console.log("app started with base url " + $api_endpoint);
</script>

{#if settings_open && is_configured}
  <Settings bind:settings_open />
{:else if is_configured}
  <Beamershow />
{:else}
  <Login />
{/if}
