<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_2')"><img src="../../../../resources/img/left.png" alt=""></div>
      <div class="content title-box">
        <p class="title mt25 title-bg">step2</p>
        <div class="flex align-center mb30">
          <p class="subtitle2 mr20">앗! 잉크가 쏟아졌어! 지우개로 잉크를 지워줘!</p>
        </div>

        <div class="text-ct">
          <div class="dropGroup flex align-center justify-center">
            <div style="position: relative;">
              <img src="../../../../resources/img/img72_41s.png" alt="" style="width: 93%;">
              <div class="vocaGroup">
                <div class="flex justify-between mb80">
                  <article class="flex align-center">
                    <div class="imgGroup mr30">
                      <img src="../../../../resources/img/img74_41s.png" data-num="1" class="ink" />
                    </div>
                    <div class="flex align-start">
                      <div>
                        <h3>mountain</h3>
                        <div class="flex align-center mt10">
                          <span class="title1">산</span>
                        </div>
                      </div>
                    </div>
                  </article>
                  <article class="flex align-center">
                    <div class="imgGroup mr30">
                      <img src="../../../../resources/img/img75_41s.png" data-num="2" class="ink" />
                    </div>
                    <div class="flex align-start">
                      <div>
                        <h3>cat</h3>
                        <div class="flex align-center mt10">
                          <span class="title1">고양이</span>
                        </div>
                      </div>
                    </div>
                  </article>
                </div>
                <div class="flex justify-between">
                  <article class="flex align-center">
                    <div class="imgGroup mr30">
                      <img src="../../../../resources/img/img76_41s.png" data-num="3" class="ink" />
                    </div>
                    <div class="flex align-start">
                      <div>
                        <h3>watermelon</h3>
                        <div class="flex align-center mt10">
                          <span class="title1">수박</span>
                        </div>
                      </div>
                    </div>
                  </article>
                  <article class="flex align-center">
                    <div class="imgGroup mr30">
                      <img src="../../../../resources/img/img77_41s.png" data-num="4" class="ink" />
                    </div>
                    <div class="flex align-start">
                      <div>
                        <h3>america</h3>
                        <div class="flex align-center mt10">
                          <span class="title1">보도</span>
                        </div>
                      </div>
                    </div>
                  </article>
                </div>
              </div>
              <div class="textbox">
                <button id="eraser1" class="dropzone" style="left: 141px; top: 44px;">
                  <img src="../../../../resources/img/img78_41s.png" alt="" />
                </button>
                <button id="eraser2" class="dropzone" style="left: 200px; bottom: 46px;">
                  <img src="../../../../resources/img/img79_41s.png" alt="" />
                </button>
                <button id="eraser3" class="dropzone" style="right: 237px; top: 114px;">
                  <img src="../../../../resources/img/img80_41s.png" alt="" />
                </button>
                <button id="eraser4" class="dropzone" style="right: 159px; bottom: 5px;">
                  <img src="../../../../resources/img/img81_41s.png" alt="" />
                </button>
              </div>
            </div>
          </div>
          <div class="dragGroup">
            <div>
              <article style="left: 83px; top: 69%;">
                <button id="eraser" draggable="true" @dragstart="handleDragStart">
                  <img src="../../../../resources/img/img73_41s.png" alt="" />
                </button>
              </article>
            </div>
          </div>
        </div>
      </div>
      <div class="next-btn" @click="goToPage('Chapter2_4')"><img src="../../../../resources/img/right.png" alt=""></div>
    </div>
  </div>
</template>

  
<script>
export default {
  data() {
    return {
      draggedElementId: null, // 드래그한 요소의 ID를 저장
    };
  },
  methods: {
    goToPage(page) {
      this.$router.push({ name: page });
    },
    handleDragStart(event) {
      this.draggedElementId = event.target.id; // 드래그한 요소의 ID를 저장
      event.dataTransfer.setData('text/plain', this.draggedElementId);
    },
    handleDragOver(event) {
      event.preventDefault(); // 드롭을 허용
    },
    handleDrop(event) {
      event.preventDefault();

      // 드롭된 영역이 버튼인지 확인
      const dropZone = event.target.closest('button.dropzone');

      if (dropZone) {
        // 드롭이 이루어진 영역이 버튼일 때만 처리
        dropZone.querySelector('img').style.display = 'none'; // 잉크를 숨깁니다
      }

      // 드래그한 요소를 원래 위치로 복원
      const draggedElement = document.getElementById(this.draggedElementId);
      if (draggedElement) {
        draggedElement.style.visibility = 'visible';
        draggedElement.style.position = '';
        draggedElement.style.top = '';
        draggedElement.style.left = '';
      }

      this.draggedElementId = null; // 드래그 상태 초기화
    }
  },
  mounted() {
    // 드래그 가능한 영역에 드래그 오버 및 드롭 이벤트를 추가합니다
    document.querySelectorAll('.dropzone').forEach(button => {
      button.addEventListener('dragover', this.handleDragOver);
      button.addEventListener('drop', this.handleDrop);
    });
  }
}
</script>



<style scoped>
.vocaGroup {
  width: 79%;
  position: absolute;
  top: 90px;
  left: 120px;
}

.ink {
  cursor: pointer;
}


</style>