import React from 'react';

import CloseIcon from '../icons/close';
import CloseSmallIcon from '../icons/close-small';
import StatusCloseIcon from '../icons/status-close';
import UnDoIcon from '../icons/undo';
import ReDoIcon from '../icons/redo';
import EnterIcon from '../icons/enter';
import VolumeIcon from '../icons/volume';
import MuteIcon from '../icons/mute';
import PlayIcon from '../icons/play';
import PauseIcon from '../icons/pause';
import LeftArrowIcon from '../icons/left-arrow';
import RightArrowIcon from '../icons/right-arrow';
import CheckIcon from '../icons/check';
import PlusIcon from '../icons/plus';
import MinusIcon from '../icons/minus';
import PencilIcon from '../icons/pencil';
import ViewIcon from '../icons/view';
import RemoveIcon from '../icons/remove';
import RetryIcon from '../icons/retry';
import UploadIcon from '../icons/upload';
import FileIcon from '../icons/file';
import StatusSuccessIcon from '../icons/status-success';
import StatusFailIcon from '../icons/status-fail';
import StatusInfoIcon from '../icons/status-info';
import StatusWarningIcon from '../icons/status-warning';
import SuccessIcon from '../icons/success';
import FailIcon from '../icons/fail';
import SearchIcon from '../icons/search';
import BackIcon from '../icons/back';
import MoveIcon from '../icons/move';
import InfoIcon from '../icons/info';
import LocationIcon from '../icons/location';
import DragBarIcon from '../icons/drag-bar';
import ReloadIcon from '../icons/reload';
import ExchangeIcon from '../icons/exchange';
import ColmunsIcon from '../icons/columns';
import CalendarIcon from '../icons/calendar';
import ClockIcon from '../icons/clock';
import CopyIcon from '../icons/copy';
import FilterIcon from '../icons/filter';
import CaretIcon from '../icons/caret';
import RightArrowBoldIcon from '../icons/right-arrow-bold';
import ColumnFilterIcon from '../icons/column-filter';
import ZoomInIcon from '../icons/zoom-in';
import ZoomOutIcon from '../icons/zoom-out';
import QuestionIcon from '../icons/question';
import QuestionMarkIcon from '../icons/question-mark';
import WindowRestoreIcon from '../icons/window-restore';
import InfoCircleIcon from '../icons/info-circle';
import WarningIcon from '../icons/warning';
import WarningMarkIcon from '../icons/warning-mark';
import ScheduleIcon from '../icons/schedule';
import HomeIcon from '../icons/home';
import FolderIcon from '../icons/folder';
import SortDefaultIcon from '../icons/sort-default';
import SortAscIcon from '../icons/sort-asc';
import SortDescIcon from '../icons/sort-desc';
import SettingIcon from '../icons/setting';
import PlusCicleIcon from '../icons/plus-cicle';
import EllipsisVIcon from '../icons/ellipsis-v';
import InputClearIcon from '../icons/input-clear';
import ResetIcon from '../icons/reset'
import ArrowDBTopIcon from '../icons/arrow-db-top'
import ArrowDBDownIcon from '../icons/arrow-db-down'
import MoreIcon from '../icons/more'
import ListIcon from '../icons/list'
import AddIcon from '../icons/add'
import SubIcon from '../icons/sub'
import LoadingOutline from '../icons/loading-outline';
import DownArrowBoldIcon from '../icons/down-arrow-bold';
import TeamsIcon from '../icons/teams';
import TimeIcon from '../icons/time';//工时
import SubWorkIcon from '../icons/sub-work';//子工作项
import BatchSubWorkIcon from '../icons/batch-sub-work' //新建子工作项
import RelatedWorkIcon from '../icons/related-work';//关联工作项
import AddRelatedWorkIcon from '../icons/add-related-work';//新建
import RelatedPlanIcon from '../icons/related-plan';//关联计划组
import RelatedLibraryIcon from '../icons/related-library';//关联用例
import relatedWikiIcon from '../icons/related-wiki';//关联Wiki
import editIcon from '../icons/edit';
import attachmentIcon from '../icons/attachment';
import linkIcon from '../icons/link';


const iconFactory: {
  [propName: string]: React.ReactType<{}>;
} = {};

export function getIcon(key: string) {
  return iconFactory[key];
}

export function hasIcon(iconName: string) {
  return !!getIcon(iconName);
}

export function registerIcon(key: string, component: React.ReactType<{}>) {
  iconFactory[key] = component;
}

