<template>
  <div class="key-vehicle-page">
    <!-- 顶部导航栏 -->
    <div class="nav-bar">
      <van-icon name="arrow-left" class="nav-back" @click="goBack" />
      <div class="nav-title">重点车辆推送</div>
      <div class="nav-placeholder"></div>
    </div>

    <!-- 页面内容 -->
    <div class="page-content">
      <!-- 搜索区域 -->
      <div class="search-card">
        <van-search
          v-model="searchText"
          placeholder="搜索车牌号"
          shape="round"
          background="transparent"
          @search="handleSearch"
        />
      </div>

      <!-- 车辆列表 -->
      <div class="vehicle-list">
        <div
          v-for="vehicle in vehicles"
          :key="vehicle.id"
          class="vehicle-card"
          @click="goToDetail(vehicle)"
        >
          <div class="vehicle-header">
            <div class="vehicle-info">
              <div class="vehicle-avatar">
                <span class="plate-suffix">{{ vehicle.plateNumber.slice(-2) }}</span>
              </div>
              <div class="vehicle-detail">
                <div class="plate-number">{{ vehicle.plateNumber }}</div>
                <div class="violation-type">{{ vehicle.violationType }}</div>
              </div>
            </div>
            <div class="violation-count">
              <div class="count-value">{{ vehicle.violationCount }}</div>
              <div class="count-label">违章次数</div>
            </div>
          </div>
          <div class="vehicle-footer">
            <div class="detection-time">
              <van-icon name="clock-o" />
              <span>{{ vehicle.detectionTime }}</span>
            </div>
            <div class="attention-tag">
              <span class="tag-text">重点关注</span>
              <van-icon name="arrow" />
            </div>
          </div>
        </div>
      </div>
    </div>

    <!-- 底部导航 -->
    <BottomTabs :active-tab="activeTab" />
  </div>
</template>

<script setup>
import { ref } from "vue";
import { useRouter, useRoute } from "vue-router";
import BottomTabs from "@/components/bottomTabs.vue";

const router = useRouter();
const route = useRoute();

// 搜索文本
const searchText = ref("");
const activeTab = ref("home");

// 车辆数据
const vehicles = ref([
  {
    id: 1,
    plateNumber: "鄂A88888",
    violationType: "超速行驶",
    detectionTime: "2026/03/27 14:30",
    violationCount: 5,
    violationTypeKey: "speeding",
    severity: "high",
  },
]);

// 返回上一页
function goBack() {
  router.back();
}

// 搜索
function handleSearch() {
  // 实现搜索逻辑
  console.log("搜索:", searchText.value);
}

// 跳转到详情页
function goToDetail(vehicle) {
  router.push({
    path: "/key-vehicle-detail",
    query: { id: vehicle.id },
  });
}
</script>

<style lang="scss" scoped>
.key-vehicle-page {
  min-height: 100vh;
  background: #f5f5f5;
  padding-bottom: 60px;
}

.nav-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: white;
  border-bottom: 1px solid #e5e5e5;
  position: sticky;
  top: 0;
  z-index: 10;

  .nav-back {
    font-size: 20px;
    color: #333;
    width: 40px;
  }

  .nav-title {
    flex: 1;
    text-align: center;
    font-size: 16px;
    font-weight: 600;
    color: #333;
    padding-right: 40px;
  }

  .nav-placeholder {
    width: 40px;
  }
}

.page-content {
  padding: 16px;
}

.search-card {
  background: white;
  border-radius: 12px;
  margin-bottom: 16px;
  overflow: hidden;

  :deep(.van-search) {
    padding: 8px 0;
  }

  :deep(.van-search__content) {
    background: #f5f5f5;
  }
}

.vehicle-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.vehicle-card {
  background: white;
  border-radius: 12px;
  padding: 16px;
  cursor: pointer;
  transition: box-shadow 0.2s;

  &:active {
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  }
}

.vehicle-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.vehicle-info {
  display: flex;
  align-items: center;
  gap: 12px;
}

.vehicle-avatar {
  width: 48px;
  height: 48px;
  background: #fef2f2;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;

  .plate-suffix {
    font-size: 18px;
    font-weight: 600;
    color: #ef4444;
  }
}

.vehicle-detail {
  .plate-number {
    font-weight: 600;
    color: #333;
    font-size: 15px;
  }

  .violation-type {
    font-size: 13px;
    color: #999;
    margin-top: 4px;
  }
}

.violation-count {
  text-align: right;

  .count-value {
    font-size: 24px;
    font-weight: 700;
    color: #ef4444;
    line-height: 1;
  }

  .count-label {
    font-size: 11px;
    color: #bbb;
    margin-top: 4px;
  }
}

.vehicle-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-top: 12px;
  border-top: 1px solid #f0f0f0;
  font-size: 12px;
  color: #bbb;
}

.detection-time {
  display: flex;
  align-items: center;
  gap: 4px;

  .van-icon {
    font-size: 14px;
  }
}

.attention-tag {
  display: flex;
  align-items: center;
  gap: 2px;

  .tag-text {
    color: #ef4444;
  }

  .van-icon {
    font-size: 14px;
  }
}
</style>
