<template>
  <div class="kole-emp-card">
    <div class="kole-emp-actions">
      <button @click="emit('message', employee)">发消息</button>
      <button @click="emit('view', employee)">详情</button>
      <button @click="emit('edit', employee)">编辑</button>
    </div>

    <div class="kole-emp-top">
      <div class="kole-emp-avatar">
        <img v-if="employee.avatar" :src="employee.avatar" :alt="employee.name">
        <span v-else>{{ initial }}</span>
      </div>
      <div>
        <div class="kole-emp-name">
          {{ employee.name }}
          <span class="kole-emp-status" :class="employee.status">{{ statusText }}</span>
        </div>
        <div class="kole-emp-id">工号：{{ employee.empId }}</div>
      </div>
    </div>

    <div class="kole-emp-meta">
      部门：{{ employee.dept }}<br>职位：{{ employee.position }}
    </div>

    <div v-if="employee.tags && employee.tags.length" class="kole-emp-tags">
      <span v-for="t in employee.tags" :key="t" class="kole-emp-tag">{{ t }}</span>
    </div>

    <div v-if="showContact && (employee.phone || employee.email)" class="kole-emp-contact">
      <div v-if="employee.phone">电话：{{ employee.phone }}</div>
      <div v-if="employee.email">邮箱：{{ employee.email }}</div>
    </div>
  </div>
</template>

<script setup>
import { computed } from 'vue';

const props = defineProps({
  employee: { type: Object, required: true },   // { name, empId, dept, position, status, avatar?, tags?, phone?, email? }
  showContact: { type: Boolean, default: false }
});
const emit = defineEmits(['message', 'view', 'edit']);

const initial = computed(() => (props.employee.name || '?').charAt(0));
const statusText = computed(() => (props.employee.status === 'left' ? '离职' : '在职'));
</script>

<!-- 样式对齐 组件9.txt EmployeeCard 规范 -->
<style scoped>
.kole-emp-card { width: 280px; background: #fff; border-radius: 8px; box-shadow: 0 1px 4px rgba(0,0,0,0.06); padding: 16px; position: relative; box-sizing: border-box; }
.kole-emp-top { display: flex; align-items: center; gap: 12px; }
.kole-emp-avatar { width: 48px; height: 48px; border-radius: 50%; background: #F0F5FF; color: #2F54EB; display: flex; align-items: center; justify-content: center; font-weight: 600; font-size: 18px; flex-shrink: 0; overflow: hidden; }
.kole-emp-avatar img { width: 100%; height: 100%; object-fit: cover; }
.kole-emp-name { font-size: 16px; font-weight: 600; color: #1F2329; display: flex; align-items: center; gap: 8px; }
.kole-emp-status { font-size: 12px; padding: 0 6px; border-radius: 2px; line-height: 18px; }
.kole-emp-status.active { background: #F6FFED; color: #2E7D0A; }
.kole-emp-status.left { background: #F5F5F5; color: #6E6E6E; }
.kole-emp-id { font-size: 12px; color: #6E6E6E; margin-top: 2px; }
.kole-emp-meta { margin-top: 12px; font-size: 13px; color: #595959; line-height: 22px; }
.kole-emp-tags { margin-top: 12px; display: flex; flex-wrap: wrap; gap: 6px; }
.kole-emp-tag { background: #F0F5FF; color: #2F54EB; font-size: 12px; padding: 1px 8px; border-radius: 2px; }
.kole-emp-contact { margin-top: 12px; font-size: 13px; color: #595959; line-height: 22px; border-top: 1px solid #F0F0F0; padding-top: 10px; }
.kole-emp-actions {
  position: absolute; top: 12px; right: 12px; display: none; gap: 4px;
  background: #fff; border: 1px solid #E8ECF1; border-radius: 4px; padding: 2px;
}
.kole-emp-card:hover .kole-emp-actions { display: flex; }
.kole-emp-actions button { border: none; background: none; cursor: pointer; color: #6E6E6E; font-size: 12px; padding: 2px 6px; border-radius: 3px; }
.kole-emp-actions button:hover { color: #2F54EB; background: #F0F5FF; }
</style>
