import type { IconComponent } from "reicon-react";
import {
  Activity2 as ReActivity2, Add2 as ReAdd2, AddCircle2 as ReAddCircle2, AddSquare2 as ReAddSquare2,
  Additem2 as ReAdditem2, AddressBook as ReAddressBook, AddressCard as ReAddressCard, Alert as ReAlert,
  AlertCircle as ReAlertCircle, AlertCircle2 as ReAlertCircle2, AlertSquare as ReAlertSquare, AlertTriangle as ReAlertTriangle,
  AlertTriangle2 as ReAlertTriangle2, AngleDown2 as ReAngleDown2, AngleDownCircle as ReAngleDownCircle, AngleDownSquare as ReAngleDownSquare,
  AngleLeft2 as ReAngleLeft2, AngleLeftCircle as ReAngleLeftCircle, AngleLeftSquare as ReAngleLeftSquare, AngleRight2 as ReAngleRight2,
  AngleRightCircle as ReAngleRightCircle, AngleRightSquare as ReAngleRightSquare, AngleUp2 as ReAngleUp2, AngleUpCircle as ReAngleUpCircle,
  AngleUpSquare as ReAngleUpSquare, AnglesLeft as ReAnglesLeft, AnglesLeft2 as ReAnglesLeft2, AnglesRight as ReAnglesRight,
  AnglesRight2 as ReAnglesRight2, Archive as ReArchive, Archive12 as ReArchive12, Archive2 as ReArchive2,
  Archive22 as ReArchive22, Archive4 as ReArchive4, ArchiveAdd2 as ReArchiveAdd2, ArchiveBook2 as ReArchiveBook2,
  ArchiveBox as ReArchiveBox, ArchiveCheck as ReArchiveCheck, ArchiveDown as ReArchiveDown, ArchiveDown2 as ReArchiveDown2,
  ArchiveMinus2 as ReArchiveMinus2, ArchiveSlash2 as ReArchiveSlash2, ArchiveTick2 as ReArchiveTick2, ArchiveUp as ReArchiveUp,
  ArchiveUp2 as ReArchiveUp2, Arrow2 as ReArrow2, Arrow22 as ReArrow22, Arrow32 as ReArrow32,
  ArrowBottom2 as ReArrowBottom2, ArrowCircleDown2 as ReArrowCircleDown2, ArrowCircleLeft2 as ReArrowCircleLeft2, ArrowCircleRight2 as ReArrowCircleRight2,
  ArrowCircleUp2 as ReArrowCircleUp2, ArrowDoorIn as ReArrowDoorIn, ArrowDoorOut3 as ReArrowDoorOut3, ArrowDottedRotateAnticlockwise as ReArrowDottedRotateAnticlockwise,
  ArrowDown as ReArrowDown, ArrowDown12 as ReArrowDown12, ArrowDown2 as ReArrowDown2, ArrowDown22 as ReArrowDown22,
  ArrowDown3 as ReArrowDown3, ArrowDown5 as ReArrowDown5, ArrowDownCircle as ReArrowDownCircle, ArrowDownLeft2 as ReArrowDownLeft2,
  ArrowDownLeftCircle as ReArrowDownLeftCircle, ArrowDownLeftSquare as ReArrowDownLeftSquare, ArrowDownRight2 as ReArrowDownRight2, ArrowDownRightCircle as ReArrowDownRightCircle,
  ArrowDownRightSquare as ReArrowDownRightSquare, ArrowDownSquare as ReArrowDownSquare, ArrowLeft as ReArrowLeft, ArrowLeft12 as ReArrowLeft12,
  ArrowLeft2 as ReArrowLeft2, ArrowLeft22 as ReArrowLeft22, ArrowRotate as ReArrowRotate, ArrowsRotate as ReArrowsRotate,
  Battery as ReBattery, Battery3full2 as ReBattery3full2, BatteryCharge as ReBatteryCharge, BatteryCharge2 as ReBatteryCharge2,
  BatteryCharging2 as ReBatteryCharging2, BatteryDisable2 as ReBatteryDisable2, BatteryEmpty12 as ReBatteryEmpty12, BatteryEmpty2 as ReBatteryEmpty2,
  BatteryFull as ReBatteryFull, BatteryFull2 as ReBatteryFull2, BatteryFull4 as ReBatteryFull4, BatteryHalf as ReBatteryHalf,
  BatteryHalf2 as ReBatteryHalf2, BatteryHigh as ReBatteryHigh, BatteryLow as ReBatteryLow, Bell as ReBell,
  BellAlert as ReBellAlert, BellOff as ReBellOff, BellOff2 as ReBellOff2, BellRing as ReBellRing,
  Bluetooth as ReBluetooth, Bluetooth22 as ReBluetooth22, Bluetooth3 as ReBluetooth3, BluetoothCircle as ReBluetoothCircle,
  BluetoothCircle3 as ReBluetoothCircle3, BluetoothRectangle2 as ReBluetoothRectangle2, BluetoothSquare as ReBluetoothSquare, BluetoothWave as ReBluetoothWave,
  Book as ReBook, Book12 as ReBook12, Book2 as ReBook2, Book3 as ReBook3,
  Book4 as ReBook4, Book6 as ReBook6, BookBookmark as ReBookBookmark, BookBookmark2 as ReBookBookmark2,
  BookOpen as ReBookOpen, BookSaved2 as ReBookSaved2, BookSquare2 as ReBookSquare2, Bookmark as ReBookmark,
  Bookmark2 as ReBookmark2, Bookmark22 as ReBookmark22, Bookmark3 as ReBookmark3, Bookmark5 as ReBookmark5,
  BookmarkAdd as ReBookmarkAdd, BookmarkCheck as ReBookmarkCheck, BookmarkCircle as ReBookmarkCircle, BookmarkMinus as ReBookmarkMinus,
  BookmarkOpen as ReBookmarkOpen, BookmarkSlash as ReBookmarkSlash, BookmarkSquare as ReBookmarkSquare, BookmarkSquare2 as ReBookmarkSquare2,
  BookmarkX as ReBookmarkX, Bookmarks as ReBookmarks, Box as ReBox, BrowserTerminal as ReBrowserTerminal,
  Building as ReBuilding, Buildings2 as ReBuildings2, Cabinet as ReCabinet, Calendar as ReCalendar, Camera as ReCamera, Camera2 as ReCamera2,
  Camera3 as ReCamera3, Camera4 as ReCamera4, CameraAdd as ReCameraAdd, CameraAdd2 as ReCameraAdd2,
  CameraAlt as ReCameraAlt, CameraOff as ReCameraOff, CameraRecord as ReCameraRecord, CameraRotate as ReCameraRotate,
  CameraSlash2 as ReCameraSlash2, CameraSquare as ReCameraSquare, ChartLine as ReChartLine, Check as ReCheck,
  Check3 as ReCheck3, CheckCircle as ReCheckCircle, CheckList as ReCheckList, CheckListSquare as ReCheckListSquare,
  CheckRead as ReCheckRead, CheckSquare as ReCheckSquare, Checklist2 as ReChecklist2, ChecklistAlt as ReChecklistAlt,
  ChevronDown as ReChevronDown, ChevronLeft as ReChevronLeft, ChevronRight as ReChevronRight, ChevronUp as ReChevronUp,
  Clipboard as ReClipboard, Clipboard3 as ReClipboard3, ClipboardAdd as ReClipboardAdd, ClipboardCheck as ReClipboardCheck,
  ClipboardClose2 as ReClipboardClose2, ClipboardExport2 as ReClipboardExport2, ClipboardHeart as ReClipboardHeart, ClipboardImport2 as ReClipboardImport2,
  ClipboardList as ReClipboardList, ClipboardRemove as ReClipboardRemove, ClipboardSlash as ReClipboardSlash, ClipboardText as ReClipboardText,
  ClipboardText3 as ReClipboardText3, ClipboardTick2 as ReClipboardTick2, CloseCircle2 as ReCloseCircle2, CloseSquare2 as ReCloseSquare2,
  Closet as ReCloset, Closet2 as ReCloset2, Cloud as ReCloud, Cloud3 as ReCloud3,
  CloudAdd2 as ReCloudAdd2, CloudBolt as ReCloudBolt, CloudBolt2 as ReCloudBolt2, CloudChange2 as ReCloudChange2,
  CloudCheck as ReCloudCheck, CloudConnect as ReCloudConnect, CloudConnection2 as ReCloudConnection2, CloudCross2 as ReCloudCross2,
  CloudDown2 as ReCloudDown2, CloudDownload as ReCloudDownload, CloudDrizzle2 as ReCloudDrizzle2, CloudDrop as ReCloudDrop,
  CloudDrops as ReCloudDrops, CloudFile as ReCloudFile, CloudFog2 as ReCloudFog2, CloudLightning2 as ReCloudLightning2,
  CloudMinus as ReCloudMinus, CloudMinus3 as ReCloudMinus3, CloudNotif2 as ReCloudNotif2, CloudPlus as ReCloudPlus,
  CloudPlus3 as ReCloudPlus3, CloudRain as ReCloudRain, CloudRemove2 as ReCloudRemove2, CloudSnow as ReCloudSnow,
  CloudSnow2 as ReCloudSnow2, CloudSnow4 as ReCloudSnow4, CloudStorage as ReCloudStorage, CloudStorm as ReCloudStorm,
  CloudSun as ReCloudSun, CloudSun2 as ReCloudSun2, CloudSunny2 as ReCloudSunny2, CloudUp2 as ReCloudUp2,
  CloudUpload as ReCloudUpload, CloudX as ReCloudX, Clouds as ReClouds, Code as ReCode,
  Code12 as ReCode12, Code2 as ReCode2, Code4 as ReCode4, CodeCircle as ReCodeCircle,
  CodeCircle3 as ReCodeCircle3, CodeFile as ReCodeFile, CodeScan as ReCodeScan, CodeSquare as ReCodeSquare,
  Command as ReCommand, Command3 as ReCommand3, CommandSquare2 as ReCommandSquare2, Copy as ReCopy,
  Copy3 as ReCopy3, CopySuccess2 as ReCopySuccess2, Copyright as ReCopyright, Copyright3 as ReCopyright3,
  Cpu as ReCpu, Cpu3 as ReCpu3, CpuBolt as ReCpuBolt, CpuCharge2 as ReCpuCharge2,
  CpuSetting2 as ReCpuSetting2, Database as ReDatabase, Document12 as ReDocument12, Document2 as ReDocument2,
  DocumentCloud2 as ReDocumentCloud2, DocumentCode2 as ReDocumentCode2, DocumentCode22 as ReDocumentCode22, DocumentCopy2 as ReDocumentCopy2,
  DocumentDownload2 as ReDocumentDownload2, DocumentFavorite2 as ReDocumentFavorite2, DocumentFilter2 as ReDocumentFilter2, DocumentForward2 as ReDocumentForward2,
  DocumentLike2 as ReDocumentLike2, DocumentNormal2 as ReDocumentNormal2, DocumentPrevious2 as ReDocumentPrevious2, DocumentSketch2 as ReDocumentSketch2,
  DocumentText12 as ReDocumentText12, DocumentText2 as ReDocumentText2, Download as ReDownload, Download2 as ReDownload2,
  Download3 as ReDownload3, DownloadSquare as ReDownloadSquare, DownloadSquare2 as ReDownloadSquare2, Edit2 as ReEdit2,
  Edit22 as ReEdit22, ExitFullscreen as ReExitFullscreen, ExitFullscreenCircle as ReExitFullscreenCircle, ExitFullscreenSquare as ReExitFullscreenSquare,
  Eye as ReEye, EyeOff as ReEyeOff, File as ReFile, FileText as ReFileText,
  FileUp as ReFileUp, Fingerprint as ReFingerprint, Folder as ReFolder, FolderFiles as ReFolderFiles,
  FolderOpen as ReFolderOpen, Fullscreen as ReFullscreen, FullscreenCircle as ReFullscreenCircle, FullscreenSquare as ReFullscreenSquare,
  Gallery as ReGallery, Gallery2 as ReGallery2, Gallery3 as ReGallery3, Gallery5 as ReGallery5,
  GalleryAdd as ReGalleryAdd, GalleryAdd3 as ReGalleryAdd3, GalleryCheck as ReGalleryCheck, GalleryCircle as ReGalleryCircle,
  GalleryDownload as ReGalleryDownload, GalleryEdit as ReGalleryEdit, GalleryEdit3 as ReGalleryEdit3, GalleryExport2 as ReGalleryExport2,
  GalleryFavorite2 as ReGalleryFavorite2, GalleryImport2 as ReGalleryImport2, GalleryRemove as ReGalleryRemove, GalleryRemove3 as ReGalleryRemove3,
  GallerySend as ReGallerySend, GallerySlash2 as ReGallerySlash2, GalleryStar as ReGalleryStar, GalleryTick2 as ReGalleryTick2,
  GalleryWide as ReGalleryWide, Gauge3 as ReGauge3, Gear as ReGear, Globe as ReGlobe,
  Globe2 as ReGlobe2, Grid as ReGrid, Grid12 as ReGrid12, Grid22 as ReGrid22,
  Grid32 as ReGrid32, Grid42 as ReGrid42, Grid52 as ReGrid52, Grid62 as ReGrid62,
  Grid72 as ReGrid72, Grid82 as ReGrid82, Grid92 as ReGrid92, GridCirclePlus as ReGridCirclePlus,
  GridEdit2 as ReGridEdit2, GridEraser2 as ReGridEraser2, GridLock2 as ReGridLock2, HardDrive as ReHardDrive,
  Help as ReHelp, HelpCircle as ReHelpCircle, HelpSquare as ReHelpSquare, Home as ReHome,
  Image as ReImage, Image3 as ReImage3, ImageCheck as ReImageCheck, ImageDepth as ReImageDepth,
  ImageDown as ReImageDown, ImageMinus as ReImageMinus, ImageMountain as ReImageMountain, ImagePlus as ReImagePlus,
  ImageSparkle as ReImageSparkle, ImageUp as ReImageUp, Images2 as ReImages2, InfoCircle as ReInfoCircle,
  InfoCircle3 as ReInfoCircle3, InfoSquare as ReInfoSquare, Information2 as ReInformation2, Key as ReKey,
  Key2 as ReKey2, Key3 as ReKey3, Key5 as ReKey5, KeySquare as ReKeySquare,
  KeySquare2 as ReKeySquare2, KeySquare3 as ReKeySquare3, KeySquare4 as ReKeySquare4, KeySquare5 as ReKeySquare5,
  KeySquare6 as ReKeySquare6, KeySquare8 as ReKeySquare8, Keyboard as ReKeyboard, Keyboard3 as ReKeyboard3,
  KeyboardOpen2 as ReKeyboardOpen2, Laptop as ReLaptop, Layers as ReLayers, Link as ReLink,
  LinkBroken as ReLinkBroken, List as ReList, List3 as ReList3, ListArrowDown as ReListArrowDown,
  ListArrowDown2 as ReListArrowDown2, ListArrowUp as ReListArrowUp, ListArrowUp2 as ReListArrowUp2, ListCheck as ReListCheck,
  ListCheck2 as ReListCheck2, ListCheck3 as ReListCheck3, ListDown as ReListDown, ListDown2 as ReListDown2,
  ListHeart as ReListHeart, ListHeart2 as ReListHeart2, ListSquare as ReListSquare, ListUp as ReListUp,
  ListUp2 as ReListUp2, ListX as ReListX, ListX2 as ReListX2, Loader as ReLoader,
  Lock as ReLock, Lock12 as ReLock12, Lock2 as ReLock2, Lock4 as ReLock4,
  LockCircle2 as ReLockCircle2, LockKeyhole as ReLockKeyhole, LockKeyhole2 as ReLockKeyhole2, LockKeyholeOpen as ReLockKeyholeOpen,
  LockKeyholeOpen2 as ReLockKeyholeOpen2, LockOpen as ReLockOpen, LockOpen2 as ReLockOpen2, LockPassword as ReLockPassword,
  LockPasswordOpen as ReLockPasswordOpen, LockSlash2 as ReLockSlash2, MagicWand as ReMagicWand, Maximize as ReMaximize,
  Maximize12 as ReMaximize12, Maximize212 as ReMaximize212, Maximize22 as ReMaximize22, Maximize3 as ReMaximize3,
  Maximize32 as ReMaximize32, Maximize42 as ReMaximize42, MaximizeCircle2 as ReMaximizeCircle2, MaximizeSquare as ReMaximizeSquare,
  MaximizeSquare2 as ReMaximizeSquare2, Menu as ReMenu, Microchip as ReMicrochip, Minimize as ReMinimize,
  Minus as ReMinus, Minus3 as ReMinus3, MinusCircle as ReMinusCircle, MinusCirlce2 as ReMinusCirlce2,
  MinusSquare as ReMinusSquare, MinusSquare3 as ReMinusSquare3, Monitor as ReMonitor, Mouse as ReMouse,
  Nodes as ReNodes, Notification as ReNotification, Notification12 as ReNotification12, Notification3 as ReNotification3,
  Package as RePackage, Paintbrush as RePaintbrush, Palette as RePalette, Password as RePassword,
  Password2 as RePassword2, Password3 as RePassword3, PasswordCheck2 as RePasswordCheck2, Pen as RePen,
  Pen2 as RePen2, Pen3 as RePen3, PenAdd12 as RePenAdd12, PenAdd2 as RePenAdd2,
  Pin as RePin, PinOff as RePinOff, Play as RePlay, Plus as RePlus,
  Printer as RePrinter, Refresh as ReRefresh, Route as ReRoute, Router as ReRouter,
  Save22 as ReSave22, Scan2 as ReScan2, Scroll2 as ReScroll2, Search as ReSearch,
  SearchZoomIn2 as ReSearchZoomIn2, SearchZoomOut2 as ReSearchZoomOut2, Server as ReServer, ServerSquare as ReServerSquare,
  Settings as ReSettings, Settings2 as ReSettings2, Shield as ReShield, ShieldCheck as ReShieldCheck, Sidebar as ReSidebar,
  SidebarLeft2 as ReSidebarLeft2, SidebarRight2 as ReSidebarRight2, Sliders as ReSliders, TerminalCircle as ReTerminalCircle,
  TerminalSquare as ReTerminalSquare, Trash2 as ReTrash2, Unlock as ReUnlock, Upload as ReUpload,
  Usb as ReUsb, User as ReUser, Users as ReUsers, Video as ReVideo,
  Volume as ReVolume, Warehouse as ReWarehouse, Wifi as ReWifi, Window as ReWindow,
  X as ReX,
} from "reicon-react";
import { buildIconSearchGroups, iconSearchGroupsMatch } from "./iconSearchAliases";
import { LUCIDE_COMPAT_ICON_COMPONENTS } from "./reicon";
import {
  ICON_PICKER_NAMES,
  REICON_PICKER_ICON_NAMES,
} from "./reiconNames";
export {
  ICON_PICKER_NAMES,
  LUCIDE_FALLBACK_PICKER_ICON_NAMES,
  REICON_PICKER_ICON_NAMES,
} from "./reiconNames";

