<template>
  <div class="tab-bar">
    <div class="tab-bar-content">
      <div
        class="tab-item"
        v-for="tab in tabs"
        :key="tab.path"
        @click="switchTab(tab.path)"
        :class="{ active: currentPath === tab.path }"
      >
        <div class="tab-icon-wrapper">
          <div class="tab-icon" :class="getIconClass(tab)">
            <i :class="tab.iconClass"></i>
          </div>
          <div class="active-indicator" v-if="currentPath === tab.path"></div>
        </div>
        <span class="tab-title">{{ tab.title }}</span>
      </div>
    </div>
    
    <!-- 背景装饰 -->
    <div class="tab-background"></div>
  </div>
</template>

<script>
export default {
  name: 'TabBar',
  data() {
    return {
      currentPath: '/home',
      tabs: [
        {
          path: '/home',
          title: '首页',
          iconClass: 'icon-home',
          color: '#667eea'
        },
        {
          path: '/mall',
          title: '退休计划',
          iconClass: 'icon-plan',
          color: '#51cf66'
        },
        {
          path: '/Medical',
          title: '红旗基金',
          iconClass: 'icon-fund',
          color: '#ff6b6b'
        },
        {
          path: '/profile',
          title: '我的',
          iconClass: 'icon-profile',
          color: '#ffd43b'
        }
      ]
    }
  },
  methods: {
    switchTab(path) {
      this.currentPath = path
      this.$router.push(path)
    },
    getIconClass(tab) {
      return {
        'active': this.currentPath === tab.path,
        [tab.iconClass]: true
      }
    }
  },
  created() {
    this.currentPath = this.$route.path
  },
  watch: {
    '$route'(to) {
      this.currentPath = to.path
    }
  }
}
</script>

<style lang="scss" scoped>
.tab-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: 75px;
  z-index: 999;
  padding: 0 15px 15px;
  box-sizing: border-box;
}

.tab-background {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: linear-gradient(145deg, #ffffff, #f8f9fa);
  border-radius: 25px 25px 0 0;
  box-shadow: 
    0 -12px 35px rgba(0, 0, 0, 0.15),
    0 -6px 18px rgba(0, 0, 0, 0.1),
    inset 0 1px 0 rgba(255, 255, 255, 0.8);
  backdrop-filter: blur(15px);
  
  // 顶部高光效果
  &::before {
    content: '';
    position: absolute;
    top: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 80px;
    height: 4px;
    background: linear-gradient(90deg, transparent, rgba(102, 126, 234, 0.4), transparent);
    border-radius: 0 0 25px 25px;
  }
}

.tab-bar-content {
  position: relative;
  z-index: 2;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: space-around;
  padding: 12px 0;
}

.tab-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  padding: 10px 8px;
  border-radius: 16px;
  position: relative;
  
  &:hover {
    background: rgba(102, 126, 234, 0.06);
    transform: translateY(-3px);
  }
  
  &.active {
    .tab-title {
      color: #667eea;
      font-weight: 700;
      text-shadow: 0 1px 3px rgba(102, 126, 234, 0.2);
      transform: scale(1.05);
    }
  }
}

.tab-icon-wrapper {
  position: relative;
  margin-bottom: 6px;
  transition: all 0.3s ease;
}

