<template>
  <view class="sub-page">
    <TopBar title="应急待命" show-back />

    <view class="px-4 pt-3">
      <!-- 应急热线 -->
      <view class="hotline-card">
        <view class="flex items-center flex-1 min-w-0">
          <view class="hotline-icon mr-3">
            <text class="uni-icons uniui-phone-filled hotline-glyph"></text>
          </view>
          <view class="min-w-0">
            <text class="hotline-label">应急热线</text>
            <text class="hotline-number">400-119-1100</text>
          </view>
        </view>
        <view class="hotline-btn" hover-class="hotline-btn-hover" :hover-start-time="0" :hover-stay-time="120" @click="callPhone('400-119-1100')">
          拨打
        </view>
      </view>

      <!-- 待命说明 -->
      <view class="notice-banner">
        <text class="uni-icons uniui-notification notice-icon mr-2"></text>
        <text class="notice-text">应急待命人员保持通讯畅通，随时准备响应紧急任务</text>
      </view>

      <view v-if="emergencyTeam.length === 0">
        <EmptyState message="暂无应急待命人员" />
      </view>

      <view v-else class="glass-card">
        <view
          v-for="person in emergencyTeam"
          :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 icon-chip-red mr-3">
                <text class="uni-icons uniui-person-filled chip-glyph-red"></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 v-if="person.qualifications && person.qualifications.length > 0" class="flex flex-wrap gap-2 mb-3">
              <text
                v-for="qual in person.qualifications"
                :key="qual"
                class="qual-tag"
              >
                {{ qual }}
              </text>
            </view>

            <view class="phone-btn" 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>
  </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 emergencyTeam = computed(() => personnelStore.emergencyTeam)

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;
}

.hotline-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px;
  margin-bottom: 12px;
  border-radius: 24px;
  background-color: rgba(239, 68, 68, 0.06);
  border: 1px solid rgba(239, 68, 68, 0.2);
}

.hotline-icon {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #ef4444 0%, #f87171 100%);
}

.hotline-glyph {
  font-size: 22px;
  color: #ffffff;
}

.hotline-label {
  display: block;
  font-size: 13px;
  color: #ef4444;
}

.hotline-number {
  display: block;
  font-size: 20px;
  font-weight: 800;
  color: #1f2937;
}

.hotline-btn {
  padding: 8px 20px;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 600;
  color: #ffffff;
  background: linear-gradient(135deg, #ef4444 0%, #f87171 100%);
}

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

.notice-banner {
  display: flex;
  align-items: center;
  padding: 10px 12px;
  margin-bottom: 12px;
  border-radius: 12px;
  background-color: rgba(239, 68, 68, 0.08);
}

.notice-icon {
  font-size: 16px;
  color: #ef4444;
}

.notice-text {
  font-size: 13px;
  color: #dc2626;
}

.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: 12px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: rgba(164, 216, 152, 0.2);
}

.icon-chip-red {
  border-radius: 50%;
  background-color: rgba(239, 68, 68, 0.1);
}

.chip-glyph-red {
  font-size: 20px;
  color: #ef4444;
}

.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: #ef4444;
  background-color: rgba(239, 68, 68, 0.1);
}

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

.qual-tag {
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 11px;
  color: #ef4444;
  background-color: rgba(239, 68, 68, 0.08);
}

.phone-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 9px 0;
  border-radius: 12px;
  background: linear-gradient(135deg, #ef4444 0%, #f87171 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>
