<template>
  <div>

    <Edit_Reponse_Courte @actionMoodle="passerMoodle" v-show="type_question === 'shortanswer'" v-bind:questionParsee="questionParsee"></Edit_Reponse_Courte>
    <Edit_Vrai_Faux @actionMoodle="passerMoodle" v-show="type_question === 'truefalse'" v-bind:questionParsee="questionParsee"></Edit_Vrai_Faux>
    <Edit_Choix_Multiple @actionMoodle="passerMoodle" v-show="type_question === 'multichoice'" v-bind:questionParsee="questionParsee"></Edit_Choix_Multiple>
    <Edit_Numerique @actionMoodle="passerMoodle" v-show="type_question === 'numerical'" v-bind:questionParsee="questionParsee"></Edit_Numerique>
    <Edit_Calculee_Simple @actionMoodle="passerMoodle" v-show="type_question === 'calculatedsimple'" v-bind:questionParsee="questionParsee"></Edit_Calculee_Simple>
  </div>
</template>

<script>
import Service from "@/service/Service";
import Edit_Reponse_Courte from "@/components/moodle/Edit_Reponse_Courte";
import Edit_Vrai_Faux from "@/components/moodle/Edit_Vrai_Faux";
import Edit_Choix_Multiple from "@/components/moodle/Edit_Choix_Multiple";
import Edit_Numerique from "@/components/moodle/Edit_Numerique";
import Edit_Calculee_Simple from "@/components/moodle/Edit_Calculee_Simple";

export default {
  name: "Edit_Contenus",
  components: {Edit_Calculee_Simple, Edit_Numerique, Edit_Choix_Multiple, Edit_Vrai_Faux, Edit_Reponse_Courte},
  props: {
    // mode sombre activé ou non
    darktheme: {},
    //l'id du contenu clique
    idContenu: {},
    //la provenance du contenu
    provenance: {}
  },
  methods: {
    passerMoodle: function (event) {
      if (event.action === 'arriere')
        this.$emit("actionMoodle", {action: event.action})
      else
        this.$emit("actionMoodle", {action: event.action, questionParsee: event.questionParsee})
    }
  },
  data: function () {
    return {
      questionParsee: '',
      type_question: ''
    }
  },
  watch: {
    idContenu: function () {
      let that = this

      //alert(that.provenance)

      if (this.provenance !== 'en-cours') {
        Service.parserTexte(JSON.stringify(this.idContenu)).then(function (response) {
          that.questionParsee = response.data
          that.type_question = that.questionParsee.type_question

        })
      } else {
        Service.parserTexteEnCours(JSON.stringify(this.idContenu)).then(function (response) {
          that.questionParsee = response.data
          that.type_question = that.questionParsee.type_question

        })
      }
    }
  }
}
</script>

<style scoped>

</style>