<template>
  <div id="Chapter2_2" class="content-wrap">
    <div style="margin: 30px 0px 50px; width: 20%">
      <router-link to="/MyPlan.page">
        <div class="logo mb25">
          <img src="../../../../resources/img/logo2.png" alt="" />
        </div>
      </router-link>
    </div>
    <div
      class="title-box mb25 flex align-center mt40"
      style="justify-content: space-between"
    >
      <div>
        <span class="title mr40">1. Hello WORLD</span>
        <span class="subtitle">my name is dd</span>
      </div>
      <button class="completeBtn" @click="complete">학습 종료</button>
    </div>
    <div class="flex justify-between align-center">
      <div class="pre-btn" @click="goToPage('Chapter2_9')">
        <img src="../../../../resources/img/left.png" alt="" />
      </div>
      <div class="content title-box">
        <p class="title mt25 title-bg">STEP 2 - 단어로 공부하는 영어</p>
        <div class="flex align-center mb30">
          <p class="subtitle2 mr20">다음을 듣고 맞는 단어를 선택하세요.</p>
          <!-- <button><img src="../../../../resources/img/btn10_s.png" alt="">
          </button> -->
        </div>

        <div class="imgGroup">
          <div class="flex justify-center">
            <div class="listenGroup flex" style="gap: 60px">
              <button
                class="popTxt"
                v-for="(item, index) in items"
                :key="index"
                @click="updateContent(index)"
                :class="{ active: selectedIndex === index }"
              >
                <img :src="item.imgSrc1" />
                <img
                  :src="item.imgSrc2"
                  v-if="selectedIndex === index"
                  style="display: block"
                />
                <div class="textbox">
                  <div style="height: 80%; line-height: 200px">
                    <img :src="item.imgSrc" alt="" />
                  </div>
                  <p class="subtitle3" style="height: 20%">{{ item.title }}</p>
                </div>
              </button>
            </div>
          </div>
          <div class="listen-btn mt50">
            <img
              src="client/resources/img/btn10_s.png"
              alt="Listen"
              @click="playAudio"
            />
          </div>

          <audio
            id="audio-player"
            src="client/resources/audio/bank.wav"
            preload="auto"
          ></audio>
        </div>
      </div>
      <div class="next-btn" @click="goToPage('Chapter2_8')">
        <img src="../../../../resources/img/right.png" alt="" />
      </div>
    </div>
  </div>
</template>
<script>
import SvgIcon from "@jamescoyle/vue-icon";
export default {
  data() {
    return {
      items: [
        {
          imgSrc1: "client/resources/img/img61_36s.png",
          imgSrc2: "client/resources/img/img62_36s.png",
          imgSrc: "client/resources/img/img59_36s.png",
          title: "apple",
        },
        {
          imgSrc1: "client/resources/img/img61_36s.png",
          imgSrc2: "client/resources/img/img62_36s.png",
          imgSrc: "client/resources/img/img2_4.png",
          title: "bank",
        },
        {
          imgSrc1: "client/resources/img/img61_36s.png",
          imgSrc2: "client/resources/img/img62_36s.png",
          imgSrc: "client/resources/img/img57_36s.png",
          title: "car",
        },
        {
          imgSrc1: "client/resources/img/img61_36s.png",
          imgSrc2: "client/resources/img/img62_36s.png",
          imgSrc: "client/resources/img/img56_36s.png",
          title: "guitar",
        },
      ],
      selectedIndex: 0,
    };
  },
  methods: {
    complete() {
      this.$router.push({ name: "Dashboard", query: { value: 2 } });
    },
    goToPage(page) {
      this.$router.push({ name: page });
    },
    updateContent(index) {
      this.selectedIndex = index;
      this.currentCon = this.items[index].con;
      setTimeout(() => {
        if (index == 1) {
          alert("정답입니다!");
        } else {
          alert("오답입니다!");
        }
      }, 0);
    },
    playAudio() {
      const audio = document.getElementById("audio-player");
      audio.play();
      console.log("playing");
    },
  },
  components: {
    SvgIcon,
  },
};
</script>

<style scoped>
.listenGroup {
  height: 305px;
}

.listenGroup button {
  position: relative;
}

.listenGroup .textbox {
  width: 184px;
  height: 206px;
  left: 46%;
  top: 43%;
}

.look-text {
  bottom: 50px;
}

.btnGroup {
  width: 1060px;
  height: 340px;
}

.popTxt {
  width: 216px;
}

.popTxt > img {
  position: absolute;
  top: 0;
  left: 0;
}

.completeBtn {
  margin-right: 100px;
  background-color: #ffba08;
  padding: 10px 30px;
  border-radius: 10px;
  font-size: 28px;
  font-family: "ONEMobilePOPOTF";
}
</style>
