<template>
  <div
    class="base-element-enjoy screen-element-enjoy"
    :style="{
      top: elementInfo.top + 'px',
      left: elementInfo.left + 'px',
      width: elementInfo.width + 'px',
      height: elementInfo.height + 'px'
    }"
  >
    <div class="rotate-wrapper" :style="{ transform: `rotate(${elementInfo.rotate}deg)` }">
      <div class="element-content">
        <enjoyPlayer v-if="inCurrentSlide" :elementInfo="elementInfo" :scale="scale" :isScreening="true" :needWaitAnimation="needWaitAnimation" />
      </div>
    </div>
  </div>
</template>

<script lang="ts" setup>
import { inject, ref, computed } from "vue"
import { storeToRefs } from "pinia"
import { useSlidesStore } from "@/store"
import type { PPTEnjoyElement } from "@/types/slides"
import enjoyPlayer from "./enjoyPlayer.vue"
import { injectKeySlideScale, injectKeySlideId } from "@/types/injectKey"

defineProps<{
  elementInfo: PPTEnjoyElement
  needWaitAnimation: boolean
}>()

const { currentSlide } = storeToRefs(useSlidesStore())

const scale = inject(injectKeySlideScale) || ref(1)
const slideId = inject(injectKeySlideId) || ref("")

const inCurrentSlide = computed(() => currentSlide.value.id === slideId.value)
</script>

<style lang="scss" scoped>
.screen-element-enjoy {
  position: absolute;
}
.rotate-wrapper {
  width: 100%;
  height: 100%;
}
.element-content {
  width: 100%;
  height: 100%;
}
</style>
