<template>
  <main class="flex flex-col items-stretch | w-full" style="--row-gap: 2rem">
    <header class="flex | bg-white | rounded-2xl | p-8">
      <router-link
        :to="'/' + page.parent"
        class="btn btn--white"
        data-icon="arrow-left"
        aria-labelledby="back-to-project"
      >
        <span id="back-to-project">Retour au projet</span>
      </router-link>
      <button
        class="btn | ml-auto"
        @click="validate"
        v-if="page.content.isvalidated != 'true'"
        :disabled="
          !page.hasOwnProperty('moodboard') || page.moodboard.length === 0
        "
        :title="
          !page.hasOwnProperty('moodboard') || page.moodboard.length === 0
            ? 'Ajoutez au moins une image'
            : undefined
        "
      >
        Valider et envoyer le brief
      </button>
    </header>
    <Images />
  </main>
</template>
<script setup>
import Images from '../components/project/brief/Images.vue';
import { usePageStore } from '../stores/page';
import { storeToRefs } from 'pinia';
import { useApiStore } from '../stores/api';

const { page } = storeToRefs(usePageStore());
const api = useApiStore();

function validate() {
  api.validateBrief(page.value.uri).then((res) => {
    location.href = '/' + page.value.parent;
  });
}
</script>

<style scoped>
@media (max-width: 540px) {
  #back-to-project {
    display: none;
  }
}
</style>
