import {
  CircleCheck,
  FileText,
  Folder,
  HelpCircle,
  Image,
  MessageSquare,
  Mic,
  Radio,
  StickyNote,
  Trash2,
  Video,
  type LucideIcon,
} from 'lucide-react';
import { isParticleDeleted, type Particle } from '@/api/types';

export function getParticleTypeIcon(particle: Particle): LucideIcon {
  if (isParticleDeleted(particle)) return Trash2;
  switch (particle.type) {
    case 'stream':
      return Radio;
    case 'folder':
      return Folder;
    case 'text':
      return MessageSquare;
    case 'media': {
      const mime = particle.properties.mime_type;
      if (mime.startsWith('video/')) return Video;
      if (mime.startsWith('audio/')) return Mic;
      if (mime.startsWith('image/')) return Image;
      return Video;
    }
    case 'file':
      return FileText;
    case 'task':
      return CircleCheck;
    case 'paper':
      return StickyNote;
    case 'unknown':
      return HelpCircle;
  }
}

export function getMessagePreview(particle: Particle): string {
  if (isParticleDeleted(particle)) return 'Deleted particle';
  switch (particle.type) {
    case 'stream':
    case 'folder':
      return particle.properties.name;
    case 'text':
      return particle.properties.content;
    case 'media': {
      const mime = particle.properties.mime_type;
      if (mime.startsWith('image/')) return 'Photo';
      if (mime.startsWith('video/') || mime.startsWith('audio/')) {
        const transcriptText = particle.properties.transcript?.transcript;
        if (transcriptText) return transcriptText;
        return mime.startsWith('video/') ? 'Video clip' : 'Voice note';
      }
      return 'Media';
    }
    case 'file':
      return particle.properties.filename;
    case 'task':
      return particle.properties.title;
    case 'paper':
      return particle.properties.title;
    case 'unknown':
      return 'Unsupported particle';
  }
}

export function getParticleDisplayName(particle: Particle): string {
  switch (particle.type) {
    case 'stream':
    case 'folder':
      return particle.properties.name;
    case 'task':
      return particle.properties.title;
    case 'paper':
      return particle.properties.title;
    case 'file':
      return particle.properties.filename;
    case 'text':
      return particle.properties.content.slice(0, 30);
    case 'media':
      return particle.type;
    case 'unknown':
      return 'Unsupported particle';
  }
}
