import React from 'react';
import * as ArcoIcons from '@arco-design/web-react/icon';

export interface DynamicIconProps {
  type: string;
  library?: 'arco'; // 可以扩展支持更多图标库
  [key: string]: any;
}

const DynamicIcon: React.FC<DynamicIconProps> = ({
                                                   type,
                                                   library = 'arco',
                                                   ...restProps
                                                 }) => {
  let IconComponent: React.ComponentType<any> | undefined;

  if (library === 'arco') {
    IconComponent = ArcoIcons[type as keyof typeof ArcoIcons];
  } // library 有其他的图标库时可添加

  if (!IconComponent) {
    console.warn(`Icon '${type}' from library '${library}' not found`);
    return null;
  }

  return <IconComponent {...restProps} />;
};

export default DynamicIcon;
