<template>
  <div class="flex flex-col gap-2 h-full w-full overflow-y-auto">
    <div v-if="activeNewsletterObj != null" class="flex flex-col gap-2 w-full">
      <p class="italic">
        Titel und Zusammenfassung werden standardmäßig nicht im Newsletter angezeit, können aber bei Verwendung eines
        eigenen Templates verwendet werden.
      </p>
      <div class="w-full">
        <label for="title">Titel</label>
        <input
          type="text"
          id="title"
          v-model="activeNewsletterObj.title"
          :disabled="!can('create', 'club', 'newsletter')"
        />
      </div>
      <div class="flex flex-col h-1/2">
        <label for="summary">Zusammenfassung</label>
        <QuillEditor
          id="summary"
          theme="snow"
          placeholder="Zusammenfassung zum Newsletter..."
          style="height: 250px; max-height: 250px; min-height: 250px"
          contentType="html"
          :toolbar="toolbarOptions"
          v-model:content="activeNewsletterObj.description"
          :enable="can('create', 'club', 'newsletter')"
          :style="!can('create', 'club', 'newsletter') ? 'opacity: 75%; background: rgb(243 244 246)' : ''"
        />
      </div>
    </div>

    <Spinner v-if="loadingActive == 'loading'" class="mx-auto" />
    <p v-else-if="loadingActive == 'failed'" @click="fetchNewsletterByActiveId" 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 { useNewsletterStore } from "@/stores/admin/club/newsletter/newsletter";
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: {
    newsletterId: String,
  },
  computed: {
    ...mapWritableState(useNewsletterStore, ["loadingActive", "activeNewsletterObj"]),
    ...mapState(useAbilityStore, ["can"]),
  },
  mounted() {
    // this.fetchNewsletterByActiveId();
  },
  methods: {
    ...mapActions(useNewsletterStore, ["fetchNewsletterByActiveId"]),
  },
});
</script>
