import{objectWithoutProperties as e,slicedToArray as t,defineProperty as n,extends as o}from"../../../../../_virtual/_rollupPluginBabelHelpers.js";import i,{useState as a,useEffect as l,useCallback as r}from"react";import{components as s}from"react-select";import c from"classnames";import{useHiddenOptionsData as u}from"../../hooks/useHiddenOptionsData.js";import p from"../../../Counter/Counter.js";import{Dialog as m,DialogContentContainer as d}from"@vibe/dialog/mockedClassNames";import h from"../../../Chips/Chips.js";import f from"./MultiValueContainer.module.scss.js";var v=["children","selectProps"];function g(g){var C=g.children,E=g.selectProps,w=e(g,v),D=E.isDisabled,N=E.placeholder,P=E.inputValue,b=E.selectProps,y=void 0===b?{}:b,M=E.withMandatoryDefaultOptions,k=E.readOnly,O=y.selectedOptions,j=y.onSelectedDelete,S=y.isMultiline,x=y.popupsContainerSelector,A=y.size,T=y.dialogClassName,R=C[1],V=a(),B=t(V,2),H=B[0],I=B[1],F=a(!1),W=t(F,2),_=W[0],z=W[1],q=a(!1),G=t(q,2),J=G[0],K=G[1],L=0===O.length&&!P,Q=f["chip-with-input-wrapper"],U=c(S?f["multiselect-chip-multi-line"]:f["multiselect-chip-single-line-".concat(A)],n({},f["multiselect-chip-disabled"],D)),X=u({isMultiline:S,ref:H,chipClassName:U,chipWrapperClassName:Q,selectedOptionsCount:O.length,isCounterShown:_}),Y=X.overflowIndex,Z=X.hiddenOptionsCount;l((function(){z(Z>0)}),[Z]);var $=r((function(){K(!0)}),[]),ee=r((function(){K(!1)}),[]),te=r((function(e){j(e.value,{action:"remove-value",removedValue:e})}),[j]),ne=["primary","negative","positive"],oe=r((function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0,t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:O.length;return O.map((function(n,o){var a=ne.includes(n.chipColor)?n.chipColor:"primary";return o>=e&&t>o?i.createElement(h,{"data-testid":"value-container-chip",key:n.value,className:c(f.chips,U),noAnimation:!0,disabled:D,id:n.value,label:n.label,onDelete:function(){return te(n)},disableClickableBehavior:!0,onMouseDown:function(e){e.stopPropagation()},readOnly:k||M&&n.isMandatory,allowTextSelection:k,leftRenderer:n.leftRenderer,rightRenderer:n.rightRenderer,leftAvatar:n.leftAvatar,leftIcon:n.leftIcon,color:a}):null}))}),[O,U,D,k,M,te,A]);return i.createElement(s.ValueContainer,o({selectProps:E},w),i.createElement("div",{className:f["value-container"],onTouchEndCapture:function(e){e.stopPropagation()}},L&&i.createElement("div",{className:f["placeholder-container"]},i.createElement(s.Placeholder,w,N)),i.createElement("div",{className:c(f["value-container-chips"],n({},f["without-placeholder"],!L)),ref:function(e){return I(e)},"data-testid":"value-container-chips"},_?i.createElement(i.Fragment,null,oe(0,Y-1),i.createElement("div",{className:Q},oe(Y-1,Y),R),oe(Y)):i.createElement(i.Fragment,null,oe(0,O.length-1),i.createElement("div",{className:Q},oe(O.length-1),R))),i.createElement("div",null,_&&i.createElement(m,{content:function(){return i.createElement(d,{className:f.valueDialogContent,onMouseDown:function(e){e.stopPropagation()}},oe(Y))},containerSelector:x,tooltip:!0,showTrigger:"click",hideTrigger:"clickoutside",position:"bottom",moveBy:{main:5},wrapperClassName:T,onDialogDidShow:$,onDialogDidHide:ee},i.createElement(p,{kind:"line",prefix:"+",count:Z,counterClassName:c(f.dropdownCounter,n({},f.active,J)),onMouseDown:function(e){e.stopPropagation()},noAnimation:!0})))))}export{g as default};
//# sourceMappingURL=MultiValueContainer.js.map
