import{defineProperty as e}from"../../../../../../_virtual/_rollupPluginBabelHelpers.js";import n,{useRef as t,useMemo as o,createRef as i}from"react";import r from"../../../../Chips/Chips.js";import{Flex as a}from"@vibe/layout/mockedClassNames";import{DialogContentContainer as l,Dialog as s}from"@vibe/dialog/mockedClassNames";import c from"../../../../../hooks/useItemsOverflow/useItemsOverflow.js";import d from"./MultiSelectedValues.module.scss.js";import u from"classnames";import m from"../Trigger/DropdownChip.js";function p(p){var f=p.selectedItems,h=p.onRemove,g=p.renderInput,v=p.disabled,C=p.readOnly,b=p.minVisibleCount,w=void 0===b?0:b,y=t(null),E=t(null),k=o((function(){return f.map((function(){return i()}))}),[f]),D=c({containerRef:y,itemRefs:k,gap:4,deductedSpaceRef:E,minVisibleCount:1===f.length?1:w}),N=D.visibleCount,O=D.hasMeasured,I=o((function(){var e=f.length>N?f.slice(N):[];return{hiddenItems:e,hiddenCount:e.length}}),[f,N]),j=I.hiddenItems,M=I.hiddenCount,P=o((function(){return function(){return n.createElement(l,null,n.createElement(a,{direction:"column",gap:"xs",align:"start",className:d.hiddenChipsDialog},j.map((function(e){return n.createElement(m,{key:"dropdown-chip-dialog-".concat(e.value),item:e,onDelete:function(){return h(e)},className:d.dialogChip,disabled:v,readOnly:C})}))))}}),[j,h,v,C]),R=o((function(){return f.map((function(t,o){var i=N>o;return n.createElement("div",{key:"dropdown-chip-visible-".concat(t.value),ref:k[o],className:u(e(e({},d.chipWrapperWithOverflow,void 0!==w),d.hiddenChip,!i)),"aria-hidden":!i,"data-testid":"dropdown-chip-".concat(t.value)},n.createElement(m,{item:t,onDelete:function(){return h(t)},disabled:v,readOnly:C,className:d.visibleChip}))}))}),[f,N,h,k,v,C,w]);return(null==f?void 0:f.length)?n.createElement(a,{align:"center",wrap:!1,gap:"xs",ref:y,className:u(d.containerWrapper,e(e({},d.singleChip,1===f.length),d.measuring,!O))},R,n.createElement(a,{ref:E,gap:"xs"},M>0&&n.createElement("div",{onClick:function(e){e.stopPropagation()},onKeyDown:function(e){e.stopPropagation()},onMouseDown:function(e){e.stopPropagation()}},n.createElement(s,{content:P,showTrigger:["click","enter"],hideTrigger:["clickoutside","enter"],position:"bottom",moveBy:{main:4},hideWhenReferenceHidden:!0,addKeyboardHideShowTriggersByDefault:!0},n.createElement(r,{label:"+ ".concat(M),readOnly:!0,noMargin:!0,ariaLabel:"+".concat(M,". ").concat(f.length-M," items are visible out of ").concat(f.length),"data-testid":"dropdown-overflow-counter",className:d.overflowCounter,onClick:function(){},onMouseDown:function(e){e.preventDefault()}}))),g&&n.createElement("div",{className:d.inputWrapper},g()))):null}export{p as default};
//# sourceMappingURL=MultiSelectedValues.js.map
