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