<template>
  <div class="working-area">
    <img
      v-show="innerState === 0"
      class="helper-board"
      src="@/assets/images/helper-board.png"
      alt=""
      draggable="false"
    >
    <video
      v-show="innerState === 0 && workState === 'working'"
      ref="videoRef1"
      class="helper-board"
      src="@/assets/videos/step-4-1.mp4"
      playsinline
      webkit-playsinline="true"
      muted
      @ended="workState = 'init', innerState = 1"
    />
    <img
      v-show="innerState == 1 || innerState === 2"
      class="helper-board"
      src="@/assets/images/helper-board-middle.png"
      alt=""
      draggable="false"
    >
    <video
      v-show="(innerState === 1 && workState === 'working') || (innerState === 2)"
      ref="videoRef2"
      class="helper-board"
      src="@/assets/videos/step-4-2.mp4"
      playsinline
      webkit-playsinline="true"
      muted
      @ended="innerState = 2, videoRef3.play()"
    />
    <!-- <img
      v-show="innerState == 2"
      class="helper-board"
      src="@/assets/images/helper-board-done.png"
      alt=""
      draggable="false"
    > -->
    <img
      class="rubber-board-init"
      src="@/assets/images/step-4-init.png"
      alt=""
      draggable="false"
    >
    <video
      ref="videoRef3"
      class="rubber-board"
      src="@/assets/videos/step-4-3.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 === 1) {
    setTimeout(() => {
      workState.value = 'working'
    }, 500)
  } else if (vNew === 2) {
    setTimeout(() => {
      workState.value = 'working'
    }, 500)
  }
})

const videoRef1 = ref(null)
const videoRef2 = ref(null)
const videoRef3 = ref(null)

const innerState = ref(0) //0：初始，1：颜料已挤出，2：滚筒已粘上颜料

watch(workState, (vNew) => {
  if (vNew === 'working' && innerState.value === 0) {
    videoRef1.value.play()
  } else if (vNew === 'working' && innerState.value === 1) {
    videoRef2.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.helper-board{
    position: absolute;
    left: 0;
    top: 0;
    width: 100%;
    // height: 100%;
  }
  >video.helper-board{
    position: absolute;
    left: 0;
    top: 0;
    width: 98%;
    // height: 100%;
  }
  >img.rubber-board-init{
    position: absolute;
    left: 0;
    top: calc(168 / v-bind('windowSizeWhenDesignForRef') * v-bind('windowSizeInCssForRef'));;
    width: 100%;
  }
  >video.rubber-board{
    position: absolute;
    left: 0;
    top: calc(169 / v-bind('windowSizeWhenDesignForRef') * v-bind('windowSizeInCssForRef'));;
    width: 97.5%;
  }
}
</style>