.tab-icon {
  width: 32px;
  height: 32px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.3s ease;
  background: linear-gradient(145deg, #f8f9fa, #e9ecef);
  box-shadow: 
    0 4px 8px rgba(0, 0, 0, 0.1),
    inset 0 1px 0 rgba(255, 255, 255, 0.5);
  
  i {
    font-style: normal;
    font-size: 18px;
    font-weight: bold;
    color: #666;
    transition: all 0.3s ease;
  }
  
  &.active {
    background: linear-gradient(145deg, #667eea, #764ba2);
    box-shadow: 
      0 6px 16px rgba(102, 126, 234, 0.3),
      inset 0 1px 0 rgba(255, 255, 255, 0.2);
    transform: scale(1.1);
    
    i {
      color: white;
      text-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
    }
  }
}

.active-indicator {
  position: absolute;
  top: -4px;
  left: 50%;
  transform: translateX(-50%);
  width: 8px;
  height: 8px;
  background: linear-gradient(145deg, #667eea, #764ba2);
  border-radius: 50%;
  box-shadow: 
    0 3px 8px rgba(102, 126, 234, 0.4),
    0 0 0 3px rgba(255, 255, 255, 0.9);
  animation: pulse 2s infinite;
}

.tab-title {
  font-size: 12px;
  color: #666;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  font-weight: 600;
  line-height: 1.2;
  text-align: center;
  letter-spacing: 0.5px;
}

// 脉搏动画
@keyframes pulse {
  0% {
    transform: translateX(-50%) scale(1);
    opacity: 1;
  }
  50% {
    transform: translateX(-50%) scale(1.3);
    opacity: 0.7;
  }
  100% {
    transform: translateX(-50%) scale(1);
    opacity: 1;
  }
}

// 首页图标
.icon-home {
  i::before {
    content: '🏠';
  }
  
  &.active {
    background: linear-gradient(145deg, #667eea, #764ba2);
  }
}

// 退休计划图标
.icon-plan {
  i::before {
    content: '📊';
  }
  
  &.active {
    background: linear-gradient(145deg, #51cf66, #40c057);
  }
}

// 红旗基金图标
.icon-fund {
  i::before {
    content: '💰';
  }
  
  &.active {
    background: linear-gradient(145deg, #ff6b6b, #e74c3c);
  }
}

// 我的图标
.icon-profile {
  i::before {
    content: '👤';
  }
  
  &.active {
    background: linear-gradient(145deg, #ffd43b, #fab005);
  }
}

// 点击反馈动画
.tab-item:active {
  transform: translateY(-1px) scale(0.98);
  
  .tab-icon {
    transform: scale(0.95);
  }
}

// 为不同标签页的激活指示器添加特殊颜色
.tab-item:nth-child(1).active {
  .active-indicator {
    background: linear-gradient(145deg, #667eea, #764ba2);
  }
}

.tab-item:nth-child(2).active {
  .active-indicator {
    background: linear-gradient(145deg, #51cf66, #40c057);
  }
}

.tab-item:nth-child(3).active {
  .active-indicator {
    background: linear-gradient(145deg, #ff6b6b, #e74c3c);
  }
}

.tab-item:nth-child(4).active {
  .active-indicator {
    background: linear-gradient(145deg, #ffd43b, #fab005);
  }
}

// 响应式设计
@media (max-width: 375px) {
  .tab-bar {
    height: 68px;
    padding: 0 10px 10px;
  }
  
  .tab-icon {
    width: 28px;
    height: 28px;
    border-radius: 10px;
    
    i {
      font-size: 16px;
    }
  }
  
  .tab-title {
    font-size: 11px;
  }
  
  .active-indicator {
    width: 6px;
    height: 6px;
  }
}

@media (min-width: 414px) {
  .tab-bar {
    height: 80px;
    padding: 0 20px 20px;
  }
  
  .tab-icon {
    width: 36px;
    height: 36px;
    border-radius: 14px;
    
    i {
      font-size: 20px;
    }
  }
  
  .tab-title {
    font-size: 13px;
  }
  
  .active-indicator {
    width: 10px;
    height: 10px;
  }
}

// 添加微妙的进入动画
.tab-item {
  animation: slideUp 0.5s ease-out;
}

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

// 为每个标签项添加延迟动画
.tab-item:nth-child(1) { animation-delay: 0.1s; }
.tab-item:nth-child(2) { animation-delay: 0.2s; }
.tab-item:nth-child(3) { animation-delay: 0.3s; }
.tab-item:nth-child(4) { animation-delay: 0.4s; }
</style> 