registerIcon('close', CloseIcon);
registerIcon('close-small', CloseSmallIcon);
registerIcon('status-close', StatusCloseIcon);
registerIcon('undo', UnDoIcon);
registerIcon('redo', ReDoIcon);
registerIcon('enter', EnterIcon);
registerIcon('volume', VolumeIcon);
registerIcon('mute', MuteIcon);
registerIcon('play', PlayIcon);
registerIcon('pause', PauseIcon);
registerIcon('left-arrow', LeftArrowIcon);
registerIcon('right-arrow', RightArrowIcon);
registerIcon('prev', LeftArrowIcon);
registerIcon('next', RightArrowIcon);
registerIcon('check', CheckIcon);
registerIcon('plus', PlusIcon);
registerIcon('add', PlusIcon);
registerIcon('minus', MinusIcon);
registerIcon('pencil', PencilIcon);
registerIcon('view', ViewIcon);
registerIcon('remove', RemoveIcon);
registerIcon('retry', RetryIcon);
registerIcon('upload', UploadIcon);
registerIcon('file', FileIcon);
registerIcon('status-success', StatusSuccessIcon);
registerIcon('status-fail', StatusFailIcon);
registerIcon('status-info', StatusInfoIcon);
registerIcon('status-warning', StatusWarningIcon);
registerIcon('success', SuccessIcon);
registerIcon('fail', FailIcon);
registerIcon('warning', WarningIcon);
registerIcon('warning-mark', WarningMarkIcon);
registerIcon('search', SearchIcon);
registerIcon('back', BackIcon);
registerIcon('move', MoveIcon);
registerIcon('info', InfoIcon);
registerIcon('info-circle', InfoCircleIcon);
registerIcon('location', LocationIcon);
registerIcon('drag-bar', DragBarIcon);
registerIcon('reload', ReloadIcon);
registerIcon('exchange', ExchangeIcon);
registerIcon('columns', ColmunsIcon);
registerIcon('calendar', CalendarIcon);
registerIcon('clock', ClockIcon);
registerIcon('copy', CopyIcon);
registerIcon('filter', FilterIcon);
registerIcon('column-filter', ColumnFilterIcon);
registerIcon('caret', CaretIcon);
registerIcon('right-arrow-bold', RightArrowBoldIcon);
registerIcon('zoom-in', ZoomInIcon);
registerIcon('zoom-out', ZoomOutIcon);
registerIcon('question', QuestionIcon);
registerIcon('question-mark', QuestionMarkIcon);
registerIcon('window-restore', WindowRestoreIcon);
registerIcon('schedule', ScheduleIcon);
registerIcon('home', HomeIcon);
registerIcon('folder', FolderIcon);
registerIcon('sort-default', SortDefaultIcon);
registerIcon('sort-asc', SortAscIcon);
registerIcon('sort-desc', SortDescIcon);
registerIcon('setting', SettingIcon);
registerIcon('plus-cicle', PlusCicleIcon);
registerIcon('ellipsis-v', EllipsisVIcon);
registerIcon('input-clear', InputClearIcon);
registerIcon('reset', ResetIcon);
registerIcon('arrow-db-top', ArrowDBTopIcon);
registerIcon('arrow-db-down', ArrowDBDownIcon);
registerIcon('more', MoreIcon);
registerIcon('list', ListIcon);
registerIcon('add', AddIcon);
registerIcon('sub', SubIcon);
registerIcon('loading-outline', LoadingOutline);
registerIcon('down-arrow-bold', DownArrowBoldIcon);
registerIcon('teams', TeamsIcon);
registerIcon('time', TimeIcon);
registerIcon('sub-work', SubWorkIcon);                  
registerIcon('batch-sub-Work', BatchSubWorkIcon);
registerIcon('related-work', RelatedWorkIcon);
registerIcon('add-related-work', AddRelatedWorkIcon);
registerIcon('related-plan', RelatedPlanIcon);
registerIcon('related-library', RelatedLibraryIcon);
registerIcon('related-wiki', relatedWikiIcon);
registerIcon('edit', editIcon);
registerIcon('attachment', attachmentIcon);
registerIcon('link', linkIcon);



export function Icon({
  icon,
  className,
  ...rest
}: {
  icon: string;
} & React.ComponentProps<any>) {

  const Component = getIcon(icon);
  return Component ? (
    <Component {...rest} className={`${className || ''} icon-${icon}`} />
  ) : (
    <span className="text-danger">没有 icon {icon}</span>
  );
}

export {
  CloseIcon,
  UnDoIcon,
  ReDoIcon,
  EnterIcon,
  VolumeIcon,
  MuteIcon,
  PlayIcon,
  PauseIcon,
  LeftArrowIcon,
  RightArrowIcon,
  CheckIcon,
  PlusIcon,
  MinusIcon,
  PencilIcon
};

export default Icon;