<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"
          :disabled="!can('create', 'club', 'protocol')"
        />
      </div>
      <div class="w-full">
        <label for="date">Datum</label>
        <input type="date" id="date" v-model="activeProtocolObj.date" :disabled="!can('create', 'club', 'protocol')" />
      </div>
      <div class="flex flex-row gap-2 w-full">
        <div class="w-full">
          <label for="starttime">Startzeit</label>
          <input
            type="time"
            id="starttime"
            step="1"
            v-model="activeProtocolObj.starttime"
            :disabled="!can('create', 'club', 'protocol')"
          />
        </div>
        <div class="w-full">
          <label for="endtime">Endzeit</label>
          <input
            type="time"
            id="endtime"
            step="1"
            v-model="activeProtocolObj.endtime"
            :disabled="!can('create', 'club', 'protocol')"
          />
        </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"
          :enable="can('create', 'club', 'protocol')"
          :style="!can('create', 'club', 'protocol') ? 'opacity: 75%; background: rgb(243 244 246)' : ''"
        />
      </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";
import { useAbilityStore } from "@/stores/ability";
</script>

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