"use strict";const t=require("react/jsx-runtime"),c=require("../vendor.cjs"),l=require("react"),x=require("../global.module.cjs"),n=require("../tools/tools.cjs"),D=function(P){const{as:k="div",className:g,contentClasses:v,disabled:p,dropOldClass:b,hideActiveOptions:I,onChange:u,options:B,placeholder:y,selectableCount:m,single:h,style:C,variables:O,...F}=P,W=(B??[]).map((e,s)=>({...e,id:e.id??s})),q=n.pickObjectProperties(v,["optionItem","selectButton"],!0),R=n.pickObjectProperties(v,["optionItem","selectButton"]),[j,$]=l.useState(!1),[i,A]=l.useState(W),{context:N,floatingStyles:H,refs:S}=c.useFloating({middleware:[c.size({apply({availableHeight:e,elements:s,rects:o}){Object.assign(s.floating.style,{maxHeight:`${Math.max(0,e)}px`,minWidth:`${o.reference.width}px`})}})],onOpenChange:$,open:j,whileElementsMounted:c.autoUpdate}),_=c.useClick(N,{enabled:!p}),E=c.useDismiss(N),{getFloatingProps:K,getReferenceProps:L}=c.useInteractions([_,E]),z=l.useMemo(()=>i.some(e=>n.isDefined(e.header,!0)),[i]),w=l.useMemo(()=>n.groupByProperty(i,"header"),[i]),d=l.useMemo(()=>{if(h){const e=i.find(s=>s.active);return e?[e]:[]}else return i.filter(e=>e.active)},[i,h]),M=l.useMemo(()=>d.length,[d.length]),f=l.useCallback(e=>{A(s=>s.map((o,r)=>({...o,active:h?r===e:r===e?!o.active:o.active})))},[h]),G=l.useCallback(e=>{const s=i.findIndex(o=>o.id===e.id);s!==-1&&f(s)},[f,i]),T=l.useMemo(()=>{const e=n.classx(!b&&`form-select ${x.treeStyles.brlMinH38px}`,p&&"bg-body-secondary",g),s=n.stylex((o,r)=>({tKey:n.convertBsKeyToVar(r)}),O,C);return{className:e,style:s,tabIndex:p?void 0:0}},[g,p,b,C,O]),a=n.processSlotClasses(q,{activeOption:n.classxWithOptions(null,"d-flex align-items-center badge text-bg-secondary",x.treeStyles.brlCursorDefault),bottomDivider:"dropdown-divider",clearIcon:n.classxWithOptions(null,"bi bi-x",x.treeStyles.brlCursorPointer),countDisplay:n.classxWithOptions(null,"align-self-center flex-shrink-0 text-secondary",x.treeStyles.brlScale75),floatingMenu:"overflow-y-auto dropdown-menu rounded-3 shadow show",header:"dropdown-header",mainContainer:n.classxWithOptions(null,typeof m=="number"&&"d-flex flex-wrap justify-content-between gap-2"),optionsContainer:"d-flex flex-wrap column-gap-2 row-gap-1",placeholder:"text-secondary user-select-none",topDivider:"dropdown-divider"});return l.useEffect(()=>{u==null||u(d.map(e=>e.id))},[d,u]),t.jsxs(k,{...L(),...F,...T,ref:S.setReference,children:[t.jsxs("div",{className:a.mainContainer,"data-slot-main-container":"",children:[t.jsx("div",{className:a.optionsContainer,"data-slot-options-container":"",children:y&&d.length===0?t.jsx("div",{className:a.placeholder,"data-slot-placeholder":"",children:y}):d.map(e=>t.jsxs("div",{className:a.activeOption,"data-slot-active-option":"",children:[e.text,t.jsx("i",{className:a.clearIcon,"data-slot-clear-icon":"",onClick:s=>{s.stopPropagation(),G(e)},tabIndex:-1})]},e.id))}),typeof m=="number"&&t.jsx("div",{className:a.countDisplay,"data-slot-count-display":"",children:`${M} / ${m}`})]}),j&&t.jsx(c.FloatingPortal,{children:t.jsx("ul",{"data-slot-floating-menu":"",ref:S.setFloating,...K(),className:a.floatingMenu,style:H,children:w.keys.map(e=>t.jsxs(l.Fragment,{children:[z&&t.jsx("li",{children:t.jsx("h6",{className:a.header,"data-slot-header":"",children:e})},e),w.groupedData[e].map(({index:s,item:o})=>{const r=n.processSlotClasses(R,{optionItem:n.classxWithOptions(null,o.active&&I&&"visually-hidden"),selectButton:n.classxWithOptions(null,"dropdown-item",o.active&&"active",(o.disabled||m===M)&&"disabled")});return t.jsxs(l.Fragment,{children:[o.divider==="top"&&t.jsx("li",{children:t.jsx("hr",{className:a.topDivider,"data-slot-top-divider":""})}),t.jsx("li",{className:r.optionItem,"data-slot-option-item":"",children:t.jsx("button",{className:r.selectButton,"data-slot-select-button":"",onClick:U=>{U.stopPropagation(),f(s)},type:"button",children:o.text})}),o.divider==="bottom"&&t.jsx("li",{children:t.jsx("hr",{className:a.bottomDivider,"data-slot-bottom-divider":""})})]},o.id)})]},e))})})]})};D.displayName="BRL.SelectMultiple";exports.SelectMultiple=D;
//# sourceMappingURL=select-multiple.cjs.map
