<script setup lang="ts">
/**
 * 第三方监督人员列表页
 *
 * 展示监督人员列表，支持搜索和状态筛选（全部/在岗/离岗），
 * 点击卡片跳转人员详情。
 * Design: #1E74FF NavBar, #F4F7F8 bg, white cards border-radius 10px.
 */
import { ref, computed } from 'vue'
import { useRouter } from 'vue-router'

const router = useRouter()

/** 搜索关键词 */
const searchText = ref('')

/** 当前激活的 Tab */
const activeTab = ref(0)

/** 模拟监督人员数据 */
const mockSupervisors = [
  { id: 1, name: '张监督', company: '水务监理公司A', status: 'on_duty', phone: '13800001001', project: '城北供水改造工程', rating: 4.8 },
  { id: 2, name: '李监督', company: '市政监理公司B', status: 'off_duty', phone: '13800001002', project: '高新区管网新建', rating: 4.5 },
  { id: 3, name: '王监督', company: '环境监理公司C', status: 'on_duty', phone: '13800001003', project: '老城区雨污分流', rating: 4.9 },
  { id: 4, name: '赵监督', company: '水务监理公司A', status: 'on_duty', phone: '13800001004', project: '东区泵站升级', rating: 4.6 },
  { id: 5, name: '孙监督', company: '市政监理公司B', status: 'off_duty', phone: '13800001005', project: '商业区管道维护', rating: 4.3 },
]

/** 状态映射 */
const statusMap: Record<string, string> = {
  on_duty: '在岗',
  off_duty: '离岗',
}

const statusColorMap: Record<string, 'success' | 'danger'> = {
  on_duty: 'success',
  off_duty: 'danger',
}

/** 筛选后的列表 */
const filteredSupervisors = computed(() => {
  let list = mockSupervisors
  if (searchText.value) {
    const kw = searchText.value.toLowerCase()
    list = list.filter(s =>
      s.name.toLowerCase().includes(kw) ||
      s.company.toLowerCase().includes(kw) ||
      s.project.toLowerCase().includes(kw)
    )
  }
  if (activeTab.value === 1) list = list.filter(s => s.status === 'on_duty')
  else if (activeTab.value === 2) list = list.filter(s => s.status === 'off_duty')
  return list
})

/** 跳转详情 */
function goDetail(id: number) {
  router.push(`/supervisor/detail?id=${id}`)
}
</script>

<template>
  <div class="supervisor-page">
    <!-- NavBar — brand blue -->
    <van-nav-bar
      title="第三方监督人员"
      left-arrow
      fixed
      placeholder
      @click-left="router.back()"
    />

    <!-- Search -->
    <div class="search-wrapper">
      <van-search
        v-model="searchText"
        placeholder="搜索姓名、公司、项目"
        shape="round"
        background="transparent"
      />
    </div>

    <!-- Tabs -->
    <van-tabs
      v-model:active="activeTab"
      sticky
      :duration="0.3"
      swipeable
      color="#1E74FF"
      title-active-color="#1E74FF"
      title-inactive-color="#646566"
      line-width="20"
      line-height="3"
    >
      <van-tab title="全部" />
      <van-tab title="在岗" />
      <van-tab title="离岗" />
    </van-tabs>

    <!-- Supervisor List -->
    <div class="supervisor-list">
      <van-empty
        v-if="filteredSupervisors.length === 0"
        image="search"
        description="暂无监督人员"
      />
      <div
        v-for="item in filteredSupervisors"
        :key="item.id"
        class="supervisor-card"
        @click="goDetail(item.id)"
      >
        <div class="supervisor-card__header">
          <div class="supervisor-card__name-row">
            <h4 class="supervisor-card__name">{{ item.name }}</h4>
            <div class="supervisor-card__rating">
              <van-icon name="star" size="14" color="#FF976A" />
              <span>{{ item.rating }}</span>
            </div>
          </div>
          <van-tag :type="statusColorMap[item.status]" size="medium" round>
            {{ statusMap[item.status] }}
          </van-tag>
        </div>
        <div class="supervisor-card__body">
          <span class="info-item">
            <van-icon name="user-o" size="14" />
            {{ item.company }}
          </span>
          <span class="info-item">
            <van-icon name="phone-o" size="14" />
            {{ item.phone }}
          </span>
        </div>
        <div class="supervisor-card__footer">
          <van-icon name="location-o" size="12" color="#969799" />
          <span class="project-text">{{ item.project }}</span>
        </div>
      </div>
    </div>
  </div>
</template>

<style lang="scss" scoped>
.supervisor-page {
  min-height: 100vh;
  background: #F4F7F8;

  :deep(.van-nav-bar) { background: #1E74FF; }
  :deep(.van-nav-bar__title) { color: #fff; font-size: 18px; font-weight: 600; }
  :deep(.van-nav-bar__text),
  :deep(.van-nav-bar__arrow) { color: #fff; }
  :deep(.van-nav-bar .van-icon) { color: #fff; }
}

.search-wrapper {
  padding: 8px 12px 0;
  background: #F4F7F8;

  :deep(.van-search__content) {
    border-radius: 10px;
    background: #fff;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
  }
}

:deep(.van-tabs) { background: #fff; }
:deep(.van-tabs__wrap) { padding: 0 8px; }
:deep(.van-tab) { font-size: 14px; }

.supervisor-list {
  padding: 8px 12px 16px;
}

.supervisor-card {
  background: #fff;
  border-radius: 10px;
  padding: 14px 16px;
  margin-bottom: 10px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
  cursor: pointer;
  transition: box-shadow 0.15s ease;

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

.supervisor-card__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.supervisor-card__name-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
  min-width: 0;
}

.supervisor-card__name {
  font-size: 16px;
  font-weight: 600;
  color: var(--color-text-primary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.supervisor-card__rating {
  display: flex;
  align-items: center;
  gap: 2px;
  font-size: 13px;
  font-weight: 500;
  color: #FF976A;
  flex-shrink: 0;
}

.supervisor-card__body {
  display: flex;
  gap: 16px;
  margin-bottom: 8px;
  font-size: 13px;
  color: var(--color-text-regular);
}

.info-item {
  display: flex;
  align-items: center;
  gap: 4px;
}

.supervisor-card__footer {
  display: flex;
  align-items: center;
  gap: 4px;
  padding-top: 8px;
  border-top: 1px solid var(--color-border-light);
}

.project-text {
  font-size: 12px;
  color: var(--color-text-placeholder);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
</style>
