<template>
  <div class="flex flex-col gap-2 h-full w-full overflow-y-auto">
    <div v-if="activeProtocolObj != null" class="flex flex-col gap-2 w-full">
      <div class="w-full">
        <label for="title">Titel</label>
        <input type="text" id="title" v-model="activeProtocolObj.title" />
      </div>
      <div class="w-full">
        <label for="date">Datum</label>
        <input type="date" id="date" v-model="activeProtocolObj.date" />
      </div>
      <div class="flex flex-row gap-2 w-full">
        <div class="w-full">
          <label for="starttime">Startzeit</label>
          <input type="time" id="starttime" v-model="activeProtocolObj.starttime" />
        </div>
        <div class="w-full">
          <label for="endtime">Endzeit</label>
          <input type="time" id="endtime" v-model="activeProtocolObj.endtime" />
        </div>
      </div>
      <div class="flex flex-col h-1/2">
        <label for="summary">Zusammenfassung</label>
        <QuillEditor
          id="summary"
          theme="snow"
          placeholder="Zusammenfassung zur Sitzung..."
          style="height: 250px; max-height: 250px; min-height: 250px"
          contentType="html"
          :toolbar="toolbarOptions"
          v-model:content="activeProtocolObj.summary"
        />
      </div>
    </div>

    <Spinner v-if="loadingActive == 'loading'" class="mx-auto" />
    <p v-else-if="loadingActive == 'failed'" @click="fetchProtocolByActiveId" class="cursor-pointer">
      &#8634; laden fehlgeschlagen
    </p>
  </div>
</template>

<script setup lang="ts">
import { defineComponent } from "vue";
import { mapActions, mapState, mapWritableState } from "pinia";
import Spinner from "@/components/Spinner.vue";
import { useProtocolStore } from "@/stores/admin/protocol";
import { QuillEditor } from "@vueup/vue-quill";
import "@vueup/vue-quill/dist/vue-quill.snow.css";
import { toolbarOptions } from "@/helpers/quillConfig";
</script>

<script lang="ts">
export default defineComponent({
  props: {
    protocolId: String,
  },
  computed: {
    ...mapWritableState(useProtocolStore, ["loadingActive", "activeProtocolObj"]),
  },
  mounted() {
    this.fetchProtocolByActiveId();
  },
  methods: {
    ...mapActions(useProtocolStore, ["fetchProtocolByActiveId"]),
  },
});
</script>
