<template>
  <Dialog
    id="virtual-sample"
    v-model:visible="isOpen"
    modal
    :draggable="false"
    header="Titre du rendu"
    class="dialog"
    :class="{ 'with-comments': isCommentsOpen }"
    :closeOnEscape="true"
  >
    <template #header>
      <div class="dialog__tabs">
        <button
          class="btn btn--transparent | font-serif"
          data-icon="cursor"
          :aria-pressed="activeTab === 'dynamic' ? true : false"
          @click="activeTab = 'dynamic'"
        >
          <span>Vue Dynamique</span>
        </button>
        <button
          @click="activeTab = 'static'"
          class="btn btn--transparent | font-serif"
          data-icon="image"
          :aria-pressed="activeTab === 'static' ? true : false"
        >
          <span>Vue statique</span>
        </button>
      </div>
      <h2 class="font-serif text-lg">Échantillon virtuel</h2>
    </template>

    <Dynamic v-if="activeTab === 'dynamic'" />
    <Static v-if="activeTab === 'static'" />

    <template #footer>
      <button
        id="download-image"
        class="btn btn--white-10"
        data-icon="download"
      >
        <span>Sauvegarder l’image</span>
      </button>
      <button
        id="loop-animation"
        class="btn btn--transparent btn--outline"
        data-icon="loop"
      >
        <span>Animation en boucle</span>
      </button>
      <button
        id="toggle-comments"
        :aria-pressed="isCommentsOpen"
        class="btn btn--transparent btn--outline"
        data-icon="comment"
        @click="isCommentsOpen = !isCommentsOpen"
      >
        <span class="sr-only">Afficher les commentaires</span>
      </button>
      <Comments
        v-if="isCommentsOpen"
        :current-page-index="currentPageIndex"
        :file="file"
        :comments="file.comments"
        @update:file="changeFile"
      />
    </template>
  </Dialog>
</template>

<script setup>
import { storeToRefs } from "pinia";
import Dialog from "primevue/dialog";
import Dynamic from "./Dynamic.vue";
import Static from "./Static.vue";
import { ref } from "vue";
import { useDialogStore } from "../../../stores/dialog";

const { file } = defineProps({
  file: Object,
});

const { comments } = storeToRefs(useDialogStore());

// Variables
const isOpen = ref(true);
const isCommentsOpen = ref(false);
const activeTab = ref("dynamic");
</script>

<style scoped>
.dialog__inner {
  padding: var(--space-16);
}
</style>
