<template>
  <div class="welcome-page w-full">
    <!-- 粒子背景 -->
    <canvas ref="particleCanvas" class="particle-canvas"></canvas>

    <!-- 欢迎文字 -->
    <div class="welcome-content">
      <h1 class="welcome-title">欢迎访问格莱默标签打印平台！</h1>
    </div>
  </div>
</template>
<script lang="ts" setup>
import { ref, onMounted, onUnmounted } from 'vue'

defineOptions({ name: 'WelcomePage' })

// 粒子画布引用
const particleCanvas = ref<HTMLCanvasElement | null>(null)
let animationFrameId: number | null = null

// 粒子配置
interface Particle {
  x: number
  y: number
  size: number
  speedX: number
  speedY: number
  color: string
}

const particles: Particle[] = []
const particleCount = 100
const elementBlue = '#409EFF' // Element Plus主题蓝色

// 初始化粒子
const initParticles = () => {
  if (!particleCanvas.value) return

  const canvas = particleCanvas.value
  const ctx = canvas.getContext('2d')
  if (!ctx) return

  // 设置画布尺寸
  canvas.width = window.innerWidth
  canvas.height = window.innerHeight

  // 清空现有粒子
  particles.length = 0

  // 创建新粒子
  for (let i = 0; i < particleCount; i++) {
    particles.push({
      x: Math.random() * canvas.width,
      y: Math.random() * canvas.height,
      size: Math.random() * 3 + 1,
      speedX: (Math.random() - 0.5) * 0.5,
      speedY: (Math.random() - 0.5) * 0.5,
      color: elementBlue
    })
  }
}

// 绘制粒子
const drawParticles = () => {
  if (!particleCanvas.value) return

  const canvas = particleCanvas.value
  const ctx = canvas.getContext('2d')
  if (!ctx) return

  // 清空画布
  ctx.clearRect(0, 0, canvas.width, canvas.height)

  // 绘制粒子
  particles.forEach((particle) => {
    ctx.fillStyle = particle.color
    ctx.globalAlpha = 0.6
    ctx.beginPath()
    ctx.arc(particle.x, particle.y, particle.size, 0, Math.PI * 2)
    ctx.fill()

    // 更新粒子位置
    particle.x += particle.speedX
    particle.y += particle.speedY

    // 边界检测
    if (particle.x < 0 || particle.x > canvas.width) {
      particle.speedX *= -1
    }
    if (particle.y < 0 || particle.y > canvas.height) {
      particle.speedY *= -1
    }
  })

  // 绘制粒子连线
  particles.forEach((particle, index) => {
    for (let i = index + 1; i < particles.length; i++) {
      const otherParticle = particles[i]
      const distance = Math.sqrt(
        Math.pow(particle.x - otherParticle.x, 2) + Math.pow(particle.y - otherParticle.y, 2)
      )

      if (distance < 100) {
        ctx.beginPath()
        ctx.strokeStyle = elementBlue
        ctx.globalAlpha = 0.2
        ctx.lineWidth = 0.5
        ctx.moveTo(particle.x, particle.y)
        ctx.lineTo(otherParticle.x, otherParticle.y)
        ctx.stroke()
      }
    }
  })
}

// 动画循环
const animate = () => {
  drawParticles()
  animationFrameId = requestAnimationFrame(animate)
}

// 窗口大小变化处理
const handleResize = () => {
  initParticles()
}

// 初始化
onMounted(() => {
  initParticles()
  animate()

  // 监听窗口大小变化
  window.addEventListener('resize', handleResize)
})

// 清理
onUnmounted(() => {
  if (animationFrameId) {
    cancelAnimationFrame(animationFrameId)
  }
  window.removeEventListener('resize', handleResize)
})
</script>

<style scoped>
.welcome-page {
  position: relative;
  overflow: hidden;
  height: calc(100vh - var(--top-tool-height) - var(--tags-view-height) - var(--app-footer-height));
}

.particle-canvas {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 1;
}

.welcome-content {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 2;
  text-align: center;
}

.welcome-title {
  font-size: 36px;
  font-weight: 700;
  color: #333;
  margin: 0;
  text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.1);
  animation: fadeInUp 1s ease-out;
}

@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(30px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.weather-icon {
  margin-right: 8px;
  color: #e6a23c;
}

.calendar-card {
  margin-bottom: 16px;
  overflow-y: auto;
}

.quick-actions-card {
  margin-bottom: 16px;
}

.quick-action-card {
  cursor: pointer;
  transition: all 0.3s ease;
}

.quick-action-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.quick-action-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 20px;
}

.card-title {
  font-size: 16px;
  font-weight: 600;
  color: #303133;
}

.custom-calendar {
  width: 100%;
  height: 390px;
}

.weather-card {
  background: linear-gradient(180deg, #fff 0%, #fff 10%, #fff 50%);
  color: #303133;
}

.weather-card .card-title {
  color: #303133;
}

.weather-content {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 20px;
  padding: 20px 0;
  min-height: 297px;
}

.weather-icon {
  color: var(--el-color-primary);
}

.weather-info {
  text-align: center;
}

.weather-temp {
  font-size: 32px;
  font-weight: 600;
  margin-bottom: 8px;
}

.weather-desc {
  font-size: 16px;
  opacity: 0.9;
}

.weather-details {
  display: flex;
  justify-content: space-around;
  padding: 20px 0;
  border-top: 1px solid #eee;
}

.detail-item {
  text-align: center;
}

.detail-label {
  font-size: 14px;
  opacity: 0.9;
  margin-bottom: 4px;
}

.detail-value {
  font-size: 18px;
  font-weight: 600;
}
.home-bg {
  width: 100%;
  border-radius: 12px;
  filter: blur(5px);
  -webkit-filter: blur(5px);
  position: relative;
}

.home-bg::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(255, 255, 255, 0.3);
  border-radius: 12px;
  pointer-events: none;
}
</style>
