<template>
  <div id="Chapter1_1" class="content-wrap">
    <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('Chapter1')"><img src="../../../../resources/img/left.png" alt=""></div>
      <div class="content title-box">
        <p class="title mt25 title-bg">step1. Hello WORLD</p>

        <div class="imgGroup">
          <img src="../../../../resources/img/img35_s.png" data-num="1">

        </div>
        <div class="textareaGroup">
          <textarea>Bike lanes are important because they ket, bike riders and all other people safe. Before bike lanes, people rode on the sidewalk or in the same lanes as the cars on the street. Riding a bike on the sidewalk can cause you to crash into someone who is walking by. And riding a bike in the same lanes as cars can be unsafe, too, Bikes move more slowly than cars, so people driving behind bikes will try to go around them. These cars could hit the bike riders or other cars. </textarea>
          <div id="popup" class="popup">
            <div class="imgGroup mb10">
              <img src="../../../../resources/img/img36_s.png" data-num="1">
            </div>
              <h3>sidewalk</h3>
             <div class="flex align-center  justify-center mt10">
                <p class="yellow-box">명</p>
                <span class="title1">보도</span>
             </div>
          </div>
        </div>
      </div>
      <div class="next-btn" @click="goToPage('Chapter1_2')"><img src="../../../../resources/img/right.png" alt=""></div>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
    }
  },
  methods: {
    goToPage(page) {
      this.$router.push({ name: page });
    }
  },
  watch: {

  },
  computed: {

  },
  components: {
  },
  mounted() {
    const textArea = this.$refs.textArea;
      const popup = this.$refs.popup;

      textArea.addEventListener('mousemove', (event) => {
         const text = textArea.value;
         const words = text.split(' ');
         const selectionStart = textArea.selectionStart;
         const selectionEnd = textArea.selectionEnd;

         if (selectionStart !== selectionEnd) {
            const selectedText = text.substring(selectionStart, selectionEnd);
            const rect = textArea.getBoundingClientRect();
            popup.style.left = `${event.clientX}px`;
            popup.style.top = `${event.clientY + window.scrollY}px`;
            popup.innerHTML = `You selected: ${selectedText}`;
            popup.style.display = 'block';
         } else {
            popup.style.display = 'none';
         }
      });

      document.addEventListener('click', (event) => {
         if (!textArea.contains(event.target) && !popup.contains(event.target)) {
            popup.style.display = 'none';
         }
      });
  }
}
</script>