<template>
  <div class="screen-header">
    <!-- Left: Clock -->
    <div class="nav-left">
      <div class="nav-clock">
        <div class="time">{{ currentTime }}</div>
        <div class="date">{{ currentDate }}</div>
      </div>
    </div>

    <!-- Center: Logo + Org + Divider + Title -->
    <div class="nav-center">
      <div class="nav-logo">
        <div class="nav-logo-ring"></div>
      </div>
      <div class="nav-org">
        <strong>中国安全生产科学研究院</strong>
        <span>National Institute for Occupational Safety</span>
      </div>
      <div class="nav-divider"></div>
      <div class="nav-title-wrap">
        <div class="nav-title">实验室安全智能监测与管控中心</div>
        <div class="nav-title-deco"></div>
      </div>
    </div>

    <!-- Right: Weather -->
    <div class="nav-right">
      <div class="nav-weather">
        <!--<span class="icon">&#9925;</span>-->
        <div>
          <div class="weather-location">{{weather}}</div>
          <div class="weather-detail">{{weatherA}}{{weatherB}}</div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
  import { getWeather } from '@/api/screen'
export default {
  name: 'ScreenHeader',
  data() {
    return {
      currentTime: '',
      currentDate: '',
      timer: null,
      weather:'',
      weatherA:'',
      weatherB:'',
    }
  },
  mounted() {
    this.updateTime()
    this.timer = setInterval(this.updateTime, 1000)
    this.fetchWeather()
  },
  beforeDestroy() {
    if (this.timer) {
      clearInterval(this.timer)
      this.timer = null
    }
  },
  methods: {
    updateTime() {
      const now = new Date()
      const h = String(now.getHours()).padStart(2, '0')
      const m = String(now.getMinutes()).padStart(2, '0')
      const s = String(now.getSeconds()).padStart(2, '0')
      this.currentTime = `${h}:${m}:${s}`

      const y = now.getFullYear()
      const mon = now.getMonth() + 1
      const d = now.getDate()
      const weekDays = ['日', '一', '二', '三', '四', '五', '六']
      this.currentDate = `${y}年${mon}月${d}日 星期${weekDays[now.getDay()]}`
    },
    async fetchWeather() {
      try {
        const res = await getWeather()
        const d = res.data
        this.weather = ` 北京 · ${d.weekDay} `;
        this.weatherA = ` ${d.weatherDesc} `;
        this.weatherB = ` ${d.temperature}°C`;
      } catch (e) {
        this.weather = ''
      }
    }
  }
}
</script>

<style lang="scss" scoped>
@import '../styles/variables.scss';

/* ========== ringPulse: logo outer ring breathing animation ========== */
@keyframes ringPulse {
  0%, 100% {
    transform: scale(1);
    opacity: 0.5;
  }
  50% {
    transform: scale(1.1);
    opacity: 1;
  }
}

/* ========== titleShine: title gradient scroll animation ========== */
@keyframes titleShine {
  from {
    background-position: 0% center;
  }
  to {
    background-position: 200% center;
  }
}

/* ========== decoGlow: decorative line glow animation ========== */
@keyframes decoGlow {
  0%, 100% {
    opacity: 0.5;
  }
  50% {
    opacity: 1;
    filter: blur(1px);
  }
}

/* ========== TOP NAV ========== */
.screen-header {
  position: relative;
  z-index: 1;
  flex-shrink: 0;
  width: 100%;
  height: 160px;
  display: flex;
  align-items: stretch;
  background: linear-gradient(180deg, rgba(4, 18, 52, 0.99) 0%, rgba(3, 12, 36, 0.97) 100%);
  border-bottom: 1px solid rgba(30, 144, 255, 0.3);
  box-shadow: 0 2px 30px rgba(0, 80, 220, 0.28), inset 0 1px 0 rgba(30, 144, 255, 0.15);
  font-family: $font-main;
}

/* ========== LEFT: Clock ========== */
.nav-left {
  display: flex;
  align-items: center;
  padding: 0 50px;
  width: 950px;
  gap: 30px;
}

.nav-clock {
  .time {
    font-size: 55px;
    font-weight: 300;
    color: $gold;
    font-variant-numeric: tabular-nums;
    letter-spacing: 4px;
    line-height: 1;
  }

  .date {
    font-size: 30px;
    color: $text-dim;
    margin-top: 5px;
  }
}

/* ========== CENTER: Logo + Org + Divider + Title ========== */
.nav-center {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 30px;
  position: relative;
}

.nav-logo {
  width: 100px;
  height: 100px;
  border-radius: 20px;
  flex-shrink: 0;
  background: linear-gradient(135deg, #0d2d6b, #1565c0);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 0 40px rgba(30, 144, 255, 0.6), inset 0 0 20px rgba(255, 255, 255, 0.1);
  position: relative;
  overflow: visible;

  &::after {
    content: '安';
    font-size: 45px;
    font-weight: 900;
    color: rgba(255, 255, 255, 0.95);
  }
}

.nav-logo-ring {
  position: absolute;
  inset: -10px;
  border-radius: 25px;
  border: 2px solid rgba(30, 144, 255, 0.5);
  animation: ringPulse 2s ease-in-out infinite;
}

.nav-org {
  font-size: 30px;
  color: $text-dim;
  line-height: 1.4;
  margin-right: 50px;

  strong {
    display: block;
    font-size: 32px;
    color: $cyan;
  }
}

.nav-divider {
  width: 2px;
  height: 80px;
  background: linear-gradient(180deg, transparent, rgba(30, 144, 255, 0.6), transparent);
  flex-shrink: 0;
  margin-right: 50px;
}

.nav-title-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  position: relative;
}

.nav-title {
  font-size: 65px;
  font-weight: 700;
  letter-spacing: 10px;
  background: linear-gradient(90deg, $blue, $cyan, $white, $cyan, $blue);
  background-size: 200% auto;
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  animation: titleShine 4s linear infinite;
  filter: drop-shadow(0 0 40px rgba(30, 144, 255, 0.5));
  white-space: nowrap;
}

.nav-title-deco {
  position: absolute;
  bottom: -5px;
  left: 50%;
  transform: translateX(-50%);
  width: 900px;
  height: 2px;
  background: linear-gradient(90deg, transparent, $blue, $cyan, $blue, transparent);
  animation: decoGlow 3s ease-in-out infinite;
}

/* ========== RIGHT: Weather ========== */
.nav-right {
  width: 950px;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding: 0 50px;
  gap: 50px;
}

.nav-weather {
  display: flex;
  align-items: center;
  gap: 20px;
  font-size: 32px;
  color: $text-dim;

  .icon {
    font-size: 45px;
  }

  .weather-location {
    color: $text-dim;
  }

  .weather-detail {
    font-size: 28px;
    color: $gold;
    margin-top: 4px;
  }
}
</style>
