import {
	Circle,
	Globe,
	Shield,
	DollarSign,
	ShieldOff,
	Gem,
	Activity,
	Blocks,
	FileText,
	Server,
	UserCheck,
	Zap,
	ShieldAlert,
	Hourglass,
	Code2,
	Globe2,
	Pin,
	Layers,
	GalleryHorizontal,
	PlayCircle,
	BookOpen,
} from 'lucide-react';

/**
 * Maps schema-driven icon name strings to lucide-react components.
 *
 * Only icons chosen from data (module/tab/link config) belong here. Icons a
 * component renders directly should keep importing from lucide-react.
 */
const REGISTRY = {
	globe: Globe,
	shield: Shield,
	'dollar-sign': DollarSign,
	'shield-off': ShieldOff,
	gem: Gem,
	activity: Activity,
	blocks: Blocks,
	'file-text': FileText,
	server: Server,
	'user-check': UserCheck,
	zap: Zap,
	'shield-alert': ShieldAlert,
	hourglass: Hourglass,
	'code-2': Code2,
	'globe-2': Globe2,
	pin: Pin,
	layers: Layers,
	'gallery-horizontal': GalleryHorizontal,
	'play-circle': PlayCircle,
	'book-open': BookOpen,
};

/**
 * Resolves an icon name to its component, for cases that pass the component on.
 *
 * @param {string}   name       Registered icon name.
 * @param {Function} [fallback] Component to use when the name is unknown.
 * @return {Function} An icon component.
 */
export function resolveIcon( name, fallback = Circle ) {
	return REGISTRY[ name ] ?? fallback;
}

/**
 * Renders a registered icon by name.
 *
 * @param {Object}   props
 * @param {string}   props.name       Registered icon name.
 * @param {Function} [props.fallback] Component to use when the name is unknown.
 * @return {Object} The icon element.
 */
export function Icon( { name, fallback = Circle, ...props } ) {
	const Cmp = resolveIcon( name, fallback );
	return <Cmp { ...props } />;
}
