<template>
  <div
    class="base-element-cloudCoach screen-element-cloudCoach"
    :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">
        <cloudCoachPlayer v-if="inCurrentSlide" :url="elementInfo.url" :width="elementInfo.width" :height="elementInfo.height" :scale="scale" />
      </div>
    </div>
  </div>
</template>

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

defineProps<{
  elementInfo: PPTCloudCoachElement
}>()

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-cloudCoach {
  position: absolute;
}
.rotate-wrapper {
  width: 100%;
  height: 100%;
}
.element-content {
  width: 100%;
  height: 100%;
}
</style>
