<template>
<div class="vue-component">
   <h2><a id="section-100"></a>
      {{ $t('confirm.title') }}
   </h2>
   <div>
      <p v-html="$t('confirm.text_draft', [$t('course.step.draft')])"></p>

      <div v-if="!isValidToBeConfirmed">
         <div class="alert alert-warning">
            {{ $t('confirm.alert_validation') }}
            <ul class="mt-2">
               <li v-for="k in validationKeys">
                  {{ $t(notValidMessages[k].msg) }}
                  <a :href="notValidMessages[k].anchor">
                     <i class="fa fa-level-up fa-fw"></i>
                  </a>
               </li>
            </ul>
         </div>
         <ul class="record_actions">
            <li>
               <button class="btn btn-save" disabled>
                  {{ $t('confirm.ok') }}
               </button>
            </li>
         </ul>
      </div>

      <div v-else>
         <p v-html="$t('confirm.text_active', [$t('course.step.active')])"></p>
         <ul class="record_actions">
            <li>
               <button
                  class="btn btn-save"
                  @click="modal.showModal = true">
                  {{ $t('confirm.ok') }}
               </button>
            </li>
         </ul>
      </div>

   </div>

   <teleport to="body">
      <modal v-if="modal.showModal" :modalDialogClass="modal.modalDialogClass" @close="modal.showModal = false">
         <template v-slot:header>
            <h2 class="modal-title">{{ $t('confirm.sure') }}</h2>
         </template>
         <template v-slot:body>
            <p>{{ $t('confirm.sure_description') }}</p>
         </template>
         <template v-slot:footer>
            <button class="btn btn-danger" @click="confirmCourse">
               {{ $t('confirm.ok') }}
            </button>
         </template>
      </modal>
   </teleport>

</div>
</template>

<script>
import {mapGetters, mapState} from "vuex";
import Modal from 'ChillMainAssets/vuejs/_components/Modal';

export default {
   name: "Confirm",
   components: {
      Modal,
   },
   data() {
      return {
         modal: {
            showModal: false,
            modalDialogClass: "modal-dialog-centered modal-md"
         },
         notValidMessages: {
            participation: {
               msg: 'confirm.participation_not_valid',
               anchor: '#section-10'
            },
            location: {
               msg: 'confirm.location_not_valid',
               anchor: '#section-20' //
            },
            socialIssue: {
               msg: 'confirm.socialIssue_not_valid',
               anchor: '#section-50'
            },
            scopes: {
              msg: 'confirm.set_a_scope',
              anchor: '#section-65'
            }
         }
      }
   },
   computed: {
      ...mapState([
         'accompanyingCourse'
      ]),
      ...mapGetters([
         'isParticipationValid',
         'isSocialIssueValid',
         'isLocationValid',
         'validationKeys',
         'isValidToBeConfirmed'
      ])
   },
   methods: {
      confirmCourse() {
        //console.log('@@ CLICK confirmCourse');
         this.$store.dispatch('confirmAccompanyingCourse');
        //console.log('confirm last');
      }
   }
}
</script>
