<template>
  <div class="working-area">
    <img
      class="rubber-board"
      src="@/assets/images/step-3-init.png"
      alt=""
      draggable="false"
    >
    <div
      v-show="toolList[7].selected && workState === 'init'"
      class="paper"
    />
    <video
      v-show="workState === 'working' || workState === 'done'"
      ref="videoRef"
      src="@/assets/videos/step-5.mp4"
      playsinline
      webkit-playsinline="true"
      muted
      @ended="workState = 'done'"
    />
    <Transition name="tool-fade-in-out">
      <img
        v-show="workState === 'working'"
        class="tool"
        :style="{
          animationPlayState: workState === 'working' ? 'running' : 'paused',
        }"
        :src="toolList[4].url"
        alt=""
        draggable="false"
      >
    </Transition>
  </div>
</template>

<script setup>
import { ref, computed, watch } from "vue"
import { toolList, selectedToolNum, workState } from "@/store/index.js"

const {
  windowSizeInCssForRef,
  windowSizeWhenDesignForRef,
} = useSizeAdapt()

const props = defineProps(['requiredToolList'])

const requiredToolList = computed(() => {
  return props.requiredToolList
})

watch(selectedToolNum, (vNew) => {
  if (vNew === requiredToolList.value.length) {
    setTimeout(() => {
      workState.value = 'working'
    }, 1000)
  }
})

const videoRef = ref(null)

watch(workState, (vNew) => {
  if (vNew === 'working') {
    videoRef.value.play()
  }
})

</script>

<style lang="less" scoped>
.working-area{
  position: absolute;
  left: 50%;
  top: calc(314 / v-bind('windowSizeWhenDesignForRef') * v-bind('windowSizeInCssForRef'));
  transform: translate(-50%, -50%);
  width: calc(328 / v-bind('windowSizeWhenDesignForRef') * v-bind('windowSizeInCssForRef'));
  height: calc(438 / v-bind('windowSizeWhenDesignForRef') * v-bind('windowSizeInCssForRef'));;
  >img.rubber-board{
    position: absolute;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    box-shadow: 0px 4px 7px 0px rgba(0,0,0,0.25);
  }
  >.paper{
    position: absolute;
    left: -2.5%;
    top: -2.5%;
    width: 97%;
    height: 97.5%;
    background-color: #fff;
    box-shadow: 0px 4px 7px 0px rgba(0,0,0,0.25);
  }
  >video{
    position: absolute;
    left: 0;
    top: 0;
    width: 97%;
    height: 98%;
  }
  >img.tool{
    position: absolute;
    transform: translate(-30%, -65%);
    width: calc(85 / v-bind('windowSizeWhenDesignForRef') * v-bind('windowSizeInCssForRef'));
    animation-name: tool-move;
    animation-delay: 0.5s;
    animation-duration: 4s;
    animation-timing-function: linear;
    animation-fill-mode: forwards;
    left: 15%;
    top: 15%;
  }
}
@keyframes tool-move {
  6% {
    left: 85%;
    top: 15%;
  }
  6.1% {
    left: 15%;
    top: 32.5%;
  }
  12% {
    left: 85%;
    top: 32.5%;
  }
  12.1% {
    left: 15%;
    top: 50%;
  }
  18% {
    left: 85%;
    top: 50%;
  }
  18.1% {
    left: 15%;
    top: 67.5%;
  }
  24% {
    left: 85%;
    top: 67.5%;
  }
  24.1% {
    left: 15%;
    top: 85%;
  }
  30% {
    left: 85%;
    top: 85%;
  }
  30.1% {
    left: 15%;
    top: 15%;
  }
  36% {
    left: 85%;
    top: 15%;
  }
  36.1% {
    left: 15%;
    top: 32.5%;
  }
  42% {
    left: 85%;
    top: 32.5%;
  }
  42.1% {
    left: 15%;
    top: 50%;
  }
  48% {
    left: 85%;
    top: 50%;
  }
  48.1% {
    left: 15%;
    top: 67.5%;
  }
  54%{
    left: 85%;
    top: 67.5%;
  }
  54.1% {
    left: 15%;
    top: 85%;
  }
  60%{
    left: 85%;
    top: 85%;
  }
  60.1% {
    left: 15%;
    top: 15%;
  }
  66% {
    left: 85%;
    top: 15%;
  }
  66.1% {
    left: 15%;
    top: 32.5%;
  }
  72% {
    left: 85%;
    top: 32.5%;
  }
  72.1% {
    left: 15%;
    top: 50%;
  }
  78% {
    left: 85%;
    top: 50%;
  }
  78.1% {
    left: 15%;
    top: 67.5%;
  }
  84%{
    left: 85%;
    top: 67.5%;
  }
  84.1% {
    left: 15%;
    top: 85%;
  }
  90%{
    left: 85%;
    top: 85%;
  }
  100% {
    left: 85%;
    top: 85%;
  }
}
</style>