import{slicedToArray as e,defineProperty as o}from"../../../_virtual/_rollupPluginBabelHelpers.js";import t,{forwardRef as a,useRef as i,useState as r,useCallback as s,useMemo as n}from"react";import l from"classnames";import{Icon as c}from"@vibe/icon/mockedClassNames";import m from"../../hooks/useMergeRef.js";import{CloseSmall as d}from"@vibe/icons";import{getCSSVar as u}from"../../services/themes.js";import{ElementAllowedColor as p}from"../../utils/colors-vars-map.js";import{getElementColor as v}from"../../types/Colors.js";import f from"../Avatar/Avatar.js";import b from"../IconButton/IconButton.js";import g from"../Text/Text.js";import{getTestId as y,ComponentDefaultTestId as h}from"../../tests/testIds.js";import{AvatarType as j}from"../Avatar/AvatarConstants.js";import{withStaticProps as k}from"../../types/withStaticProps.js";import C from"../../hooks/useSetFocus/index.js";import{useClickableProps as N}from"@vibe/clickable/mockedClassNames";import x from"./Chips.module.scss.js";import{ComponentVibeId as S}from"../../tests/constants.js";var A=k(a((function(a,p){var j=a.className,k=a.avatarClassName,A=a.iconClassName,E=a.id,T=a.label,M=void 0===T?"":T,w=a.leftIcon,B=void 0===w?null:w,P=a.rightIcon,I=void 0===P?null:P,z=a.leftAvatar,H=void 0===z?null:z,L=a.rightAvatar,O=void 0===L?null:L,R=a.disabled,D=void 0!==R&&R,F=a.readOnly,_=void 0!==F&&F,U=a.allowTextSelection,q=void 0!==U&&U,G=a.color,J=void 0===G?"primary":G,K=a.iconSize,Q=void 0===K?18:K,V=a.onDelete,W=void 0===V?function(e,o){}:V,X=a.onMouseDown,Y=a.onClick,Z=a.noAnimation,$=void 0===Z||Z,ee=a.ariaLabel,oe=a.ariaHasPopup,te=void 0!==oe&&oe,ae=a.disableClickableBehavior,ie=void 0!==ae&&ae,re=a.leftAvatarType,se=void 0===re?"img":re,ne=a.rightAvatarType,le=void 0===ne?"img":ne,ce=a.showBorder,me=void 0!==ce&&ce,de=a.leftRenderer,ue=a.rightRenderer,pe=a.closeButtonAriaLabel,ve=void 0===pe?"Remove":pe,fe=a.noMargin,be=void 0!==fe&&fe,ge=a["data-testid"]||y(h.CHIP,E),ye=!(!Y&&!X||ie),he=!_&&!D,je=ee||"string"==typeof M&&M||"",ke=i(null),Ce=i(null),Ne=r(!1),xe=e(Ne,2),Se=xe[0],Ae=xe[1],Ee=s((function(){return Ae(!0)}),[]),Te=s((function(){return Ae(!1)}),[]),Me=C({ref:Ce}).isFocused,we=m(p,Ce),Be=l(x.chips,j,o(o(o(o(o({},x.disabled,D),x.noAnimation,$),x.withUserSelect,q),x.border,me),x.noMargin,be)),Pe=l(x.clickable,Be,o(o({},x.disabled,D),x.disableTextSelection,!q)),Ie=n((function(){return{backgroundColor:D?u("disabled-background-color"):ye&&(Se||Me)?v(J,!0,!0):v(J,!0)}}),[D,ye,Se,Me,J]),ze=s((function(e){e.stopPropagation(),W&&W(E,e)}),[E,W]),He=s((function(e){void 0!==Y&&e.target!==ke.current&&(e.preventDefault(),Y(e))}),[Y]),Le=N({onClick:He,onMouseDown:X,disabled:D,id:E,"data-testid":ge,ariaLabel:je,ariaHidden:!1,ariaHasPopup:te,ariaExpanded:!1},we),Oe=ye?Object.assign(Object.assign({},Le),{ref:we,className:Pe,style:Ie,onMouseEnter:Ee,onMouseLeave:Te}):{className:Be,"aria-label":je,style:Ie,ref:we,onClick:He,onMouseDown:X,id:E,"data-testid":ge,onMouseEnter:Ee,onMouseLeave:Te},Re="text"===se?{text:H}:{src:H},De="text"===se?{text:O}:{src:O};return t.createElement("div",Object.assign({},Oe,{"data-vibe":S.CHIPS}),H?t.createElement(f,Object.assign({withoutBorder:!0,className:l(x.avatar,x.left,k),customSize:18,type:se,key:E},Re)):null,B?t.createElement(c,{className:l(x.icon,x.left,A),iconType:"font",icon:B,iconSize:Q,ignoreFocusStyle:!0}):null,de&&t.createElement("div",{className:l(x.customRenderer,x.left)},de),t.createElement(g,{type:"text2",className:x.label},M),I?t.createElement(c,{className:l(x.icon,x.right,A),iconType:"font",icon:I,iconSize:Q,ignoreFocusStyle:!0}):null,O?t.createElement(f,Object.assign({withoutBorder:!0,className:l(x.avatar,x.right,k),customSize:18,type:le,key:E},De)):null,ue&&t.createElement("div",{className:l(x.customRenderer,x.right)},ue),he&&t.createElement(b,{size:"xxs",color:"on-primary-color",className:l(x.icon,x.close),ariaLabel:ve,hideTooltip:!0,icon:d,onClick:ze,"data-testid":"".concat(ge,"-close"),ref:ke}))})),{colors:p,avatarTypes:j});export{A as default};
//# sourceMappingURL=Chips.js.map
