import { KnowledgeStatus, SkillType } from '../../api';

export const DEFAULT_AVATAR = 'https://static.svipdata.com/hoyidata/materials/B7lNeTYQM1_0/materials.jpg';

export const PRESET_AVATARS: string[] = [
  'https://static.svipdata.com/hoyidata/materials/PkM0iQCaAY_0/materials.png',
  'https://static.svipdata.com/hoyidata/materials/tmPDm2FhJY_1/materials.png',
  'https://static.svipdata.com/hoyidata/materials/hNCyP4RvJL_2/materials.png',
  'https://static.svipdata.com/hoyidata/materials/l2OMyoIVff_3/materials.png',
  'https://static.svipdata.com/hoyidata/materials/CINYRp0JJS_4/materials.png',
  'https://static.svipdata.com/hoyidata/materials/oUFVVgRpJa_5/materials.png',
  'https://static.svipdata.com/hoyidata/materials/WZccHWHK40_6/materials.png',
  'https://static.svipdata.com/hoyidata/materials/sLmZKx5GoI_7/materials.png',
  'https://static.svipdata.com/hoyidata/materials/ZPHkYQHOE0_8/materials.png',
  'https://static.svipdata.com/hoyidata/materials/kpMcS2ekGq_9/materials.png',
  'https://static.svipdata.com/hoyidata/materials/1vkwcmV5MC_10/materials.png',
  'https://static.svipdata.com/hoyidata/materials/nLLWLA0eLZ_11/materials.png',
];

export const STATUS_TAG: Record<KnowledgeStatus, { color: string; text: string }> = {
  pending: { color: 'default', text: '待处理' },
  indexing: { color: 'processing', text: '索引中…' },
  ready: { color: 'success', text: '已就绪' },
  failed: { color: 'error', text: '失败' },
};

export const TYPE_TAG: Record<SkillType, { color: string; icon: string; label: string }> = {
  prompt: { color: 'blue', icon: '📝', label: 'Prompt' },
  http: { color: 'green', icon: '🌐', label: 'HTTP' },
  js: { color: 'volcano', icon: '⚙️', label: 'JS' },
};

export const isImageUrl = (url: string | undefined) => url?.startsWith('http') || url?.startsWith('/');

export const parseModelSelections = (value?: string | string[]) => {
  if (Array.isArray(value)) {
    return value;
  }
  // 尝试解析 JSON 格式
  try {
    const parsed = JSON.parse(String(value || '[]'));
    if (Array.isArray(parsed)) {
      return parsed.map((item: any) => {
        if (typeof item === 'object' && item.id) {
          return item.id;
        }
        return String(item);
      }).filter(Boolean);
    }
  } catch {
    // 兼容旧格式：逗号分隔的字符串
  }
  return String(value || '')
    .split(',')
    .map((item) => item.trim())
    .filter(Boolean);
};
