<template>
  <div class="preview-mission">
    <br />

    <EventBasicInfo :eventType="eventType" />

    <PreviewMissionMultiTests :eventType="eventType" />

   
  </div>
</template>

<script>
import PreviewMissionMultiTests from "../EventContentTypeTemplate/PreviewMissionMultiTests";
import EventBasicInfo from "../../EventBasicInfo";
import { Random } from "mockjs";

export default {
  name: "PreviewMission",
  props: ["eventType"],
  components: {
    EventBasicInfo,

    PreviewMissionMultiTests,
  },
  computed: {
    theButtonLoop: function () {
      return Math.floor(Math.random() * 6) + 2;
    },
  },
  data() {
    return {
      selected: this.$store.getters.getCurrentSelectedReadingName,
      testcheckeds: [],
      yourAns: "請選答案",
      sentAns: false,
      clickbutnoChoose: false,
      PasstheUnittest: false,
      isLoading: false,
      fullPage: true,
      opacity: 0.6,
    };
  },

  methods: {
    
    showVideoCondition() {
      if (
        this.$store.getters.getCurrentPhase == 1 &&
        this.$store.getters.getCurrentSelectedReadingName == 2
      ) {
        return true;
      } else return false;
    },
    lockContent() {
      if (
        this.$store.getters.getCurrentPhase +
          1 -
          this.$store.getters.getCurrentPassPhaseTest >=
          2 &&
        this.$store.getters.getCurrentSelectedReadingName == "隨堂考"
      )
        return true;
      else return false;
    },
    clickStepPhaseChange(phase) {
      this.$store.commit("ChangeCurrentPhase", phase);
      this.sentCurrentSelectedReadingName(1);
      this.testcheckeds = [];
      this.yourAns = "請選答案";
      this.sentAns = false;
    },
    goNextUnit() {
      this.sentCurrentPhaseChange(1);
      this.sentCurrentSelectedReadingName(1);
      this.testcheckeds = [];
      this.yourAns = "請選答案";
      this.sentAns = false;
    },
    backQA: function () {
      this.sentAns = false;
      this.clickbutnoChoose = false;
      this.testcheckeds = [];
    },
    submitAns: function () {
      if (this.testcheckeds.length == 0) {
        this.yourAns = "請選答案";
        this.sentAns = false;
        this.clickbutnoChoose = true;
      } else if (
        this.testcheckeds.includes("北京") == true &&
        this.testcheckeds.includes("首爾") == true &&
        this.testcheckeds.includes("高雄") == false &&
        this.testcheckeds.includes("上海") == false
      ) {
        this.yourAns = "答案正確";
        this.sentAns = true;
        this.$store.commit(
          "PassPhaseTest",
          this.$store.getters.getCurrentPhase + 1
        );
        if (this.$store.getters.getCurrentPassPhaseTest == 3) {
          this.$store.commit(
            "SavefinishedItemID",
            this.$store.getters.getItemTitle.eventID
          );
          this.doAjax();
        }
      } else {
        this.yourAns = "答案錯誤";
        this.sentAns = true;
      }
    },
    RandomImage: function () {
      return Random.image("200x180");
    },
    condition: function (item) {
      if (
        this.selected == item &&
        this.$store.getters.getCurrentSelectedReadingName == item
      ) {
        /*console.log(
          "目前是condition1選中",
          item,
          this.$store.getters.getCurrentSelectedReadingName
        );*/
        return true;
      }
      if (this.$store.getters.getCurrentSelectedReadingName == 1 && item == 1) {
        //重置測驗
        this.testcheckeds = [];
        this.yourAns = "請選答案";
        this.sentAns = false;
        return true;
      } else return false;
    },
    condition2: function () {
      if (
        this.selected == ""
        //this.$store.getters.getisSelectedReadingNow == false
      ) {
        //console.log("目前是condition2選中");
        return true;
      } else return false;
    },
    sentCurrentSelectedReadingName: function (item) {
      this.selected = item; //選中物件
      this.$store.commit("ChangeCurrentSelectedReadingName", item);
    },

    sentCurrentPhaseChange: function (change) {
      console.log(
        "目前通過單元：" + this.$store.getters.getCurrentPassPhaseTest
      );
      if (
        this.$store.getters.getCurrentPhase + 1 <=
        this.$store.getters.getCurrentPassPhaseTest
      ) {
        this.yourAns = "請選答案";
        this.sentAns = false;
        this.testcheckeds = [];
      }
      if (
        (change > 0 || this.$store.getters.getCurrentPhase >= 1) &&
        (this.$store.getters.getCurrentPhase <= 1 || change < 0)
      ) {
        this.$store.commit(
          "ChangeCurrentPhase",
          this.$store.getters.getCurrentPhase + change
        );
        this.sentCurrentSelectedReadingName(1);
        console.log(
          this.$store.getters.getCurrentPhase + 1,
          this.$store.getters.getCurrentPassPhaseTest
        );
      }
    },

    Randomdesc: function () {
      return Random.cparagraph(7, 80);
    },
    Randomtitle: function () {
      return Random.ctitle(3, 6);
    },
    RandomIcon: function () {
      var myArray = ["md-image", "logo-youtube", "ios-copy"];
      return myArray[Math.floor(Math.random() * myArray.length)];
    },
    doAjax() {
      this.isLoading = true;
      // simulate AJAX
      setTimeout(() => {
        this.isLoading = false;
      }, 4000);
    },
  },
};
</script>

<style scoped>
@import "~@/assets/student-web/component_styles/preview-mission.css";
</style>
