import{slicedToArray as o,defineProperty as e}from"../../_virtual/_rollupPluginBabelHelpers.js";import{jsx as i,jsxs as s}from"react/jsx-runtime";import{forwardRef as t,useRef as a,useMemo as r,useCallback as l}from"react";import n from"classnames";import c from"../Icon/Icon.js";import d from"../../hooks/useMergeRefs.js";import m from"../Icon/Icons/components/CloseSmall.js";import{getCSSVar as u}from"../../services/themes.js";import{tagElementColorsNames as p,getTagElementColor as v}from"../../utils/colors-vars-map.js";import f from"../Avatar/Avatar.js";import b from"../IconButton/IconButton.js";import{getTestId as g}from"../../tests/testIds.js";import{TagsSize as j}from"./TagsConstants.js";import{AvatarType as h}from"../Avatar/AvatarConstants.js";import I from"../../hooks/useHover.js";import k from"../Clickable/ClickableWrapper.js";import{ComponentDefaultTestId as N}from"../../tests/constants.js";import O from"./Tags.module.scss.js";var T=t((function(t,T){var C,A,y=t.className,S=t.id,w=t.label,z=void 0===w?"":w,R=t.leftIcon,_=void 0===R?null:R,M=t.rightIcon,B=void 0===M?null:M,P=t.leftAvatar,D=void 0===P?null:P,F=t.rightAvatar,G=void 0===F?null:F,L=t.disabled,x=void 0!==L&&L,W=t.readOnly,H=void 0!==W&&W,X=t.allowTextSelection,Y=void 0!==X&&X,E=t.color,U=void 0===E?p.gradient_blue:E,q=t.iconSize,J=void 0===q?16:q,K=t.onDelete,Q=void 0===K?function(o,e){}:K,V=t.onMouseDown,Z=t.onClick,$=t.noAnimation,oo=void 0!==$&&$,eo=t.ariaLabel,io=t.isClickable,so=void 0!==io&&io,to=t.size,ao=void 0===to?"large":to,ro=t.outlined,lo=void 0!==ro&&ro,no=t.dataTestId||g(N.TAG,S),co=so&&(!!Z||!!V),mo=!H&&!x,uo=I(),po=o(uo,2),vo=po[0],fo=po[1],bo=a(null),go=a(null),jo=d({refs:[T,go,vo]}),ho=r((function(){var o;return o=x?u("disabled-background-color"):fo&&co?v(U,!0,!0):v(U,!0),lo?{"--outline-border-color-var":o}:{background:o}}),[x,fo,co,U,lo]),Io=l((function(o){o.stopPropagation(),Q&&Q(S,o)}),[S,Q]),ko=l((function(o){o.target!==bo.current&&Z&&(o.preventDefault(),Z(o))}),[Z]);return i("div",Object.assign({className:n(O.tagsWrapper,y,(C={},e(C,O.sizeSmall,"small"===ao),e(C,O.outlined,lo),C))},{children:i(k,Object.assign({isClickable:co,clickableProps:{onClick:ko,onMouseDown:V,disabled:x,ariaLabel:eo||z,className:O.clickableWrapper}},{children:s("div",Object.assign({ref:jo,className:n(O.tags,"tags--wrapper",y,(A={},e(A,O.disabled,x),e(A,O.withClose,mo),e(A,O.noAnimation,oo),e(A,O.withUserSelect,Y),A)),id:S,style:ho,"data-testid":no},{children:[D?i(f,{withoutBorder:!0,className:n(O.avatar,O.left),customSize:18,src:D,type:h.IMG},S):null,_?i(c,{className:n(O.icon,O.left),iconType:c.type.ICON_FONT,clickable:!1,icon:_,iconSize:J,ignoreFocusStyle:!0}):null,i("div",Object.assign({className:n(O.label,e({},O.white,"white"===U))},{children:z})),B?i(c,{className:n(O.icon,O.right),iconType:c.type.ICON_FONT,clickable:!1,icon:B,iconSize:J,ignoreFocusStyle:!0}):null,G?i(f,{withoutBorder:!0,className:n(O.avatar,O.right),customSize:16,src:G,type:h.IMG},S):null,mo&&i("div",Object.assign({className:n(O.icon,O.close)},{children:i(b,{size:j.XXS,color:b.colors.ON_PRIMARY_COLOR,ariaLabel:"Remove",hideTooltip:!0,icon:function(){return i("div",Object.assign({className:n(O.close,e({},O.closeOutlined,lo))},{children:i(m,{})}))},onClick:Io,dataTestId:"".concat(no,"-close"),ref:bo,kind:b.kinds.TERTIARY})}))]}))}))}))}));Object.assign(T,{sizes:j,defaultTestId:N.TAG,colors:p});var C=T;export{C as default};