export type IconLibrarySource = "reicon" | "lucide";

export type ReiconSearchItem = {
  name: string;
  label: string;
  keywords: string[];
  searchText: string;
  Icon: IconComponent;
  source: IconLibrarySource;
};

const REICON_COMPONENTS = {
  "Activity2": ReActivity2, "AlertTriangle": ReAlertTriangle, "Archive": ReArchive, "Bell": ReBell,
  "BookOpen": ReBookOpen, "Bookmark": ReBookmark, "Box": ReBox, "Building": ReBuilding,
  "Buildings2": ReBuildings2, "Cabinet": ReCabinet, "Calendar": ReCalendar, "Camera": ReCamera, "ChartLine": ReChartLine, "Check": ReCheck,
  "CheckCircle": ReCheckCircle, "ChevronDown": ReChevronDown, "ChevronLeft": ReChevronLeft, "ChevronRight": ReChevronRight,
  "ChevronUp": ReChevronUp, "Clipboard": ReClipboard, "Cloud": ReCloud, "Code": ReCode,
  "Code2": ReCode2, "Command": ReCommand, "Copy": ReCopy, "Cpu": ReCpu,
  "Database": ReDatabase, "Document2": ReDocument2, "DocumentCode2": ReDocumentCode2, "DocumentText2": ReDocumentText2,
  "Download": ReDownload, "Edit2": ReEdit2, "Eye": ReEye, "EyeOff": ReEyeOff,
  "File": ReFile, "FileText": ReFileText, "FileUp": ReFileUp, "Folder": ReFolder,
  "FolderOpen": ReFolderOpen, "FolderFiles": ReFolderFiles, "Gauge3": ReGauge3, "Gear": ReGear,
  "Globe": ReGlobe, "Globe2": ReGlobe2, "Grid": ReGrid, "HardDrive": ReHardDrive,
  "HelpCircle": ReHelpCircle, "Home": ReHome, "Image": ReImage, "ImagePlus": ReImagePlus,
  "ImageUp": ReImageUp, "InfoCircle": ReInfoCircle, "Keyboard": ReKeyboard, "Key": ReKey,
  "Laptop": ReLaptop, "Layers": ReLayers, "Link": ReLink, "LinkBroken": ReLinkBroken,
  "List": ReList, "Loader": ReLoader, "Lock": ReLock, "LockKeyhole": ReLockKeyhole,
  "LockOpen": ReLockOpen, "MagicWand": ReMagicWand, "Maximize": ReMaximize, "Menu": ReMenu,
  "Microchip": ReMicrochip, "Minimize": ReMinimize, "Monitor": ReMonitor, "Mouse": ReMouse,
  "Nodes": ReNodes, "Package": RePackage, "Palette": RePalette, "Paintbrush": RePaintbrush,
  "PasswordCheck2": RePasswordCheck2, "Pin": RePin, "PinOff": RePinOff, "Play": RePlay,
  "Plus": RePlus, "Printer": RePrinter, "Refresh": ReRefresh, "Route": ReRoute,
  "Router": ReRouter, "Save22": ReSave22, "Scan2": ReScan2, "Scroll2": ReScroll2,
  "Search": ReSearch, "SearchZoomIn2": ReSearchZoomIn2, "SearchZoomOut2": ReSearchZoomOut2, "Server": ReServer,
  "ServerSquare": ReServerSquare, "Settings": ReSettings, "Settings2": ReSettings2, "Shield": ReShield, "ShieldCheck": ReShieldCheck,
  "Sliders": ReSliders, "Sidebar": ReSidebar, "SidebarLeft2": ReSidebarLeft2, "SidebarRight2": ReSidebarRight2,
  "TerminalCircle": ReTerminalCircle, "TerminalSquare": ReTerminalSquare, "Trash2": ReTrash2, "Unlock": ReUnlock,
  "Upload": ReUpload, "Usb": ReUsb, "User": ReUser, "Users": ReUsers,
  "Video": ReVideo, "Volume": ReVolume, "Warehouse": ReWarehouse, "Wifi": ReWifi,
  "Window": ReWindow, "X": ReX, "Alert": ReAlert, "AlertCircle": ReAlertCircle,
  "AlertCircle2": ReAlertCircle2, "AlertSquare": ReAlertSquare, "AlertTriangle2": ReAlertTriangle2, "BellAlert": ReBellAlert,
  "BellOff": ReBellOff, "BellOff2": ReBellOff2, "BellRing": ReBellRing, "Help": ReHelp,
  "HelpSquare": ReHelpSquare, "InfoCircle3": ReInfoCircle3, "Information2": ReInformation2, "InfoSquare": ReInfoSquare,
  "Notification": ReNotification, "Notification12": ReNotification12, "Notification3": ReNotification3, "Add2": ReAdd2,
  "AddCircle2": ReAddCircle2, "Additem2": ReAdditem2, "AddressBook": ReAddressBook, "AddressCard": ReAddressCard,
  "AddSquare2": ReAddSquare2, "ArrowRotate": ReArrowRotate, "ArrowsRotate": ReArrowsRotate, "Check3": ReCheck3,
  "CheckList": ReCheckList, "Checklist2": ReChecklist2, "ChecklistAlt": ReChecklistAlt, "CheckListSquare": ReCheckListSquare,
  "CheckRead": ReCheckRead, "CheckSquare": ReCheckSquare, "Clipboard3": ReClipboard3, "ClipboardAdd": ReClipboardAdd,
  "ClipboardCheck": ReClipboardCheck, "ClipboardClose2": ReClipboardClose2, "ClipboardExport2": ReClipboardExport2, "ClipboardHeart": ReClipboardHeart,
  "ClipboardImport2": ReClipboardImport2, "ClipboardList": ReClipboardList, "ClipboardRemove": ReClipboardRemove, "ClipboardSlash": ReClipboardSlash,
  "ClipboardText": ReClipboardText, "ClipboardText3": ReClipboardText3, "ClipboardTick2": ReClipboardTick2, "CloseCircle2": ReCloseCircle2,
  "CloseSquare2": ReCloseSquare2, "Closet": ReCloset, "Closet2": ReCloset2, "Copy3": ReCopy3,
  "Copyright": ReCopyright, "Copyright3": ReCopyright3, "CopySuccess2": ReCopySuccess2, "Download2": ReDownload2,
  "Download3": ReDownload3, "DownloadSquare": ReDownloadSquare, "DownloadSquare2": ReDownloadSquare2, "Edit22": ReEdit22,
  "Minus": ReMinus, "Minus3": ReMinus3, "MinusCircle": ReMinusCircle, "MinusCirlce2": ReMinusCirlce2,
  "MinusSquare": ReMinusSquare, "MinusSquare3": ReMinusSquare3, "Pen": RePen, "Pen2": RePen2,
  "Pen3": RePen3, "PenAdd12": RePenAdd12, "PenAdd2": RePenAdd2, "AngleDown2": ReAngleDown2,
  "AngleDownCircle": ReAngleDownCircle, "AngleDownSquare": ReAngleDownSquare, "AngleLeft2": ReAngleLeft2, "AngleLeftCircle": ReAngleLeftCircle,
  "AngleLeftSquare": ReAngleLeftSquare, "AngleRight2": ReAngleRight2, "AngleRightCircle": ReAngleRightCircle, "AngleRightSquare": ReAngleRightSquare,
  "AnglesLeft": ReAnglesLeft, "AnglesLeft2": ReAnglesLeft2, "AnglesRight": ReAnglesRight, "AnglesRight2": ReAnglesRight2,
  "AngleUp2": ReAngleUp2, "AngleUpCircle": ReAngleUpCircle, "AngleUpSquare": ReAngleUpSquare, "Arrow2": ReArrow2,
  "Arrow22": ReArrow22, "Arrow32": ReArrow32, "ArrowBottom2": ReArrowBottom2, "ArrowCircleDown2": ReArrowCircleDown2,
  "ArrowCircleLeft2": ReArrowCircleLeft2, "ArrowCircleRight2": ReArrowCircleRight2, "ArrowCircleUp2": ReArrowCircleUp2, "ArrowDoorIn": ReArrowDoorIn,
  "ArrowDoorOut3": ReArrowDoorOut3, "ArrowDottedRotateAnticlockwise": ReArrowDottedRotateAnticlockwise, "ArrowDown": ReArrowDown, "ArrowDown12": ReArrowDown12,
  "ArrowDown2": ReArrowDown2, "ArrowDown22": ReArrowDown22, "ArrowDown3": ReArrowDown3, "ArrowDown5": ReArrowDown5,
  "ArrowDownCircle": ReArrowDownCircle, "ArrowDownLeft2": ReArrowDownLeft2, "ArrowDownLeftCircle": ReArrowDownLeftCircle, "ArrowDownLeftSquare": ReArrowDownLeftSquare,
  "ArrowDownRight2": ReArrowDownRight2, "ArrowDownRightCircle": ReArrowDownRightCircle, "ArrowDownRightSquare": ReArrowDownRightSquare, "ArrowDownSquare": ReArrowDownSquare,
  "ArrowLeft": ReArrowLeft, "ArrowLeft12": ReArrowLeft12, "ArrowLeft2": ReArrowLeft2, "ArrowLeft22": ReArrowLeft22,
  "Archive12": ReArchive12, "Archive2": ReArchive2, "Archive22": ReArchive22, "Archive4": ReArchive4,
  "ArchiveAdd2": ReArchiveAdd2, "ArchiveBook2": ReArchiveBook2, "ArchiveBox": ReArchiveBox, "ArchiveCheck": ReArchiveCheck,
  "ArchiveDown": ReArchiveDown, "ArchiveDown2": ReArchiveDown2, "ArchiveMinus2": ReArchiveMinus2, "ArchiveSlash2": ReArchiveSlash2,
  "ArchiveTick2": ReArchiveTick2, "ArchiveUp": ReArchiveUp, "ArchiveUp2": ReArchiveUp2, "Book": ReBook,
  "Book12": ReBook12, "Book2": ReBook2, "Book3": ReBook3, "Book4": ReBook4,
  "Book6": ReBook6, "BookBookmark": ReBookBookmark, "BookBookmark2": ReBookBookmark2, "Bookmark2": ReBookmark2,
  "Bookmark22": ReBookmark22, "Bookmark3": ReBookmark3, "Bookmark5": ReBookmark5, "BookmarkAdd": ReBookmarkAdd,
  "BookmarkCheck": ReBookmarkCheck, "BookmarkCircle": ReBookmarkCircle, "BookmarkMinus": ReBookmarkMinus, "BookmarkOpen": ReBookmarkOpen,
  "Bookmarks": ReBookmarks, "BookmarkSlash": ReBookmarkSlash, "BookmarkSquare": ReBookmarkSquare, "BookmarkSquare2": ReBookmarkSquare2,
  "BookmarkX": ReBookmarkX, "BookSaved2": ReBookSaved2, "BookSquare2": ReBookSquare2, "Document12": ReDocument12,
  "DocumentCloud2": ReDocumentCloud2, "DocumentCode22": ReDocumentCode22, "DocumentCopy2": ReDocumentCopy2, "DocumentDownload2": ReDocumentDownload2,
  "DocumentFavorite2": ReDocumentFavorite2, "DocumentFilter2": ReDocumentFilter2, "DocumentForward2": ReDocumentForward2, "DocumentLike2": ReDocumentLike2,
  "DocumentNormal2": ReDocumentNormal2, "DocumentPrevious2": ReDocumentPrevious2, "DocumentSketch2": ReDocumentSketch2, "DocumentText12": ReDocumentText12,
  "Bluetooth": ReBluetooth, "Bluetooth22": ReBluetooth22, "Bluetooth3": ReBluetooth3, "BluetoothCircle": ReBluetoothCircle,
  "BluetoothCircle3": ReBluetoothCircle3, "BluetoothRectangle2": ReBluetoothRectangle2, "BluetoothSquare": ReBluetoothSquare, "BluetoothWave": ReBluetoothWave,
  "BrowserTerminal": ReBrowserTerminal, "Cloud3": ReCloud3, "CloudAdd2": ReCloudAdd2, "CloudBolt": ReCloudBolt,
  "CloudBolt2": ReCloudBolt2, "CloudChange2": ReCloudChange2, "CloudCheck": ReCloudCheck, "CloudConnect": ReCloudConnect,
  "CloudConnection2": ReCloudConnection2, "CloudCross2": ReCloudCross2, "CloudDown2": ReCloudDown2, "CloudDownload": ReCloudDownload,
  "CloudDrizzle2": ReCloudDrizzle2, "CloudDrop": ReCloudDrop, "CloudDrops": ReCloudDrops, "CloudFile": ReCloudFile,
  "CloudFog2": ReCloudFog2, "CloudLightning2": ReCloudLightning2, "CloudMinus": ReCloudMinus, "CloudMinus3": ReCloudMinus3,
  "CloudNotif2": ReCloudNotif2, "CloudPlus": ReCloudPlus, "CloudPlus3": ReCloudPlus3, "CloudRain": ReCloudRain,
  "CloudRemove2": ReCloudRemove2, "Clouds": ReClouds, "CloudSnow": ReCloudSnow, "CloudSnow2": ReCloudSnow2,
  "CloudSnow4": ReCloudSnow4, "CloudStorage": ReCloudStorage, "CloudStorm": ReCloudStorm, "CloudSun": ReCloudSun,
  "CloudSun2": ReCloudSun2, "CloudSunny2": ReCloudSunny2, "CloudUp2": ReCloudUp2, "CloudUpload": ReCloudUpload,
  "CloudX": ReCloudX, "Code12": ReCode12, "Code4": ReCode4, "CodeCircle": ReCodeCircle,
  "CodeCircle3": ReCodeCircle3, "CodeFile": ReCodeFile, "CodeScan": ReCodeScan, "CodeSquare": ReCodeSquare,
  "Command3": ReCommand3, "CommandSquare2": ReCommandSquare2, "Cpu3": ReCpu3, "CpuBolt": ReCpuBolt,
  "CpuCharge2": ReCpuCharge2, "CpuSetting2": ReCpuSetting2, "Keyboard3": ReKeyboard3, "KeyboardOpen2": ReKeyboardOpen2,
  "Fingerprint": ReFingerprint, "Key2": ReKey2, "Key3": ReKey3, "Key5": ReKey5,
  "KeySquare": ReKeySquare, "KeySquare2": ReKeySquare2, "KeySquare3": ReKeySquare3, "KeySquare4": ReKeySquare4,
  "KeySquare5": ReKeySquare5, "KeySquare6": ReKeySquare6, "KeySquare8": ReKeySquare8, "Lock12": ReLock12,
  "Lock2": ReLock2, "Lock4": ReLock4, "LockCircle2": ReLockCircle2, "LockKeyhole2": ReLockKeyhole2,
  "LockKeyholeOpen": ReLockKeyholeOpen, "LockKeyholeOpen2": ReLockKeyholeOpen2, "LockOpen2": ReLockOpen2, "LockPassword": ReLockPassword,
  "LockPasswordOpen": ReLockPasswordOpen, "LockSlash2": ReLockSlash2, "Password": RePassword, "Password2": RePassword2,
  "Password3": RePassword3, "ExitFullscreen": ReExitFullscreen, "ExitFullscreenCircle": ReExitFullscreenCircle, "ExitFullscreenSquare": ReExitFullscreenSquare,
  "Fullscreen": ReFullscreen, "FullscreenCircle": ReFullscreenCircle, "FullscreenSquare": ReFullscreenSquare, "Grid12": ReGrid12,
  "Grid22": ReGrid22, "Grid32": ReGrid32, "Grid42": ReGrid42, "Grid52": ReGrid52,
  "Grid62": ReGrid62, "Grid72": ReGrid72, "Grid82": ReGrid82, "Grid92": ReGrid92,
  "GridCirclePlus": ReGridCirclePlus, "GridEdit2": ReGridEdit2, "GridEraser2": ReGridEraser2, "GridLock2": ReGridLock2,
  "List3": ReList3, "ListArrowDown": ReListArrowDown, "ListArrowDown2": ReListArrowDown2, "ListArrowUp": ReListArrowUp,
  "ListArrowUp2": ReListArrowUp2, "ListCheck": ReListCheck, "ListCheck2": ReListCheck2, "ListCheck3": ReListCheck3,
  "ListDown": ReListDown, "ListDown2": ReListDown2, "ListHeart": ReListHeart, "ListHeart2": ReListHeart2,
  "ListSquare": ReListSquare, "ListUp": ReListUp, "ListUp2": ReListUp2, "ListX": ReListX,
  "ListX2": ReListX2, "Maximize12": ReMaximize12, "Maximize212": ReMaximize212, "Maximize22": ReMaximize22,
  "Maximize3": ReMaximize3, "Maximize32": ReMaximize32, "Maximize42": ReMaximize42, "MaximizeCircle2": ReMaximizeCircle2,
  "MaximizeSquare": ReMaximizeSquare, "MaximizeSquare2": ReMaximizeSquare2, "Camera2": ReCamera2, "Camera3": ReCamera3,
  "Camera4": ReCamera4, "CameraAdd": ReCameraAdd, "CameraAdd2": ReCameraAdd2, "CameraAlt": ReCameraAlt,
  "CameraOff": ReCameraOff, "CameraRecord": ReCameraRecord, "CameraRotate": ReCameraRotate, "CameraSlash2": ReCameraSlash2,
  "CameraSquare": ReCameraSquare, "Gallery": ReGallery, "Gallery2": ReGallery2, "Gallery3": ReGallery3,
  "Gallery5": ReGallery5, "GalleryAdd": ReGalleryAdd, "GalleryAdd3": ReGalleryAdd3, "GalleryCheck": ReGalleryCheck,
  "GalleryCircle": ReGalleryCircle, "GalleryDownload": ReGalleryDownload, "GalleryEdit": ReGalleryEdit, "GalleryEdit3": ReGalleryEdit3,
  "GalleryExport2": ReGalleryExport2, "GalleryFavorite2": ReGalleryFavorite2, "GalleryImport2": ReGalleryImport2, "GalleryRemove": ReGalleryRemove,
  "GalleryRemove3": ReGalleryRemove3, "GallerySend": ReGallerySend, "GallerySlash2": ReGallerySlash2, "GalleryStar": ReGalleryStar,
  "GalleryTick2": ReGalleryTick2, "GalleryWide": ReGalleryWide, "Image3": ReImage3, "ImageCheck": ReImageCheck,
  "ImageDepth": ReImageDepth, "ImageDown": ReImageDown, "ImageMinus": ReImageMinus, "ImageMountain": ReImageMountain,
  "Images2": ReImages2, "ImageSparkle": ReImageSparkle, "Battery": ReBattery, "Battery3full2": ReBattery3full2,
  "BatteryCharge": ReBatteryCharge, "BatteryCharge2": ReBatteryCharge2, "BatteryCharging2": ReBatteryCharging2, "BatteryDisable2": ReBatteryDisable2,
  "BatteryEmpty12": ReBatteryEmpty12, "BatteryEmpty2": ReBatteryEmpty2, "BatteryFull": ReBatteryFull, "BatteryFull2": ReBatteryFull2,
  "BatteryFull4": ReBatteryFull4, "BatteryHalf": ReBatteryHalf, "BatteryHalf2": ReBatteryHalf2, "BatteryHigh": ReBatteryHigh,
  "BatteryLow": ReBatteryLow,
} as const satisfies Readonly<Record<string, IconComponent>>;

