<template>
  <div class="working-area">
    <img
      class="effect"
      src="@/assets/images/step-1-init.png"
      alt=""
      draggable="false"
    >
    <video
      v-show="workState === 'working' || workState === 'done'"
      ref="videoRef"
      src="@/assets/videos/step-1.mp4"
      playsinline
      webkit-playsinline="true"
      muted
      @ended="workState = 'done'"
    />
    <img
      v-show="workState === 'working'"
      class="tool"
      :style="{
        animationPlayState: workState === 'working' ? 'running' : 'paused',
      }"
      :src="toolList[requiredToolList[0]].url"
      alt=""
      draggable="false"
    >
  </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'
    }, 500)
  }
})

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.effect{
    position: absolute;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    object-fit: contain;
  }
  >video{
    position: absolute;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    object-fit: contain;
  }
  >img.tool{
    position: absolute;
    transform: translate(-10%, -95%);
    width: calc(85 / v-bind('windowSizeWhenDesignForRef') * v-bind('windowSizeInCssForRef'));
    animation-name: tool-move;
    animation-delay: 0.3s;
    animation-duration: 1.9s;
    animation-timing-function: linear;
    animation-fill-mode: forwards;
    left: 10%;
    top: 10%;
  }
}
@keyframes tool-move {
  15% {
    left: 90%;
    top: 10%;
  }
  30% {
    left: 10%;
    top: 30%;
  }
  45% {
    left: 90%;
    top: 30%;
  }
  60% {
    left: 10%;
    top: 70%;
  }
  75% {
    left: 90%;
    top: 70%;
  }
  88% {
    left: 10%;
    top: 90%;
  }
  100% {
    left: 90%;
    top: 90%;
  }
}
</style>