// Mock 数据 - 迎宾机器人屏幕端
// 后续可替换为真实接口

// 延迟模拟
const delay = (ms = 300) => new Promise(resolve => setTimeout(resolve, ms))

// ============================================
// 1. 机器人状态
// ============================================
export const mockRobotStatus = {
  batteryLevel: 85,
  networkStatus: 'online',
  workStatus: 'idle',
  chargeStatus: 'not_charging',
  faultFlag: false
}

// ============================================
// 2. 屏幕配置
// ============================================
export const mockScreenConfig = {
  robotName: '智能迎宾机器人',
  logoUrl: '',
  idleTimeout: 60,
  theme: 'default',
  version: '1.0.0'
}

// ============================================
// 3. 播放方案与素材（本地测试素材）
// ============================================

// 本地测试素材 import（后续替换为后端接口返回的 url 即可）
// 注意：import.meta.glob 这里必须使用相对路径，不能使用 @ 别名。
// 当前文件位于 src/mock/screen.js，所以到 assets 的路径是 ../assets/...
const imageModules = import.meta.glob('../assets/media/play-plan/images/*.{png,jpg,jpeg,webp}', {
  eager: true,
  import: 'default'
})

const videoModules = import.meta.glob('../assets/media/play-plan/videos/*.{mp4,webm}', {
  eager: true,
  import: 'default'
})

const getFileTitle = (filePath, fallback) => {
  const fileName = filePath.split('/').pop() || fallback
  return decodeURIComponent(fileName).replace(/\.[^.]+$/, '')
}

const imageItems = Object.entries(imageModules).map(([path, url], index) => ({
  id: `local_img_${String(index + 1).padStart(3, '0')}`,
  type: 'image',
  title: getFileTitle(path, `图片素材 ${index + 1}`),
  subtitle: '',
  url,
  duration: 8000,
  fitMode: 'cover',
  showTitle: false
}))

const videoItems = Object.entries(videoModules).map(([path, url], index) => ({
  id: `local_video_${String(index + 1).padStart(3, '0')}`,
  type: 'video',
  title: getFileTitle(path, `视频素材 ${index + 1}`),
  subtitle: '',
  url,
  duration: 30000,
  fitMode: 'cover',
  // 开发测试阶段默认静音，避免 Chromium 因未交互而拦截自动播放；后续可由播放方案字段控制
  muted: true,
  showTitle: false
}))

const localPlayItems = [
  //...imageItems,
  ...videoItems
]

export const mockPlayPlan = {
  enabled: localPlayItems.length > 0,
  planId: 'plan_local_test_001',
  planName: '本地测试播放方案',
  playMode: 'loop',
  defaultFitMode: 'cover',
  items: localPlayItems
}

// 欢迎页兜底内容
export const mockWelcomeContent = {
  title: '欢迎光临',
  subtitle: '您好，请问有什么可以帮您？',
  hint: '触摸屏幕开启服务',
  logo: ''
}

// ============================================
// 4. 播报内容
// ============================================
export const mockBroadcastState = {
  broadcasting: false,
  title: '',
  content: '',
  startTime: null,
  endTime: null
}

// 示例播报内容
export const mockBroadcastContent = {
  title: '重要通知',
  content: '各位访客请注意，本周日下午两点将在会议中心举办新产品发布会，欢迎各位参加。'
}

// ============================================
// 5. 语音指令
// ============================================
export const mockCommands = [
  { commandId: 'cmd_001', type: 'OPEN_MENU', action: 'menu', payload: {}, timestamp: Date.now() },
  { commandId: 'cmd_002', type: 'OPEN_PAGE', action: 'visitor', payload: { page: '/visitor' }, timestamp: Date.now() },
  { commandId: 'cmd_003', type: 'SHOW_ALERT', action: 'alert', payload: { title: '低电量', message: '机器人电量较低，请及时充电' }, timestamp: Date.now() }
]

