<template>
  <header>
    <div class="header-inner">
      <div class="header-left">
        <div class="time">{{ timeStr }}</div>
        <div class="date">{{ dateStr }}</div>
      </div>
      <div class="header-center">
        <div class="title-wrap">
          <svg class="title-frame" viewBox="0 0 1200 120" preserveAspectRatio="none" aria-hidden="true">
            <defs>
              <linearGradient id="frameStroke" x1="0" y1="0" x2="1" y2="0">
                <stop offset="0" stop-color="rgba(34,211,238,0.0)" />
                <stop offset="0.18" stop-color="rgba(34,211,238,0.85)" />
                <stop offset="0.5" stop-color="rgba(96,165,250,0.95)" />
                <stop offset="0.82" stop-color="rgba(34,211,238,0.85)" />
                <stop offset="1" stop-color="rgba(34,211,238,0.0)" />
              </linearGradient>
              <linearGradient id="frameFill" x1="0" y1="0" x2="0" y2="1">
                <stop offset="0" stop-color="rgba(30,144,255,0.20)" />
                <stop offset="1" stop-color="rgba(2,6,23,0.0)" />
              </linearGradient>
              <filter id="frameGlow" x="-30%" y="-60%" width="160%" height="220%">
                <feGaussianBlur stdDeviation="3.2" result="blur" />
                <feColorMatrix
                  in="blur"
                  type="matrix"
                  values="1 0 0 0 0  0 1 0 0 0  0 0 1 0 0  0 0 0 1 0"
                  result="colored"
                />
                <feMerge>
                  <feMergeNode in="colored" />
                  <feMergeNode in="SourceGraphic" />
                </feMerge>
              </filter>
            </defs>
            <path d="M10 5 L150 115 L1050 115 L1190 5 Z" fill="url(#frameFill)" />
            <path
              d="M10 5 L150 115 L1050 115 L1190 5"
              stroke="url(#frameStroke)"
              stroke-width="4"
              fill="none"
              filter="url(#frameGlow)"
            />
          </svg>
          <div class="title">产线运行看板</div>
        </div>
      </div>
      <div class="header-right">
        <!-- <div class="back-btn" @click="goBack">
          <Icon icon="ep:back" />
          <span>返回</span>
        </div> -->
        <div class="weather">
          <Icon icon="fa-solid:cloud-sun" class="weather-icon" />
          <div class="weather-meta">
            <div class="temp">{{ weather.temp }}</div>
            <div class="desc">{{ weather.desc }}</div>
          </div>
        </div>
      </div>
    </div>
  </header>
</template>

<script setup lang="ts">
import { ref, onMounted, onUnmounted } from 'vue'
import { useRouter } from 'vue-router'

const router = useRouter()
const timeStr = ref('')
const dateStr = ref('')
const weather = ref({ temp: '27°C', desc: 'Cloudy to clear' })
let timer: number | undefined

const goBack = () => {
  router.back()
}

const updateTime = () => {
  const d = new Date()
  const h = String(d.getHours()).padStart(2, '0')
  const mi = String(d.getMinutes()).padStart(2, '0')
  const s = String(d.getSeconds()).padStart(2, '0')
  timeStr.value = `${h}:${mi}:${s}`

  const y = d.getFullYear()
  const m = String(d.getMonth() + 1).padStart(2, '0')
  const day = String(d.getDate()).padStart(2, '0')
  const weekMap = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday']
  dateStr.value = `${weekMap[d.getDay()]}, ${y}-${m}-${day}`
}

onMounted(() => {
  updateTime()
  timer = window.setInterval(updateTime, 1000)
})

onUnmounted(() => {
  if (timer) clearInterval(timer)
})
</script>

<style scoped>
header {
  position: relative;
  z-index: 2;
  display: flex;
  height: var(--header-h);
  padding: 0 18px;
  background:
    linear-gradient(to bottom, rgb(15 23 42 / 95%), rgb(15 23 42 / 85%)),
    radial-gradient(circle at 50% 0, rgb(56 189 248 / 22%), transparent 60%);
  border-bottom: 1px solid rgb(148 163 184 / 35%);
  box-shadow: 0 10px 35px rgb(15 23 42 / 90%);
  align-items: center;
}

.header-inner {
  display: grid;
  width: 100%;
  grid-template-columns: 320px 1fr 320px;
  align-items: center;
  gap: 12px;
}

.header-left {
  justify-self: start;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.time {
  font-size: 22px;
  font-weight: 800;
  letter-spacing: 1px;
  color: #e0f2fe;
}

.date {
  font-size: 12px;
  color: var(--muted);
}

.header-center {
  justify-self: center;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
}

.title-wrap {
  position: relative;
  display: flex;
  width: min(980px, 100%);
  height: 64px;
  align-items: center;
  justify-content: center;
}

.title-frame {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  opacity: 0.95;
}

.title {
  position: relative;
  z-index: 1;
  font-size: 28px;
  font-weight: 900;
  letter-spacing: 3px;
  text-shadow: 0 0 20px rgb(56 189 248 / 65%);
  background: linear-gradient(to bottom, #e0f2fe, #60a5fa);
  background-clip: text;
  -webkit-text-fill-color: transparent;
}

.header-right {
  justify-self: end;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 20px;
}

.back-btn {
  display: flex;
  padding: 6px 16px;
  font-size: 14px;
  color: #e0f2fe;
  cursor: pointer;
  background: rgb(30 64 175 / 30%);
  border: 1px solid rgb(56 189 248 / 30%);
  border-radius: 4px;
  transition: all 0.3s;
  align-items: center;
  gap: 6px;
}

.back-btn:hover {
  background: rgb(30 64 175 / 60%);
  border-color: rgb(56 189 248 / 80%);
  box-shadow: 0 0 10px rgb(56 189 248 / 40%);
}

.weather {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--muted);
}

.weather-icon {
  font-size: 28px;
  color: var(--accent);
}

.weather-meta {
  display: flex;
  flex-direction: column;
  line-height: 1.2;
}

.temp {
  font-size: 16px;
  font-weight: 700;
  color: #e0f2fe;
}

.desc {
  font-size: 12px;
  color: var(--muted);
}

@media (width <= 1600px) {
  .title {
    font-size: 24px;
  }

  .title-wrap {
    height: 58px;
  }

  .header-inner {
    grid-template-columns: 280px 1fr 280px;
  }
}

@media (width <= 1366px) {
  .title {
    font-size: 20px;
    letter-spacing: 3px;
  }

  .title-wrap {
    height: 54px;
  }

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