<template>
  <BulmaDrawer
    header="Konfiguration"
    :ready="is_loaded"
    @open="on_open"
    refreshable
  >
    <div class="card-content">
      <div class="columns">
        <div class="column is-one-third">
          <div class="content">
            <h4>Rätsel</h4>
            <dl>
              <dt>Titel</dt>
              <!-- TODO -->
              <dd>Adventskalender 2023</dd>

              <dt>Lösung</dt>
              <dd>{{ config_model.puzzle.solution }}</dd>

              <dt>Reihenfolge</dt>
              <dd>
                <template
                  v-for="(day_part, index) in day_parts"
                  :key="`part-${index}`"
                >
                  <span>
                    <template v-if="index > 0"> &ndash; </template>
                    {{ day_part.day }}:
                  </span>
                  <span class="is-family-monospace">{{ day_part.part }}</span>
                </template>
              </dd>

              <dt>Offene Türchen</dt>
              <!-- TODO -->
              <dd>10</dd>

              <dt>Nächstes Türchen in</dt>
              <!-- TODO -->
              <dd>dd-hh-mm-ss</dd>

              <dt>Erstes Türchen</dt>
              <dd>{{ config_model.puzzle.begin }}</dd>

              <dt>Letztes Türchen</dt>
              <dd>{{ config_model.puzzle.end }}</dd>

              <dt>Rätsel schließt</dt>
              <dd>{{ config_model.puzzle.closing }}</dd>

              <dt>Zufalls-Seed</dt>
              <dd class="is-family-monospace">
                "{{ config_model.puzzle.seed }}"
              </dd>
            </dl>
          </div>
        </div>
        <div class="column is-one-third">
          <div class="content">
            <h4>Kalender</h4>
            <dl>
              <dt>Definition</dt>
              <dd>{{ config_model.calendar.config_file }}</dd>

              <dt>Hintergrundbild</dt>
              <dd>{{ config_model.calendar.background }}</dd>

              <dt>Türchen</dt>
              <dd>
                <template
                  v-for="(day_part, index) in day_parts"
                  :key="`door-${index}`"
                >
                  <span>
                    <template v-if="index > 0">, </template>
                    {{ day_part.day }}
                  </span>
                </template>
              </dd>
            </dl>

            <h4>Bilder</h4>
            <dl>
              <dt>Größe</dt>
              <dd>{{ config_model.image.size }} px</dd>

              <dt>Rand</dt>
              <dd>{{ config_model.image.border }} px</dd>

              <dt>Schriftarten</dt>
              <dd
                v-for="(font, index) in config_model.image.fonts"
                :key="`font-${index}`"
              >
                {{ font.file }} (Größe {{ font.size }})
              </dd>
            </dl>
          </div>
        </div>
        <div class="column is-one-third">
          <div class="content">
            <h4>WebDAV</h4>
            <dl>
              <dt>URL</dt>
              <dd>{{ config_model.webdav.url }}</dd>

              <dt>Zugangsdaten</dt>
              <!-- TODO -->
              <dd>
                <span>***</span>
                <button class="tag button icon is-primary ml-2">
                  <font-awesome-icon icon="fa-solid fa-eye" />
                </button>
              </dd>

              <dt>Cache-Dauer</dt>
              <dd>{{ config_model.webdav.cache_ttl }} s</dd>

              <dt>Konfigurationsdatei</dt>
              <dd>{{ config_model.webdav.config_file }}</dd>

              <dt>UI-Admin</dt>
              <!-- TODO -->
              <dd>
                <span>***</span>
                <button class="tag button icon is-primary ml-2">
                  <font-awesome-icon icon="fa-solid fa-eye" />
                </button>
              </dd>
            </dl>
          </div>
        </div>
      </div>
    </div>
  </BulmaDrawer>
</template>

<script lang="ts">
import { ConfigModel, DayPartModel } from "@/lib/api";
import { Options, Vue } from "vue-class-component";

import BulmaDrawer from "./bulma/Drawer.vue";

@Options({
  components: {
    BulmaDrawer,
  },
})
export default class extends Vue {
  public is_loaded = false;
  public config_model: ConfigModel = {
    puzzle: {
      solution: "ABCDEFGHIJKLMNOPQRSTUVWX",
      begin: "01.12.2023",
      end: "24.12.2023",
      closing: "01.04.2024",
      seed: "",
    },
    calendar: {
      config_file: "default.toml",
      background: "adventskalender.jpg",
    },
    image: {
      size: 500,
      border: 30,
      fonts: [{ file: "files/Lena.ttf", size: 50 }],
    },
    webdav: {
      url: "https://example.com/remote.php/webdav/advent22",
      cache_ttl: 30,
      config_file: "config.toml",
    },
  };
  public day_parts: DayPartModel[] = [];

  public on_open(): void {
    this.is_loaded = false;

    Promise.all([
      this.$advent22.api_get<ConfigModel>("admin/config_model"),
      this.$advent22.api_get<DayPartModel[]>("admin/day_parts"),
    ])
      .then(([config_model, day_parts]) => {
        this.config_model = config_model;
        this.day_parts = day_parts;
        this.is_loaded = true;
      })
      .catch(console.log);
  }
}
</script>

<style scoped>
dd {
  overflow-x: auto;
}
</style>
