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