<template>
  <section class="hero is-small is-primary">
    <div class="hero-body">
      <h1 class="title is-uppercase">{{ title }}</h1>
      <h2 class="subtitle">{{ subtitle }}</h2>
    </div>
  </section>

  <section class="section">
    <div class="container">
      <AdminView v-if="store.is_admin" />
      <UserView v-else />
    </div>
  </section>

  <div class="is-flex-grow-1" />

  <footer class="footer">
    <div class="level is-mobile">
      <div class="level-item">
        <p v-html="footer" />
      </div>
      <div class="level-right">
        <TouchButton class="level-item tag is-warning" />
        <AdminButton class="level-item tag is-link is-outlined" />
      </div>
    </div>
  </footer>
</template>

<script lang="ts">
import { Options, Vue } from "vue-class-component";
import { advent22Store } from "./plugins/store";

import AdminView from "./components/admin/AdminView.vue";
import AdminButton from "./components/AdminButton.vue";
import TouchButton from "./components/TouchButton.vue";
import UserView from "./components/UserView.vue";

@Options({
  components: {
    AdminView,
    AdminButton,
    TouchButton,
    UserView,
  },
})
export default class extends Vue {
  public title = "Adventskalender";
  public subtitle = "Lorem Ipsum";
  public footer = "";
  public readonly store = advent22Store();

  public mounted(): void {
    Promise.all([
      this.$advent22.api_get<string>("user/title"),
      this.subtitle, // TODO
      this.$advent22.api_get<string>("user/footer"),
    ])
      .then(([title, subtitle, footer]) => {
        document.title = `${title} – ${subtitle}`;

        this.title = title;
        this.subtitle = subtitle;
        this.footer = footer;
      })
      .catch((error) => alert(this.$advent22.format_user_error(error)));
  }
}
</script>

<style>
html {
  overflow-y: auto !important;
}

#app {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
</style>
