// Copyright (c) Meta Platforms, Inc. and affiliates.

'use client';

/**
 * @file useIcon.ts
 * @input Semantic icon name
 * @output Exports useIcon hook for theme-aware icon lookup
 * @position Client hook for components that render registry icons directly
 */

import type {ReactNode} from 'react';
import {useThemeName} from '../theme/useTheme';
import {getIcon, type IconName} from './globalIconRegistry';

/**
 * Resolve a semantic icon name from the nearest Theme, falling back through
 * root theme registration, global icon overrides, and built-in defaults.
 */
export function useIcon(name: IconName): ReactNode {
  const themeName = useThemeName();
  return getIcon(name, themeName);
}
