import {
  Globe,
  Network,
  Monitor,
  Fingerprint,
  FolderSearch,
  Link,
  ShieldAlert,
  Shield,
  Camera,
  Search,
  Cpu,
} from "lucide-react"
import type { LucideIcon } from "lucide-react"

/** Unified capability tag color (using global CSS variables) */
const CAPABILITY_COLOR = "bg-primary/10 text-primary border-primary/20"

/**
 * Engine capability configuration (using global CSS colors)
 * Used for scan initiation, quick scan and other engine selection interfaces
 */
export const CAPABILITY_CONFIG: Record<string, { 
  label: string
  color: string
  icon: LucideIcon 
}> = {
  subdomain_discovery: { label: "Subdomain Discovery", color: CAPABILITY_COLOR, icon: Globe },
  port_scan: { label: "Port Scan", color: CAPABILITY_COLOR, icon: Network },
  site_scan: { label: "Site Scan", color: CAPABILITY_COLOR, icon: Monitor },
  fingerprint_detect: { label: "Fingerprint Detection", color: CAPABILITY_COLOR, icon: Fingerprint },
  directory_scan: { label: "Directory Scan", color: CAPABILITY_COLOR, icon: FolderSearch },
  url_fetch: { label: "URL Fetch", color: CAPABILITY_COLOR, icon: Link },
  vuln_scan: { label: "Vulnerability Scan", color: CAPABILITY_COLOR, icon: ShieldAlert },
  waf_detection: { label: "WAF Detection", color: CAPABILITY_COLOR, icon: Shield },
  screenshot: { label: "Screenshot", color: CAPABILITY_COLOR, icon: Camera },
  osint: { label: "OSINT", color: CAPABILITY_COLOR, icon: Search },
}

/**
 * Get main icon based on engine capabilities
 * Returns the first matching capability icon by priority
 */
export function getEngineIcon(capabilities: string[]): LucideIcon {
  const priorityOrder = [
    'vuln_scan', 
    'subdomain_discovery', 
    'port_scan', 
    'site_scan', 
    'directory_scan', 
    'url_fetch', 
    'waf_detection', 
    'screenshot', 
    'osint'
  ]
  
  for (const key of priorityOrder) {
    if (capabilities.includes(key)) {
      return CAPABILITY_CONFIG[key].icon
    }
  }
  return Cpu
}

/**
 * Parse engine configuration to get capability list
 */
export function parseEngineCapabilities(configuration: string): string[] {
  if (!configuration) return []
  
  try {
    const capabilities: string[] = []
    Object.keys(CAPABILITY_CONFIG).forEach((key) => {
      if (configuration.includes(key)) {
        capabilities.push(key)
      }
    })
    return capabilities
  } catch {
    return []
  }
}
