<template>
  <div id="Chapter1_1" class="content-wrap">
    <div style="margin: 30px 0px 50px">
      <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_6')">
        <img src="../../../../resources/img/left.png" alt="" />
      </div>
      <div class="content title-box">
        <p class="title mt25 title-bg">step3 - 놀면서 배우는 영어</p>
        <div class="flex align-center mb30">
          <p class="subtitle2 mr20">
            방문이 자물쇠로 잠겨져 있네? 세 개 중에 맞는 열쇠 하나를 찾아줘!
          </p>
        </div>

        <div class="flex align-center justify-center" style="gap: 113px">
          <div class="imgGroup">
            <div class="flex" style="gap: 60px">
              <button>
                <img src="../../../../resources/img/img82_42s.png" alt="" />
                <p>{{ beforeQuestion }}</p>
              </button>
              <button>
                <img src="../../../../resources/img/img159_42s.png" alt="" />
              </button>
              <button>
                <img src="../../../../resources/img/img83_42s.png" alt="" />
                <p>{{ afterQuestion }}</p>
              </button>
            </div>
          </div>
          <div class="pickGroup">
            <div class="pickImg">
              <img src="../../../../resources/img/img84_42s.png" alt="" />
              <img src="../../../../resources/img/img85_42s.png" alt="" />
              <img src="../../../../resources/img/img86_42s.png" alt="" />
            </div>
            <div class="pickChoice">
              <article class="flex justify-center mb50" style="gap: 60px">
                <div class="flex" style="align-items: center">
                  <button @click="handleClick(`${choice[0]}`, 1)">
                    <img
                      src="../../../../resources/img/img136_71s.png"
                      alt=""
                    />
                    <p :class="{ active: selectedButton === 1 }">1</p>
                  </button>
                  <p>{{ choice[0] }}</p>
                </div>
              </article>
              <article class="flex justify-center mb50" style="gap: 60px">
                <div class="flex" style="align-items: center">
                  <button @click="handleClick(`${choice[1]}`, 2)">
                    <img
                      src="../../../../resources/img/img136_71s.png"
                      alt=""
                    />
                    <p :class="{ active: selectedButton === 2 }">2</p>
                  </button>
                  <p>{{ choice[1] }}</p>
                </div>
              </article>
              <article class="flex justify-center" style="gap: 60px">
                <div class="flex" style="align-items: center">
                  <button @click="handleClick(`${choice[2]}`, 3)">
                    <img
                      src="../../../../resources/img/img136_71s.png"
                      alt=""
                    />
                    <p :class="{ active: selectedButton === 3 }">3</p>
                  </button>
                  <p>{{ choice[2] }}</p>
                </div>
              </article>
            </div>
          </div>
        </div>
      </div>
      <div class="next-btn" @click="goToPage('Chapter2_11')">
        <img src="../../../../resources/img/right.png" alt="" />
      </div>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      selectedButton: null, // 선택된 버튼을 추적하기 위한 데이터

      example: "Tell me/why/?",
      beforeQuestion: "Tell me",
      afterQuestion: "Why",
      choice: ["You are so upset", "You is so upset", "You am so upset"],
      answer: 0,
    };
  },
  methods: {
    goToPage(page) {
      this.$router.push({ name: page });
    },

    splitExample() {
      const parts = this.example.split("/?/");
      if (parts.length === 3) {
        this.beforeQuestion = parts[0];
        this.afterQuestion = parts[1];
      }
    },

    handleClick(text, buttonNumber) {
      this.selectedButton = buttonNumber; // 선택된 버튼 번호를 저장

      if (text === this.choice[this.answer]) {
        alert("정답입니다!");
      } else {
        alert("오답입니다!");
      }
    },
  },

  mounted() {
    this.splitExample();
  },
};
</script>

<style scoped>
.imgGroup {
  width: fit-content;
}
.imgGroup button {
  position: relative;
}

.imgGroup button p,
.textbox p {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: fit-content;
  height: fit-content;
  background: #ffffffb8;
  border-radius: 5px;
  padding: 10px;
  font-size: 23px;
  font-family: "ONEMobilePOP";
}
.pickGroup {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 40px;
}
.pickGroup button {
  position: relative;
  margin-right: 30px;
}

.pickGroup button p {
  font-size: 34px;
  color: #c6c6c6;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}

.pickGroup article img {
  object-fit: contain;
  width: -webkit-fill-available;
}

.pickGroup article > div > p {
  font-size: 25px;
  white-space: nowrap; /* 텍스트가 줄 바꿈 없이 한 줄로 표시되도록 설정 */
}

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

.pickImg {
  display: flex;
  flex-direction: column;
  gap: 70px;
}

.pickChoice {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
}
</style>
