<template>
  <div
    class="base-element-cloudCoach screen-element-musicResources"
    :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">
        <musicResourcesPlayer
          v-if="inCurrentSlide"
          :width="elementInfo.width"
          :height="elementInfo.height"
          :scale="scale"
          :sid="elementInfo.sid"
          :type="elementInfo.sType"
        />
      </div>
    </div>
  </div>
</template>

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

defineProps<{
  elementInfo: PPTMusicResourcesElement
}>()

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