<template>
  <view class="sub-page">
    <TopBar title="在岗人员" show-back />

    <view class="px-4 pt-3">
      <view v-if="onDutyStaff.length === 0">
        <EmptyState message="暂无在岗人员" />
      </view>

      <view v-else class="glass-card">
        <view
          v-for="person in onDutyStaff"
          :key="person.id"
          class="person-row"
        >
          <view class="flex items-center justify-between">
            <view class="flex items-center flex-1 min-w-0 mr-2">
              <view class="icon-chip mr-3">
                <text class="uni-icons uniui-person-filled chip-glyph"></text>
              </view>
              <view class="min-w-0">
                <text class="row-title truncate">{{ person.name }}</text>
                <text class="row-sub truncate">{{ person.team }} · {{ person.position || '施工员' }}</text>
              </view>
            </view>
            <text class="status-tag flex-shrink-0">{{ getPersonnelStatusText(person.status) }}</text>
          </view>

          <view class="row-divider">
            <view class="meta-line">
              <text class="meta-label">技能等级</text>
              <text class="meta-value">{{ person.skillLevel || '-' }}</text>
            </view>
            <view class="meta-line">
              <text class="meta-label">从业年限</text>
              <text class="meta-value">{{ person.workYears ? `${person.workYears}年` : '-' }}</text>
            </view>
            <view v-if="person.qualifications && person.qualifications.length > 0" class="flex flex-wrap gap-2 mt-2">
              <text
                v-for="qual in person.qualifications"
                :key="qual"
                class="qual-tag"
              >
                {{ qual }}
              </text>
            </view>
          </view>

          <view class="phone-btn mt-3" hover-class="phone-btn-hover" :hover-start-time="0" :hover-stay-time="120" @click="callPhone(person.phone)">
            <text class="uni-icons uniui-phone-filled phone-glyph mr-1"></text>
            <text class="phone-text">电话联系</text>
          </view>
        </view>
      </view>
    </view>
  </view>
</template>

<script setup lang="ts">
import { computed } from 'vue'
import TopBar from '../../components/common/TopBar.vue'
import EmptyState from '../../components/common/EmptyState.vue'
import { usePersonnelStore } from '../../stores/personnel'
import { getPersonnelStatusText } from '../../utils'

const personnelStore = usePersonnelStore()
const onDutyStaff = computed(() => personnelStore.onDutyStaff)

function callPhone(phone: string) {
  if (!phone) return
  uni.makePhoneCall({ phoneNumber: phone })
}
</script>

<style scoped>
.sub-page {
  max-width: 430px;
  margin: 0 auto;
  min-height: 100vh;
  background-color: #f6fbf9;
  padding-bottom: 24px;
}

.glass-card {
  background-color: rgba(255, 255, 255, 0.85);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border: 1px solid rgba(164, 216, 152, 0.35);
  border-radius: 24px;
  box-shadow: 0 18px 50px -12px rgba(54, 143, 111, 0.28);
  overflow: hidden;
  margin-bottom: 12px;
}

.person-row {
  padding: 14px 16px;
  border-top: 1px solid rgba(164, 216, 152, 0.18);
}

.person-row:first-child {
  border-top: none;
}

.icon-chip {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: rgba(164, 216, 152, 0.2);
}

.chip-glyph {
  font-size: 20px;
  color: #368f6f;
}

.row-title {
  display: block;
  font-size: 14px;
  font-weight: 500;
  color: #1f2937;
}

.row-sub {
  display: block;
  margin-top: 3px;
  font-size: 12px;
  color: #9ca3af;
}

.status-tag {
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  color: #368f6f;
  background-color: rgba(164, 216, 152, 0.24);
}

.row-divider {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid rgba(164, 216, 152, 0.18);
}

.meta-line {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
}

.meta-label {
  font-size: 12px;
  color: #9ca3af;
}

.meta-value {
  font-size: 13px;
  color: #4b5563;
}

.qual-tag {
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 11px;
  color: #368f6f;
  background-color: rgba(164, 216, 152, 0.24);
}

.phone-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 9px 0;
  border-radius: 12px;
  background: linear-gradient(135deg, #368f6f 0%, #4ba98a 100%);
}

.phone-btn-hover {
  opacity: 0.88;
}

.phone-glyph {
  font-size: 14px;
  color: #ffffff;
}

.phone-text {
  font-size: 14px;
  font-weight: 600;
  color: #ffffff;
}
</style>
