<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'"
    />
  </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.rubber-board{
    position: absolute;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
  }
  >.paper{
    position: absolute;
    left: -2.5%;
    top: -2.5%;
    width: 97%;
    height: 97.5%;
    background-color: #fff;
  }
  >video{
    position: absolute;
    left: 0;
    top: 0;
    width: 97%;
    height: 98%;
  }
}
</style>