<template>
  <div id="Chapter1_1" 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">
      <span class="title mr40">1. Hello WORLD</span>
      <span class="subtitle">my name is dd</span>
    </div>
    <div class="flex justify-between align-center">
      <div class="pre-btn" @click="goToPage('Chapter2_11')">
        <img src="../../../../resources/img/left.png" alt="" />
      </div>
      <div class="content title-box">
        <div style="display: flex; justify-content: space-between">
          <p class="title mt25 title-bg">step3-놀면서 배우는 영어</p>
          <button id="returnButton" @click="returnPage" style="margin: 4rem">
            <img src="../../../../resources/img/btn_return_50x50.png" alt="" />
            <p>되돌리기</p>
          </button>
        </div>

        <div class="flex align-center mb30 questionBox">
          <p class="subtitle2 mr20">문제를 맞춰 폭탄을 제거해줘!</p>
          <div style="height: 130px">
            <div>
              <div>
                <p class="second"></p>
                <p class="text"></p>
              </div>
            </div>
          </div>
        </div>

        <div class="text-ct">
          <div class="imgGroup flex align-center justify-center">
            <div class="flex" style="gap: 20px; position: relative">
              <img
                src="../../../../resources/img/img105_46s.png"
                alt=""
                style="width: 90%"
              />

              <div class="textbox">
                <p class="little-title">{{ problem }}</p>
                <div class="pickGroup">
                  <article class="flex mb10" style="gap: 60px">
                    <div class="flex align-center" @click="handleClick(1)">
                      <button>
                        <img
                          src="../../../../resources/img/img136_71s.png"
                          alt=""
                        />
                        <p :class="{ active: selectedButton === 1 }">1</p>
                      </button>
                      <p class="red">{{ choice[0] }}</p>
                    </div>
                  </article>
                  <article class="flex mb10" style="gap: 60px">
                    <div class="flex align-center" @click="handleClick(2)">
                      <button>
                        <img
                          src="../../../../resources/img/img136_71s.png"
                          alt=""
                        />
                        <p :class="{ active: selectedButton === 2 }">2</p>
                      </button>
                      <p class="orange">{{ choice[1] }}</p>
                    </div>
                  </article>
                  <article class="flex mb10" style="gap: 60px">
                    <div class="flex align-center" @click="handleClick(3)">
                      <button>
                        <img
                          src="../../../../resources/img/img136_71s.png"
                          alt=""
                        />
                        <p :class="{ active: selectedButton === 3 }">3</p>
                      </button>
                      <p class="blue">{{ choice[2] }}</p>
                    </div>
                  </article>
                  <article class="flex" style="gap: 60px">
                    <div class="flex align-center" @click="handleClick(4)">
                      <button>
                        <img
                          src="../../../../resources/img/img136_71s.png"
                          alt=""
                        />
                        <p :class="{ active: selectedButton === 4 }">4</p>
                      </button>
                      <p class="green">{{ choice[3] }}</p>
                    </div>
                  </article>
                </div>
              </div>
              <!-- 오답일 경우 아래의 이미지가 보여야함 -->
              <div
                v-if="correct"
                class="flex justify-center wrong-anwser"
                style="gap: 20px"
              >
                <img src="../../../../resources/img/img165_46s.png" alt="" />
              </div>
            </div>
          </div>
        </div>
        <div class="answerBox">
          <button class="answerButton" @click="confirmAnswer">정답 확인</button>
        </div>
      </div>
      <div class="next-btn" @click="goToPage('Chapter3')">
        <img src="../../../../resources/img/right.png" alt="" />
      </div>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      timer: "00",
      problem: "아래 보기 중 한국어 뜻과 영어 뜻이 다른 것은?",

      choice: [
        "apple - 사과",
        "banana - 바나나",
        "plum - 손바닥",
        "watermelon - 수박",
      ],
      answer: 3,

      selectedButton: null,
      correct: false,
    };
  },
  methods: {
    goToPage(page) {
      this.$router.push({ name: page });
    },
    startTimer() {
      if (this.intervalId) {
        clearInterval(this.intervalId);
      }
      this.timer = 5;
      this.intervalId = setInterval(() => {
        if (this.timer > 0) {
          this.timer--;
        } else {
          clearInterval(this.intervalId);
        }
      }, 1000);
    },
    handleClick(buttonNumber) {
      this.selectedButton = buttonNumber; // 선택된 버튼 번호 저장
    },

    confirmAnswer() {
      if (this.selectedButton === null) {
        alert("정답을 선택해주세요.");
        return;
      }
      if (this.selectedButton === this.answer) {
        alert("정답입니다!");
      } else {
        this.correct = true;
      }
      this.selectedButton = null;
    },
    returnPage() {
      window.location.reload();
    },
  },
  watch: {},
  computed: {},
  components: {},
  mounted() {},
};
</script>
<style scoped>
.wrong-anwser {
  position: absolute;
  top: 51%;
  left: 45%;
  transform: translate(-50%, -50%);
}
.textbox {
  position: absolute;
  top: 140px;
  left: 45px;
}
.time-bg {
  margin-right: 40px;
  top: 136px;
  right: 124px;
}
.pickGroup {
  margin: 40px 0 0 180px;
}
.pickGroup button {
  position: relative;
  margin-right: 30px;
}
.pickGroup button img {
  width: 33px;
  height: 33px;
}
.pickGroup button p {
  font-size: 20px;
  color: #c6c6c6;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}
.pickGroup article {
  cursor: pointer;
}
.pickGroup article > div > p {
  font-size: 24px;
}

.pickGroup button p.active {
  color: #000; /* 선택된 버튼의 숫자 색을 더 진하게 */
}

.little-title {
  text-align: start;
  font-size: 24px;
  font-weight: bold;
}

.questionBox {
  justify-content: space-between;
  align-items: flex-start;
}

.imgGroup {
  position: absolute;
  top: 150px;
  left: 30%;
  width: fit-content;
}

.answerBox {
  margin-top: 295px;
  text-align: right;
}
.answerButton {
  background-color: #ffc107;
  border-radius: 30px;
  padding: 20px 50px;
  margin: 40px;
  font-family: "ONEMobileOTF-Regular";
  font-weight: bold;
  font-size: 24px;
}
</style>
