<template>
  <div
    class="cloudCoachPlayer"
    :style="{
      width: width * scale + 'px',
      height: height * scale + 'px',
      transform: `scale(${1 / scale})`
    }"
  >
    <div v-if="loading" class="loading-overlay">
      <div class="spinner"></div>
      <div class="text">云教练加载中...</div>
    </div>
    <iframe class="musicIframe" frameborder="0" :src="url" @load="handleIframeLoad"></iframe>
  </div>
</template>

<script setup lang="ts">
import { ref } from "vue"

const props = withDefaults(
  defineProps<{
    width: number
    height: number
    url: string
    scale?: number
  }>(),
  {
    scale: 1
  }
)

const loading = ref(true)
function handleIframeLoad() {
  loading.value = false
}
</script>

<style lang="scss" scoped>
.cloudCoachPlayer {
  width: 100%;
  height: 100%;
  position: relative;
  overflow: hidden;
  user-select: none;
  line-height: 1;
  transform-origin: 0 0;
  background-color: #213793;
  .musicIframe {
    width: 100%;
    height: 100%;
  }
  .loading-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    flex-direction: column;
    z-index: 10;
    color: #fff;
    background-color: #213793;
    .spinner {
      border: 4px solid #f3f3f3;
      border-top: 4px solid #213793;
      border-radius: 50%;
      width: 40px;
      height: 40px;
      animation: spin 1s linear infinite;
    }
    .text {
      margin-top: 10px;
    }
    @keyframes spin {
      0% {
        transform: rotate(0deg);
      }
      100% {
        transform: rotate(360deg);
      }
    }
  }
}
</style>
