import * as PhosphorIcons from '@phosphor-icons/react'

export type PhosphorIconWeight = 'thin' | 'light' | 'regular' | 'bold' | 'fill' | 'duotone'

export type PhosphorIconComponent = React.ComponentType<{
  className?: string
  weight?: PhosphorIconWeight
}>

/**
 * Get a Phosphor icon component by its kebab-case name
 * 
 * @param iconName - The icon name in kebab-case (e.g., "arrow-right", "github-logo")
 * @returns The Phosphor icon component or null if not found
 * 
 * @example
 * const Icon = getPhosphorIcon('arrow-right')
 * if (Icon) {
 *   return <Icon className="h-5 w-5" weight="bold" />
 * }
 */
export function getPhosphorIcon(iconName?: string): PhosphorIconComponent | null {
  if (!iconName) return null
  
  // Convert kebab-case to PascalCase for Phosphor icons
  const pascalCase = iconName
    .split('-')
    .map(part => part.charAt(0).toUpperCase() + part.slice(1))
    .join('')
  
  const IconComponent = (PhosphorIcons as Record<string, unknown>)[pascalCase]
  
  if (typeof IconComponent === 'function') {
    return IconComponent as PhosphorIconComponent
  }
  
  return null
}

/**
 * Check if a Phosphor icon exists by name
 * 
 * @param iconName - The icon name in kebab-case
 * @returns true if the icon exists
 */
export function hasPhosphorIcon(iconName?: string): boolean {
  return getPhosphorIcon(iconName) !== null
}
