import React from 'react';
import { Heart, Star01, Users01, Clock, CheckCircle } from '@untitledui/icons';

/**
 * Icon mapping utility for converting icon string names to icon components.
 * Used across design system components to ensure consistent icon rendering.
 */
export const iconMap: Record<string, React.FC<{ className?: string }>> = {
  heart: Heart,
  star: Star01,
  users: Users01,
  clock: Clock,
  check: CheckCircle,
};

/**
 * Maps an icon (string, component, or ReactNode) to an icon component.
 * If it's already a component, returns it as-is.
 * If it's a string, looks it up in the iconMap.
 * If it's null or other ReactNode, returns undefined.
 */
export function mapIcon(icon: string | React.FC<{ className?: string }> | React.ReactNode | undefined | null): React.FC<{ className?: string }> | undefined {
  if (!icon) return undefined;
  if (typeof icon === 'function') return icon;
  if (typeof icon === 'string') return iconMap[icon.toLowerCase()];
  return undefined; // For other ReactNode types
}

