<template>
  <BulmaDrawer header="Konfiguration">
    <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>{{ admin_config_model.puzzle.solution }}</dd>

              <dt>Reihenfolge</dt>
              <dd>
                <template
                  v-for="(day_part, idx) in admin_config_model.puzzle.day_parts"
                  :key="`part-${idx}`"
                >
                  <span>
                    <template v-if="idx > 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>{{ admin_config_model.puzzle.begin }}</dd>

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

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

              <dt>Zufalls-Seed</dt>
              <dd class="is-family-monospace">
                "{{ admin_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>{{ admin_config_model.calendar.config_file }}</dd>

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

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

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

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

              <dt>Schriftarten</dt>
              <dd
                v-for="(font, idx) in admin_config_model.image.fonts"
                :key="`font-${idx}`"
              >
                {{ 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>{{ admin_config_model.webdav.url }}</dd>

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

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

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

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

<script lang="ts">
import { Options, Vue } from "vue-class-component";

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

interface ConfigModel {
  puzzle: {
    solution: string;
    day_parts: { day: number; part: string }[];
    begin: string;
    end: string;
    closing: string;
    seed: string;
  };
  calendar: {
    config_file: string;
    background: string;
  };
  image: {
    size: number;
    border: number;
    fonts: { file: string; size: number }[];
  };
  webdav: {
    url: string;
    cache_ttl: number;
    config_file: string;
  };
}

@Options({
  components: {
    BulmaDrawer,
  },
})
export default class extends Vue {
  public admin_config_model: ConfigModel = {
    puzzle: {
      solution: "ABCDEFGHIJKLMNOPQRSTUVWX",
      day_parts: [],
      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 mounted(): void {
    this.$advent22
      .api_get<ConfigModel>("admin/config_model")
      .then((data) => (this.admin_config_model = data))
      .catch(console.log);
  }
}
</script>

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