<template>
  <Calendar :doors="doors" />
  <hr />
  <div class="content" v-html="store.site_config.content" />
  <template v-if="store.next_door_target !== null">
    <hr />
    <div class="content has-text-primary">
      Zeit zum nächsten Türchen: <CountDown :until="store.next_door_target" />
    </div>
  </template>
</template>

<script lang="ts">
import { DoorsSaved } from "@/lib/api";
import { Door } from "@/lib/door";
import { advent22Store } from "@/plugins/store";
import { Options, Vue } from "vue-class-component";

import Calendar from "./Calendar.vue";
import CountDown from "./CountDown.vue";

@Options({
  components: {
    Calendar,
    CountDown,
  },
})
export default class extends Vue {
  public readonly store = advent22Store();
  public doors: Door[] = [];

  public mounted(): void {
    this.$advent22
      .api_get<DoorsSaved>("user/doors")
      .then((data) => {
        this.doors.length = 0;

        for (const value of data) {
          this.doors.push(Door.load(value));
        }
      })
      .catch(this.$advent22.alert_user_error);
  }
}
</script>
