<template>
  <Teleport to="body">
    <div v-if="show" class="broadcast-bar" @click.stop>
      <!-- 左侧状态标签 -->
      <div class="bar-status">
        <span class="voice-dot"></span>
        <span>正在播报</span>
      </div>

      <!-- 中间内容区 -->
      <div class="bar-content">
        <div class="bar-title">{{ displayTitle }}</div>
        <div class="bar-text">{{ broadcast?.content }}</div>
      </div>

      <!-- 右侧音频波纹（播放中时动画） -->
      <div class="bar-wave">
        <span></span>
        <span></span>
        <span></span>
      </div>
    </div>
  </Teleport>
</template>

<script setup>
import { computed } from 'vue'

const props = defineProps({
  broadcast: {
    type: Object,
    default: () => ({})
  }
})

// 是否显示播报条
const show = computed(() => {
  return !!(
    props.broadcast &&
    props.broadcast.broadcasting === true &&
    !!props.broadcast.audioUrl
  )
})

// 显示标题
const displayTitle = computed(() => {
  return props.broadcast?.title || '通知播报'
})
</script>

<style scoped>
.broadcast-bar {
  position: fixed;
  left: 50%;
  bottom: 128px;
  transform: translateX(-50%);
  z-index: 1000;
  width: min(780px, calc(100vw - 120px));
  min-height: 86px;
  padding: 14px 22px;
  border-radius: 26px;
  background: rgba(15, 23, 42, 0.72);
  border: 1px solid rgba(255, 255, 255, 0.18);
  box-shadow: 0 14px 44px rgba(0, 0, 0, 0.28);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  display: flex;
  align-items: center;
  gap: 20px;
}

/* 左侧状态标签 */
.bar-status {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 14px;
  border-radius: 999px;
  background: rgba(47, 142, 229, 0.82);
  color: #fff;
  font-size: 17px;
  font-weight: 800;
  white-space: nowrap;
}

.voice-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 0 12px rgba(255, 255, 255, 0.8);
  animation: voicePulse 1.4s ease-in-out infinite;
}

/* 中间内容区 */
.bar-content {
  flex: 1;
  min-width: 0;
}

.bar-title {
  font-size: 24px;
  font-weight: 900;
  color: rgba(255, 255, 255, 0.96);
  line-height: 1.2;
  margin-bottom: 5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.bar-text {
  font-size: 19px;
  font-weight: 500;
  color: rgba(255, 255, 255, 0.78);
  line-height: 1.35;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* 右侧音频波纹 */
.bar-wave {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 5px;
  width: 36px;
  height: 30px;
  opacity: 0.8;
}

.bar-wave span {
  width: 5px;
  height: 14px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.9);
  animation: waveMove 1s ease-in-out infinite;
}

.bar-wave span:nth-child(2) {
  animation-delay: 0.15s;
}

.bar-wave span:nth-child(3) {
  animation-delay: 0.3s;
}

@keyframes voicePulse {
  0%, 100% {
    opacity: 1;
    transform: scale(1);
  }
  50% {
    opacity: 0.55;
    transform: scale(0.78);
  }
}

@keyframes waveMove {
  0%, 100% {
    height: 12px;
    opacity: 0.55;
  }
  50% {
    height: 30px;
    opacity: 1;
  }
}

/* 响应式适配 */
@media (max-width: 980px), (max-height: 720px) {
  .broadcast-bar {
    bottom: 122px;
    width: min(740px, calc(100vw - 100px));
    min-height: 82px;
    padding: 13px 20px;
    border-radius: 24px;
  }

  .bar-status {
    font-size: 16px;
    padding: 7px 13px;
  }

  .bar-title {
    font-size: 23px;
  }

  .bar-text {
    font-size: 18px;
  }
}
</style>
