<script>
  import { apikey, api_endpoint, lang, page, clear } 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";
  $: is_configured = $apikey && $apikey !== "null" && $apikey !== "";
  $: settings_open = $page === "settings";
  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") {
        clear();
        settings_open = true;
        is_configured = true;
        command = "";
      } else {
        command = "";
      }
    };
  })();
  console.log("app started with base url " + $api_endpoint);
</script>

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