"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const n=require("react/jsx-runtime"),m=require("react"),l=require("semantic-ui-react"),T="multi-select",p="single-select",j=Number.MIN_SAFE_INTEGER,x=v=>v==null?null:String(v),Y=v=>{const{allLabel:k,noneLabel:O,placeholder:E,options:r,current:N,onChange:s,useSingleColumn:_,enableTextSearch:S,filterType:u,allNoneSameBehaviour:A,hiddenFilters:h,value:o,closeOnSelect:C=!0,noneFunction:R,alphabeticalSort:z,ascOrder:H,...V}=v,d=u===T,I=Array.isArray(o)?o:N||[],f=(Array.isArray(I)?I.some(e=>e===j):!1)?I.filter(e=>e!==j):I,[a,$]=m.useState(""),F=(e,t)=>{if(u===T){const i=x(t),c=Array.isArray(f)?[...f]:[];let y=c.some(P=>x(P)===i)?c.filter(P=>x(P)!==i):[...c,t];return!A&&y.length===0&&(y=[j]),s&&s(e,y)}if(u===p)return s&&s(e,t);C&&g.current&&g.current.close()},K=()=>{const e=(r||[]).filter(t=>{var i;return S&&a&&a.trim().length>0&&t.text?(i=t.text)==null?void 0:i.toString().toLowerCase().includes(a.toLowerCase()):!0}).map(t=>t.value);d&&s&&s({},e),!d&&C&&g.current&&g.current.close()},U=e=>{if(R){R(e);return}else{if(!r)return[];const t=r.filter(i=>{var c;return S&&a&&a.trim().length>0&&i.text?(c=i.text)==null?void 0:c.toString().toLowerCase().includes(a==null?void 0:a.toString().toLowerCase()):!0});if(d&&s){const i=A?t.map(c=>c.value):[j];s({},i)}!d&&C&&g.current&&g.current.close()}},D=e=>{$(e)},b=m.useRef(!1);m.useEffect(()=>{if(!(!d||b.current)&&r&&r.length>0)if(!(Array.isArray(f)?f.length>0:!!f)&&s){b.current=!0;const t=r.map(i=>i.value);s({},t)}else b.current=!0},[d,r]),m.useEffect(()=>{if(d&&r&&r.length>0&&s){const e=r.map(t=>t.value);s({},e)}},[d]);const q=m.useMemo(()=>{if(u==p){const e=o?r==null?void 0:r.filter(t=>t.value==o)[0]:null;return e?`${E?E+" ":""}${e.text}`:""}else{const e=f?f.filter(i=>i==Number.MIN_SAFE_INTEGER?!1:h&&h.length>0?h.indexOf(i)==-1:!0).length:0,t=(r==null?void 0:r.filter(i=>h&&h.length>0?h.indexOf(i.id)==-1:!0).length)||0;return`${E} (${e}/${t})`}},[r,f,u]),g=m.useRef(null),M=q,L=typeof M=="string"?M:"",G=L&&L.length>0?L:E||"",w=m.useRef(void 0);m.useEffect(()=>{u===p&&w.current===void 0&&o!==void 0&&(w.current=o)},[u,o]);const B=u===p?o!=null&&o!==w.current:N&&N.length>0;return n.jsx(l.Dropdown,{...V,ref:g,fluid:!0,text:G,scrolling:!1,button:!0,icon:"angle down",multiple:d,search:!0,floating:!1,value:o,closeOnChange:C,...d?{renderLabel:()=>null}:{},className:`multiple ${B?"applied ":""}`,children:n.jsxs(l.Dropdown.Menu,{children:[u!=p&&n.jsxs(n.Fragment,{children:[n.jsx(l.Segment,{children:n.jsxs(l.Dropdown.Item,{children:[n.jsx(l.Label,{basic:!0,onClick:K,children:k})," ","|"," ",n.jsx(l.Label,{basic:!0,onClick:U,children:O})]})}),S&&n.jsxs(n.Fragment,{children:[n.jsx(l.Container,{children:n.jsx(l.Dropdown.Item,{children:n.jsx("div",{className:"ui action input",children:n.jsxs("div",{className:"ui input",children:[n.jsx("input",{className:"filter-search",value:a,placeholder:"Search...",onChange:e=>{e&&e.nativeEvent&&e.nativeEvent.stopImmediatePropagation&&e.nativeEvent.stopImmediatePropagation(),D(e.target.value)},onKeyDown:e=>{e&&e.nativeEvent&&e.nativeEvent.stopImmediatePropagation&&e.nativeEvent.stopImmediatePropagation()},onKeyUp:e=>{e&&e.nativeEvent&&e.nativeEvent.stopImmediatePropagation&&e.nativeEvent.stopImmediatePropagation()},onKeyPress:e=>{e&&e.nativeEvent&&e.nativeEvent.stopImmediatePropagation&&e.nativeEvent.stopImmediatePropagation()},onMouseDown:e=>{e.stopPropagation()},onClick:e=>{e.stopPropagation()},onFocus:e=>{e.stopPropagation()},type:"text",autoComplete:"off"}),n.jsx(l.Icon,{name:"remove",link:!0,className:"clear-icon ignore",onClick:e=>{D("")}})]})})})}),n.jsx(l.Divider,{})]})]}),n.jsx("br",{}),n.jsx(l.Container,{className:_?"dropdown-single-column":"",children:r==null?void 0:r.filter(e=>{var t;return S&&a&&a.trim().length>0&&e.text?(t=e.text)==null?void 0:t.toString().toLowerCase().includes(a.toLowerCase()):!0}).map(({value:e,text:t},i)=>n.jsxs(l.Dropdown.Item,{className:_?"dropdown-item-single-column":"",children:[u===p&&n.jsx(l.Radio,{checked:o==e,onChange:c=>{F(c,e)},label:t}),u===T&&n.jsx(l.Checkbox,{checked:f&&f.some(c=>x(c)===x(e)),onChange:()=>F(null,e),label:t})]},i))})]})})};exports.default=Y;
