import { iconLibrary } from '../../../icons';
import { sanitizeSvg } from '../../../components/settings/iconUtils';

export function HeadingIcon({ iconType, iconCategory, iconName, customIcon }) {
  if (iconType === 'library' && iconCategory && iconName) {
    const IconComponent = iconLibrary[iconCategory]?.[iconName];
    return IconComponent ? <span className="icon"><IconComponent /></span> : null;
  }
  if (iconType === 'custom' && customIcon?.includes('<svg')) {
    const safeSvg = sanitizeSvg(customIcon);
    return safeSvg ? <span className="icon" dangerouslySetInnerHTML={{ __html: safeSvg }} /> : null;
  }
  return null;
}
