<template>
  <Teleport to="body">
    <Transition name="broadcast">
      <div v-if="showBroadcast" class="broadcast-overlay">
        <div class="broadcast-card">
          <div class="broadcast-header">
            <div class="broadcast-icon">
              <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
                <polygon points="11 5 6 9 2 9 2 15 6 15 11 19 11 5" />
                <path d="M19.07 4.93a10 10 0 0 1 0 14.14M15.54 8.46a5 5 0 0 1 0 7.07" />
              </svg>
            </div>
            <span class="broadcast-label">正在播报</span>
          </div>

          <div v-if="broadcastState.title" class="broadcast-title">
            {{ broadcastState.title }}
          </div>

          <div class="broadcast-content">
            {{ broadcastState.content }}
          </div>

          <div class="broadcast-wave">
            <span class="wave-bar"></span>
            <span class="wave-bar"></span>
            <span class="wave-bar"></span>
            <span class="wave-bar"></span>
            <span class="wave-bar"></span>
          </div>
        </div>
      </div>
    </Transition>
  </Teleport>
</template>

<script setup>
import { computed } from 'vue'
import { useScreenStore } from '@/stores/screen'

const screenStore = useScreenStore()

const broadcastState = computed(() => screenStore.broadcastState)

const showBroadcast = computed(() => {
  return broadcastState.value.broadcasting
})
</script>

<style scoped>
.broadcast-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.6);
  z-index: 9998;
  backdrop-filter: blur(4px);
}

.broadcast-card {
  width: 90%;
  max-width: 700px;
  padding: 40px;
  background: var(--bg-card);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-xl);
  animation: scaleIn 0.3s ease-out;
}

.broadcast-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 24px;
}

.broadcast-icon {
  width: 36px;
  height: 36px;
  color: var(--primary);
  animation: pulse 1.5s ease-in-out infinite;
}

.broadcast-icon svg {
  width: 100%;
  height: 100%;
}

.broadcast-label {
  font-size: 18px;
  font-weight: 500;
  color: var(--primary);
  padding: 6px 16px;
  background: var(--primary-soft);
  border-radius: var(--radius-full);
}

.broadcast-title {
  font-size: 28px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 16px;
  text-align: center;
}

.broadcast-content {
  font-size: 24px;
  line-height: 1.8;
  color: var(--text-secondary);
  text-align: center;
  padding: 24px;
  background: var(--bg-page);
  border-radius: var(--radius-lg);
  margin-bottom: 32px;
}

.broadcast-wave {
  display: flex;
  align-items: flex-end;
  justify-content: center;
  gap: 6px;
  height: 40px;
}

.wave-bar {
  width: 6px;
  background: var(--primary);
  border-radius: 3px;
  animation: wave 1s ease-in-out infinite;
}

.wave-bar:nth-child(1) {
  height: 12px;
  animation-delay: 0s;
}

.wave-bar:nth-child(2) {
  height: 24px;
  animation-delay: 0.1s;
}

.wave-bar:nth-child(3) {
  height: 36px;
  animation-delay: 0.2s;
}

.wave-bar:nth-child(4) {
  height: 24px;
  animation-delay: 0.3s;
}

.wave-bar:nth-child(5) {
  height: 12px;
  animation-delay: 0.4s;
}

@keyframes wave {
  0%, 100% {
    transform: scaleY(1);
  }
  50% {
    transform: scaleY(0.5);
  }
}

@keyframes scaleIn {
  from {
    opacity: 0;
    transform: scale(0.9);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

@keyframes pulse {
  0%, 100% {
    opacity: 1;
  }
  50% {
    opacity: 0.6;
  }
}

/* 动画 */
.broadcast-enter-active,
.broadcast-leave-active {
  transition: all 0.3s ease;
}

.broadcast-enter-from,
.broadcast-leave-to {
  opacity: 0;
}

.broadcast-enter-from .broadcast-card,
.broadcast-leave-to .broadcast-card {
  transform: scale(0.9);
}
</style>
