<template>
  <div class="working-area">
    <img
      v-show="workState === 'init'"
      class="init"
      src="@/assets/images/step-3-init.png"
      alt=""
      draggable="false"
    >
    <img
      v-show="workState === 'working' || workState === 'done'"
      class="rubber-board"
      src="@/assets/images/rubber-board-big.png"
      alt=""
      draggable="false"
    >
    <video
      v-show="workState === 'working' || workState === 'done'"
      ref="videoRef"
      src="@/assets/videos/step-3.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[requiredToolList[0]].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.init{
    position: absolute;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    box-shadow: 0px 4px 7px 0px rgba(0,0,0,0.25);
  }
  >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);
  }
  >video{
    position: absolute;
    left: 0.5%;
    top: 0;
    width: 96.9%;
    height: 98%;
  }
  >img.tool{
    position: absolute;
    transform: translate(-10%, -95%);
    width: calc(85 / v-bind('windowSizeWhenDesignForRef') * v-bind('windowSizeInCssForRef'));
    animation-name: tool-move;
    animation-delay: 0.2s;
    animation-duration: 1.3s;
    animation-timing-function: linear;
    animation-fill-mode: forwards;
    left: 90%;
    top: 10%;
  }
}
@keyframes tool-move {
  20% {
    left: 10%;
    top: 35%;
  }
  40% {
    left: 90%;
    top: 35%;
  }
  60% {
    left: 10%;
    top: 60%;
  }
  80% {
    left: 90%;
    top: 60%;
  }
  100% {
    left: 10%;
    top: 85%;
  }
}
</style>