export const roleLabels: Record<string, string> = {
  super_admin: '超级管理员',
  agent: '代理管理员',
  user: '普通用户',
}

export const resourceLabels: Record<string, string> = {
  'catalog/categories': '分类管理',
  'catalog/products': '商品管理',
  'admin/users': '用户管理',
  'admin/audit-logs': '操作日志',
  'admin/api-call-logs': '接口日志',
  'admin/third-party': '第三方接口',
  'admin/permissions': '权限配置',
}

export const actionLabels: Record<string, string> = {
  read: '查看',
  write: '管理',
}

export function formatDateTime(value?: string | null) {
  if (!value) {
    return '-'
  }

  const date = new Date(value)
  if (Number.isNaN(date.getTime())) {
    return value
  }

  return date.toLocaleString('zh-CN', {
    year: 'numeric',
    month: '2-digit',
    day: '2-digit',
    hour: '2-digit',
    minute: '2-digit',
  })
}

export function getRoleLabel(code?: string, name?: string) {
  if (!code) {
    return name || '-'
  }
  return name || roleLabels[code] || code
}