export function splitIconName(name: string) {
  return name
    .replace(/([a-z0-9])([A-Z])/g, "$1 $2")
    .replace(/([A-Za-z])([0-9])/g, "$1 $2")
    .replace(/([0-9])([A-Za-z])/g, "$1 $2")
    .split(/\s+/)
    .filter(Boolean);
}

export function iconLabelForName(name: string) {
  return splitIconName(name).join(" ");
}

export function iconKeywordsForName(name: string) {
  const tokens = splitIconName(name).map((token) => token.toLowerCase());
  return Array.from(new Set([name.toLowerCase(), ...tokens]));
}

export function getReiconIconComponent(name: string | null | undefined): IconComponent | null {
  if (!name) {
    return null;
  }
  const reiconComponents = REICON_COMPONENTS as Readonly<Record<string, IconComponent>>;
  const compatComponents = LUCIDE_COMPAT_ICON_COMPONENTS as Readonly<Record<string, IconComponent>>;
  return reiconComponents[name] ?? compatComponents[name] ?? null;
}

function createIconSearchItem(name: string): ReiconSearchItem | null {
  const Icon = getReiconIconComponent(name);
  if (!Icon) {
    return null;
  }
  const label = iconLabelForName(name);
  const keywords = iconKeywordsForName(name);
  const source: IconLibrarySource = (REICON_PICKER_ICON_NAMES as readonly string[]).includes(name) ? "reicon" : "lucide";
  return {
    name,
    label,
    keywords,
    searchText: [name, label, source, ...keywords].join(" ").toLowerCase(),
    Icon,
    source,
  };
}

export const REICON_SEARCH_ITEMS = ICON_PICKER_NAMES
  .map(createIconSearchItem)
  .filter((icon): icon is ReiconSearchItem => Boolean(icon));

export function searchReiconPickerIcons(query: string, language?: string, limit = 120) {
  const groups = buildIconSearchGroups(query, language);
  const scoreTokens = groups.flat();
  const source = groups.length === 0
    ? REICON_SEARCH_ITEMS
    : REICON_SEARCH_ITEMS
        .filter((icon) => iconSearchGroupsMatch(icon.searchText, groups))
        .sort((left, right) => scoreIcon(right, scoreTokens) - scoreIcon(left, scoreTokens));

  return source.slice(0, limit);
}

function scoreIcon(icon: ReiconSearchItem, tokens: string[]) {
  let score = 0;
  const name = icon.name.toLowerCase();
  const label = icon.label.toLowerCase();
  for (const token of tokens) {
    if (name === token) {
      score += 10;
    } else if (name.includes(token)) {
      score += 5;
    }
    if (label.includes(token)) {
      score += 3;
    }
    if (icon.keywords.some((keyword) => keyword === token || keyword.includes(token))) {
      score += 1;
    }
  }
  return score;
}