// ============================================
// 6. 预约访客数据
// ============================================
export const mockAppointments = [
  {
    appointmentNo: 'AP202401150001',
    visitorName: '张先生',
    mobile: '13812345678',
    idCardNo: '310101199001011234',
    visitedPerson: '李经理',
    visitedDepartment: '市场部',
    appointmentTime: '2024-01-15 14:00',
    visitPurpose: '商务洽谈',
    status: 'confirmed'
  },
  {
    appointmentNo: 'AP202401150002',
    visitorName: '王女士',
    mobile: '13987654321',
    idCardNo: '320101199002022345',
    visitedPerson: '张主管',
    visitedDepartment: '人事部',
    appointmentTime: '2024-01-15 15:30',
    visitPurpose: '面试应聘',
    status: 'confirmed'
  },
  {
    appointmentNo: 'AP202401160001',
    visitorName: '陈先生',
    mobile: '13611112222',
    idCardNo: '330101199003033456',
    visitedPerson: '财务部',
    visitedDepartment: '财务部',
    appointmentTime: '2024-01-16 10:00',
    visitPurpose: '咨询业务',
    status: 'confirmed'
  }
]

// ============================================
// 7. 身份证读取结果 Mock
// ============================================
export const mockIdCardResult = {
  name: '张伟',
  idCardNo: '310101198805051234',
  gender: '男',
  nation: '汉族',
  address: '上海市浦东新区张江镇',
  birthDate: '1988-05-05',
  photoUrl: ''
}

// ============================================
// 8. 人脸识别结果 Mock
// ============================================
export const mockRecognitionResult = {
  personType: 'appointment',
  matchStatus: 'matched',
  visitorName: '张先生',
  appointmentNo: 'AP202401150001',
  confidence: 0.95,
  photoUrl: '',
  visitedPerson: '李经理',
  appointmentTime: '2024-01-15 14:00'
}

// ============================================
// 9. 目的地列表
// ============================================
export const mockDestinations = [
  {
    destinationId: 'dest_001',
    name: '前台',
    category: '服务',
    floor: '1楼',
    description: '综合服务前台',
    estimatedTime: '2分钟',
    icon: 'reception'
  },
  {
    destinationId: 'dest_002',
    name: '大厅',
    category: '公共',
    floor: '1楼',
    description: '主楼大厅',
    estimatedTime: '1分钟',
    icon: 'lobby'
  },
  {
    destinationId: 'dest_003',
    name: '会议室A',
    category: '会议',
    floor: '2楼',
    description: '可容纳20人',
    estimatedTime: '3分钟',
    icon: 'meeting'
  },
  {
    destinationId: 'dest_004',
    name: '会议室B',
    category: '会议',
    floor: '2楼',
    description: '可容纳10人',
    estimatedTime: '3分钟',
    icon: 'meeting'
  },
  {
    destinationId: 'dest_005',
    name: '展厅',
    category: '展示',
    floor: '1楼',
    description: '产品展示厅',
    estimatedTime: '2分钟',
    icon: 'exhibition'
  },
  {
    destinationId: 'dest_006',
    name: '休息区',
    category: '公共',
    floor: '1楼',
    description: '访客休息区域',
    estimatedTime: '1分钟',
    icon: 'rest'
  },
  {
    destinationId: 'dest_007',
    name: '卫生间',
    category: '设施',
    floor: '1楼',
    description: '男女卫生间',
    estimatedTime: '1分钟',
    icon: 'toilet'
  },
  {
    destinationId: 'dest_008',
    name: '茶水间',
    category: '设施',
    floor: '2楼',
    description: '员工茶水间',
    estimatedTime: '2分钟',
    icon: 'kitchen'
  }
]

