<template>
  <div>
    <HiteachNoteList :class="{ 'hide-sidebar': this.$store.getters.getSidebarisOpen == false }" />
    <HiteachNoteContent
      :class="{
        'hiteachNote-content-span': this.$store.getters.getSidebarisOpen == false}"
    />
  </div>
</template>

<script>
import HiteachNoteList from "./HiteachNoteList";
import HiteachNoteContent from "./HiteachNoteContent";
import mockdata from "@/api/newData";
import mockdataEn from "@/api/newDataEn";
export default {
  name: "HiteachView",

  data() {
    return {
      mockdata: "",
      MyNo: "5", //接收NavBar 選定的那一頁icon標示
      MyName: "",
    };
  },

  components: {
    HiteachNoteList,
    HiteachNoteContent,
  },
  methods: {
    gotoNextItem() {
      let nextItems = [];
      let allstudyListItem = [];
      for (let i = 0; i < this.mockdata.length; i++) {
        if (this.mockdata[i].eventType == "Hiteach電子筆記") {
          allstudyListItem.push(this.mockdata[i]);
        }
        if (this.$store.getters.getItemTitle == this.mockdata[i]) {
          console.log("目前：" + i, this.mockdata[i].eventName);
          let j = i + 1;
          if (
            j < this.mockdata.length &&
            this.mockdata[j].eventType == "Hiteach電子筆記"
          ) {
            nextItems.push(this.mockdata[j]);
          } else {
            for (let j = i + 1; j < this.mockdata.length; j++) {
              if (this.mockdata[j].eventType == "Hiteach電子筆記") {
                nextItems.push(this.mockdata[j]);
              }
            }
          }
        }
      }

      if (nextItems != "") {
        if (
          nextItems[0].eventName ==
          allstudyListItem[allstudyListItem.length - 1].eventName
        ) {
          console.log("沒有下一個!");
        }
        console.log("下一個：" + nextItems[0].eventName);
        this.$store.commit("ChangeItemName", nextItems[0]);
        this.$store.commit("SetisFromInfoPoptpScroll", true);
      } else {
        this.$store.commit("ChangeItemName", allstudyListItem[0]);
        this.$store.commit("SetisFromInfoPoptpScroll", true);
      }
    },
  },
  created() {
     if(localStorage.getItem("lang") == ""){
      this.mockdata = mockdata.eventList;
    }
   
    if (localStorage.getItem("lang") == "tw") {
      this.mockdata = mockdata.eventList;
    } else this.mockdata = mockdataEn.eventList;
    //發送本頁target 跟名字給App.Vue 的navBar
    this.MyName = this.$t("studentWeb.hiteachview-title");
    this.$emit("onNavNo", this.MyNo);
    this.$emit("onNavName", this.MyName);
    this.$store.commit("ToggleSidebar", true);
  },
};
</script>

<style scoped>
.hide-sidebar * {
  width: 0px;
  transition: ease-out 0.3s;
}
.hide-sidebar .list-title,
.hide-sidebar .search,
.hide-sidebar .icon-selector {
  display: none;
}
.hiteachNote-content-span {
  padding: 1% 15%;
  width: 100%;
  transition: 0.5s;
}
</style>
