import { computed, ref } from 'vue'

export default {
  name: 'EmployeeManagementView' ,
  setup(props, { emit }) {
    const tabs = ['全部员工', '在职', '试用中', '停用']
    const filters = ['按部门筛选', '按职级筛选', '按系统角色筛选']
    const activeTab = ref(tabs[0])
    const selectedEmployee = ref(null)

    const roleOptions = [
      { id: 'user', label: '使用者', desc: '可以发起报销、查看个人单据和使用 AI 助手。' },
      { id: 'finance', label: '财务人员', desc: '可以处理复核、查看财务知识与风险校验结果。' },
      { id: 'manager', label: '管理员', desc: '可以维护员工档案、组织结构和角色权限。' },
      { id: 'executive', label: '高级管理人员', desc: '可以查看跨部门数据看板与关键审批结果。' },
      { id: 'approver', label: '审批负责人', desc: '可以处理审批中心中的待审单据。' },
      { id: 'auditor', label: '审计观察员', desc: '可以查看变更记录和权限调整历史。' }
    ]

    const employees = [
      {
        id: 'EMP-001',
        avatar: '张',
        name: '张晓晴',
        employeeNo: 'E10234',
        department: '财务共享中心',
        position: '费用运营经理',
        grade: 'M3',
        manager: '李文静',
        financeOwner: '华东财务组',
        roles: ['管理员', '财务人员', '审批负责人'],
        status: '在职',
        statusTone: 'success',
        gender: '女',
        age: '32',
        birthDate: '1994-08-12',
        email: 'xiaoqing.zhang@xfinance.com',
        phone: '138 1023 4567',
        joinDate: '2021-03-15',
        location: '上海',
        costCenter: 'CC-2108',
        updatedAt: '2026-05-06 10:24',
        lastSync: '2026-05-06 10:24',
        syncState: '待生效',
        spotlight: true,
        permissions: [
          '可查看审批中心全部待审单据',
          '可配置员工角色与部门归属',
          '可查看知识管理与技能中心配置'
        ],
        history: [
          { action: '新增“审批负责人”角色', owner: '系统管理员 · 王敏', time: '今天 10:24' },
          { action: '调整财务归口为华东财务组', owner: '组织管理员 · 陈硕', time: '昨天 18:10' }
        ]
      },
      {
        id: 'EMP-002',
        avatar: '李',
        name: '李文静',
        employeeNo: 'E10018',
        department: '总经办',
        position: '高级财务总监',
        grade: 'D2',
        manager: 'CEO',
        financeOwner: '集团财务',
        roles: ['高级管理人员', '审批负责人'],
        status: '在职',
        statusTone: 'success',
        gender: '女',
        age: '39',
        birthDate: '1987-03-26',
        email: 'wenjing.li@xfinance.com',
        phone: '139 0018 7688',
        joinDate: '2018-06-21',
        location: '上海',
        costCenter: 'CC-1001',
        updatedAt: '2026-05-05 16:20',
        lastSync: '2026-05-05 16:20',
        syncState: '已同步',
        permissions: [
          '可查看集团层面的审批看板',
          '可处理高金额报销的最终审批',
          '可查看部门预算执行情况'
        ],
        history: [
          { action: '更新高级管理人员可见范围', owner: '系统管理员 · 王敏', time: '05-05 16:20' }
        ]
      },
      {
        id: 'EMP-003',
        avatar: '王',
        name: '王敏',
        employeeNo: 'E10867',
        department: '人力与组织',
        position: '组织发展主管',
        grade: 'P6',
        manager: '陈嘉',
        financeOwner: '总部财务',
        roles: ['管理员', '审计观察员'],
        status: '在职',
        statusTone: 'success',
        gender: '女',
        age: '30',
        birthDate: '1996-11-05',
        email: 'min.wang@xfinance.com',
        phone: '136 8867 1200',
        joinDate: '2022-08-08',
        location: '杭州',
        costCenter: 'CC-3206',
        updatedAt: '2026-05-05 09:18',
        lastSync: '2026-05-05 09:18',
        syncState: '已同步',
        permissions: [
          '可维护组织结构与岗位映射',
          '可查看员工角色分配历史'
        ],
        history: [
          { action: '新增“审计观察员”角色', owner: '系统管理员 · 张晓晴', time: '05-05 09:18' }
        ]
      },
      {
        id: 'EMP-004',
        avatar: '陈',
        name: '陈嘉',
        employeeNo: 'E11602',
        department: '销售运营',
        position: '区域销售经理',
        grade: 'M2',
        manager: '李文静',
        financeOwner: '华南财务组',
        roles: ['使用者', '审批负责人'],
        status: '试用中',
        statusTone: 'warning',
        gender: '男',
        age: '29',
        birthDate: '1997-02-18',
        email: 'jia.chen@xfinance.com',
        phone: '137 1602 9901',
        joinDate: '2026-03-01',
        location: '深圳',
        costCenter: 'CC-4102',
        updatedAt: '2026-05-04 14:12',
        lastSync: '2026-05-04 14:12',
        syncState: '已同步',
        permissions: [
          '可发起个人报销与出差申请',
          '可处理本部门基础审批'
        ],
        history: [
          { action: '完成试用期角色初始化', owner: '组织管理员 · 王敏', time: '05-04 14:12' }
        ]
      },
      {
        id: 'EMP-005',
        avatar: '赵',
        name: '赵雨辰',
        employeeNo: 'E11991',
        department: '研发中心',
        position: '产品经理',
        grade: 'P5',
        manager: '陈嘉',
        financeOwner: '总部财务',
        roles: ['使用者'],
        status: '停用',
        statusTone: 'neutral',
        gender: '男',
        age: '27',
        birthDate: '1999-06-09',
        email: 'yuchen.zhao@xfinance.com',
        phone: '135 1991 3300',
        joinDate: '2023-11-18',
        location: '北京',
        costCenter: 'CC-5209',
        updatedAt: '2026-05-01 11:06',
        lastSync: '2026-05-01 11:06',
        syncState: '已同步',
        permissions: [
          '当前账号停用，仅保留历史单据查看记录'
        ],
        history: [
          { action: '账号状态变更为停用', owner: '系统管理员 · 王敏', time: '05-01 11:06' }
        ]
      }
    ]

    const visibleEmployees = computed(() => {
      if (activeTab.value === '全部员工') return employees
      return employees.filter((item) => item.status === activeTab.value)
    })

    return {
      tabs,
      filters,
      activeTab,
      selectedEmployee,
      roleOptions,
      employees,
      visibleEmployees
    }
  }
}