// ============================================
// 10. 通知公告列表
// ============================================
export const mockNotices = [
  {
    id: 'notice_001',
    title: '关于本周产品发布会通知',
    content: '各位同事、访客：\n\n本周日下午两点将在会议中心举办新产品发布会，届时将有公司领导致辞、新产品展示和互动环节。欢迎各位参加。\n\n请提前15分钟入场签到。\n\n综合管理部\n2024年1月10日',
    publishTime: '2024-01-10 09:00',
    publisher: '综合管理部',
    contentType: 'notice',
    priority: 'high'
  },
  {
    id: 'notice_002',
    title: '春节期间放假安排',
    content: '各位员工：\n\n根据国家相关规定，结合公司实际情况，现将2024年春节期间放假安排通知如下：\n\n放假时间：2月9日至2月17日（共9天）\n2月4日（周日）、2月18日（周日）正常上班。\n\n请各部门做好工作交接，确保节日期间安全。\n\n人力资源部\n2024年1月8日',
    publishTime: '2024-01-08 14:00',
    publisher: '人力资源部',
    contentType: 'notice',
    priority: 'normal'
  },
  {
    id: 'notice_003',
    title: '办公区域消防演习通知',
    content: '各部门：\n\n为提高员工消防安全意识，公司将于1月20日上午10点进行消防演习。届时将鸣响警报，请各部门配合疏散。\n\n演习结束后将在广场集合并进行灭火器使用培训。\n\n安全保障部\n2024年1月12日',
    publishTime: '2024-01-12 10:00',
    publisher: '安全保障部',
    contentType: 'notice',
    priority: 'normal'
  },
  {
    id: 'notice_004',
    title: '茶水间使用温馨提示',
    content: '尊敬的员工：\n\n为保持茶水间整洁，请大家在使用后：\n1. 将自己的餐具带离\n2. 清理台面积水\n3. 将垃圾分类投放\n4. 节约用水用电\n\n感谢配合！',
    publishTime: '2024-01-05 08:00',
    publisher: '行政部',
    contentType: 'tips',
    priority: 'low'
  }
]

// ============================================
// 11. 导航状态 Mock
// ============================================
export const mockNavigationStatus = {
  taskId: 'nav_001',
  status: 'navigating',
  currentPoint: '当前位置：大堂',
  targetName: '会议室A',
  progress: 45,
  estimatedTime: '约2分钟'
}

// ============================================
// 12. 系统信息 Mock
// ============================================
export const mockSystemInfo = {
  deviceId: 'ROBOT-2024-001',
  robotName: '智能迎宾机器人-01号',
  ipAddress: '192.168.1.100',
  macAddress: '00:11:22:33:44:55',
  frontendVersion: '1.0.0',
  backendVersion: '1.0.0',
  screenResolution: '1024×768',
  lastUpdate: '2024-01-15 10:00:00',
  uptime: '72小时35分',
  services: [
    { name: '后端服务', status: 'online', latency: '12ms' },
    { name: '语音服务', status: 'online', latency: '25ms' },
    { name: '导航服务', status: 'online', latency: '8ms' },
    { name: '人脸识别', status: 'online', latency: '45ms' }
  ]
}

// ============================================
// 13. 待机页主题配置（屏幕主题）
// ============================================
export const mockScreenTheme = {
  robotName: '迎宾巡逻机器人',
  brandSubtitle: '智能接待 · 路线引导 · 信息服务',
  logoUrl: '',
  welcomeTitle: '您好，欢迎光临',
  welcomeSubtitle: '我可以为您提供访客登记、路线引导、通知公告查询与现场帮助服务',
  primaryColor: '#2f8ee5',
  secondaryColor: '#20b7c7',
  backgroundType: 'image',
  backgroundImage: '',
  backgroundFit: 'stretch',
  backgroundOverlay: true,
  showDecorations: false,
  touchText: '触摸屏幕进入服务',
  showServicePanel: false,
  showStatusBar: true,
  showTime: true,
  showDebugSwitch: true,
  serviceItems: [
    {
      code: '01',
      title: '访客登记',
      desc: '预约到访 / 现场登记'
    },
    {
      code: '02',
      title: '路线引导',
      desc: '大厅、展厅、会议室等'
    },
    {
      code: '03',
      title: '通知公告',
      desc: '查看最新通知信息'
    },
    {
      code: '04',
      title: '呼叫工作人员',
      desc: '需要帮助时快速联系'
    }
  ]
}

// ============================================
// 导出所有 Mock 数据
// ============================================
export default {
  mockRobotStatus,
  mockScreenConfig,
  mockPlayPlan,
  mockWelcomeContent,
  mockBroadcastState,
  mockBroadcastContent,
  mockCommands,
  mockAppointments,
  mockIdCardResult,
  mockRecognitionResult,
  mockDestinations,
  mockNotices,
  mockNavigationStatus,
  mockSystemInfo,
  mockScreenTheme
}
