import React,{useCallback,useId,useMemo}from"react";import{defaultIconSecondaryColor,getHeroicon,setUniqueIds,toPascalCase}from"./Icon/utils";import*as IconComponents from"./Icon/components";import{convertTailwindClassToVar}from"./styles/colors/utils";import cn from"./utils/cn";const getHeroiconComponent=iconName=>{const match=iconName.match(/^icon-gui-(.+)-(outline|solid|mini|micro)$/);if(!match){return null}const[,heroiconName,variant]=match;const component=getHeroicon(heroiconName,variant);return component};const Icon=({name,size="0.75rem",color,secondaryColor,additionalCSS="",variant,...additionalAttributes})=>{const uniqueId=useId();const[lightSecondaryColor,darkSecondaryColor]=(secondaryColor??"").split(" dark:");const iconName=variant&&!name.endsWith(`-${variant}`)?`${name}-${variant}`:name;const LocalIconComponent=useMemo(()=>{return IconComponents[toPascalCase(iconName)]},[iconName]);const HeroiconComponent=useMemo(()=>{return LocalIconComponent?null:getHeroiconComponent(iconName)},[LocalIconComponent,iconName]);const setUniqueIdsRef=useCallback(el=>{setUniqueIds(el,uniqueId)},[uniqueId]);const iconSvg=useCallback((secondaryColor,isDark,isThemed)=>{if(LocalIconComponent){let secondaryColorValue;if(secondaryColor){secondaryColorValue=convertTailwindClassToVar(secondaryColor)}else if(defaultIconSecondaryColor(name)){secondaryColorValue=convertTailwindClassToVar(defaultIconSecondaryColor(name))}return React.createElement(LocalIconComponent,{className:cn({[`${color}`]:color},{[`${additionalCSS}`]:additionalCSS},{"hidden dark:block":secondaryColor&&!isDark&&isThemed},{"dark:hidden":secondaryColor&&isDark&&isThemed}),style:{width:size,height:size,...secondaryColorValue&&{"--ui-icon-secondary-color":secondaryColorValue}},...additionalAttributes,ref:setUniqueIdsRef})}if(HeroiconComponent){return React.createElement(HeroiconComponent,{className:cn({[`${color}`]:color},{[`${additionalCSS}`]:additionalCSS}),style:{width:size,height:size},...additionalAttributes})}},[LocalIconComponent,HeroiconComponent,iconName,size,color,additionalCSS,lightSecondaryColor,darkSecondaryColor,name]);if(lightSecondaryColor&&darkSecondaryColor){return React.createElement(React.Fragment,null,iconSvg(lightSecondaryColor,false,!!darkSecondaryColor),iconSvg(darkSecondaryColor,true,true))}else if(lightSecondaryColor){return iconSvg(lightSecondaryColor,false,!!darkSecondaryColor)}else{return iconSvg()}};export default Icon;
//# sourceMappingURL=Icon.js.map