(self.webpackChunkunifiNetworkUi=self.webpackChunkunifiNetworkUi||[]).push([[9029],{879077:(e,t,l)=>{"use strict";l.d(t,{A:()=>_});var s=l(296540),n=l(469733),a=l(105925),r=l(459449),u=l(548950),o=l(510497),c=l(451919),i=l(778851),d=l(366702),m=l(187483),h=l(572112),f=l(458973),R=l(59308),E=l(639775),T=l(382915),b=l(883057),g=l(779185),S=l(71479),y=l(968154);const C=(0,S.A)("div")`
  // Raise above tabs in wifi scanner and wifi speed-test
  z-index: 1;
`,L=(0,S.A)(b.J)`
  &[aria-selected='true'] {
    background: ${({theme:{motifPalette:{neutral02:e}}})=>e};
  }
  &.hideSearchResultCount {
    > span:last-child {
      display: none;
    }
  }
`,A=({hideSearchResultCount:e=!1,...t})=>s.createElement(L,{...t,...e&&{className:"hideSearchResultCount"}}),M=(0,S.A)(g.F)`
  &[aria-selected='true'] {
    background: ${({theme:{motifPalette:{neutral02:e}}})=>e};
  }
`;function v(){return s.createElement(y.m,null,s.createElement("style",null,"\n        .multi-search-fix {\n          z-index: 25;\n        }\n    "))}const _=({lsKey:e,getInitialSuggestions:t,searchModelName:l,searchIndex:b,enabledColumns:g,records:S,recordIdKey:y,omitAllResults:L=!1,resultsLimit:_=1e4,onFocus:p,onBlur:w,onAddTag:N,onReset:O,onRemoveTag:$,initialTags:I,placeholder:k,hideSearchResultCount:U=!1,enableMinifiedView:x=!1})=>{const{formatMessage:Q}=(0,r.tz)(),F=(0,d.A)().width<h.A.M.TO,P=(0,s.useMemo)(()=>({width:x&&F?T.q1:T.Em,expandedWidth:x&&F?T.Em:void 0}),[x,F]),V=(0,s.useMemo)(()=>new Set(S),[S]),z=(0,s.useMemo)(()=>V.size||_,[V.size,_]),H=(0,n.useDispatch)(),q=(0,n.useSelector)(m.W1),B=(0,n.useSelector)(m.YL),W=(0,n.useSelector)(m.TP),D=(0,s.useMemo)(()=>(0,i.ns)(q,B,W),[W,B,q]),{usedPlaceholder:J,overflowTitleLabel:j,overflowTranslations:K,removeTagLabel:G,recentTermsLabel:Y,recentTermsTitle:Z,resetButton:X,searchResultsLabel:ee}=(0,s.useMemo)(()=>({usedPlaceholder:k||Q({id:"COMMON_SEARCH"}),overflowTitleLabel:Q({id:"MULTI_SEARCH_OVERFLOW_LABEL"}),overflowTranslations:{singular:`{0} ${Q({id:"MULTI_SEARCH_OVERFLOW_SINGULAR"})}`,plural:`{0} ${Q({id:"MULTI_SEARCH_OVERFLOW_PLURAL"})}`},removeTagLabel:Q({id:"MULTI_SEARCH_REMOVE_TERM"}),recentTermsLabel:Q({id:"MULTI_SEARCH_RECENT_TERMS_LABEL"}),recentTermsTitle:Q({id:"MULTI_SEARCH_RECENT_TERMS_TITLE"}),resetButton:Q({id:"COMMON_ACTION_RESET"}),searchResultsLabel:Q({id:"MULTI_SEARCH_RESULTS"})}),[k,Q]),te=(0,s.useMemo)(()=>`${c.TA.PERSIST}:${c.TA.NETWORK}.${D}.${e}`,[D,e]),le=(0,s.useMemo)(()=>{try{const e=JSON.parse(o.D.getItem(te));return e.length?e:null}catch(e){return null}},[te]),se=(0,n.useSelector)((0,s.useMemo)(()=>(0,R.f)(l),[l])),ne=(0,s.useMemo)(()=>le||(t instanceof Function?t():t)||[],[t,le]),[ae,re]=(0,s.useState)(()=>ne),[ue,oe]=(0,s.useState)({value:"",searchResults:[]}),ce=(0,s.useRef)(new Set(S.map(e=>e[y]))),ie=(0,s.useCallback)(e=>{const{id:t,tag:l}=e,s=[{id:t,label:l},...ae.filter(e=>e.id!==t)].slice(0,T.om);re(s),o.D.setItem(te,JSON.stringify(s))},[te,ae]),de=(0,s.useCallback)(e=>{const t=ae.filter(({id:t})=>t!==e);re(t),o.D.setItem(te,JSON.stringify(t))},[te,ae]);(0,s.useEffect)(()=>{const e=new Set,t=Array.from(V),l=t.length;for(let s=0;s<l;s+=1){const l=t[s];b.addAsync(l,void 0),e.add(l[y])}const s=Array.from(ce.current),n=s.length;for(let t=0;t<n;t+=1){const l=s[t];e.has(l)||b.removeAsync(l)}ce.current=e},[y,V,b]);const me=(0,s.useCallback)(()=>{oe(e=>({...e,value:""}))},[]),he=(0,s.useCallback)(()=>{oe({searchResults:[],value:""}),H((0,f.sV)(l)),O?.()},[H,O,l]),fe=(0,s.useCallback)(async e=>{N?.();const t=ue.searchResults?.find(({id:t})=>t===e);if(ue.searchResults.length>0&&t&&(H((0,f.tn)({modelName:l,id:t.id,fsQuery:t.fsQuery,result:t.result,label:t.tag})),ie(t),oe(e=>({...e,searchResults:[]}))),0===ue.searchResults.length&&e){const[t,s]=e.split("::"),n="all"===t?g:[t],a=await b.searchAsync({query:s,index:n,limit:z});H((0,f.tn)({modelName:l,id:e,fsQuery:(0,E.pR)(a,s,n),result:(0,E.UV)(a),label:s})),ie({id:e,tag:s})}},[ie,H,g,z,N,b,l,ue.searchResults]),Re=(0,s.useCallback)(e=>{H((0,f.W1)(l,e)),$?.(e)},[H,$,l]);(0,s.useEffect)(()=>{const e=se.length;if(e)for(let t=0;t<e;t+=1){const e=se[t],s=(0,E.UV)(b.search(e.fsQuery.query,z,{index:g,enrich:!0,limit:z}));(0,u._)(e.result,s)||H((0,f.P8)({...e,result:s,label:`${e.fsQuery.query}`,modelName:l}))}},[H,S]),(0,s.useEffect)(()=>{if(I){he();const e=I.length;for(let t=0;t<e;t+=1)fe(`${T.G_}${I[t]}`)}},[I]);const Ee=(0,s.useCallback)(e=>t=>{t.stopPropagation(),de(e)},[de]),Te=(0,s.useMemo)(()=>ae.map(({id:e,label:t})=>({id:e,label:s.createElement(M,{label:t,onRemove:Ee(e)})})),[Ee,ae]);return s.createElement(C,null,s.createElement(v,null),s.createElement(a.A,{dropdownPortalClassName:"multi-search-fix",placeholder:se.length?null:J,selectOnEnter:!0,onFocus:p,onBlur:w,onAddTag:fe,onChange:(e,t)=>{const n=b.search(t,z,{index:g,enrich:!0,limit:z}),a=(0,E.UV)(n),r=(0,E.Qp)(se),o=(0,E.lN)(n),c=1===o.length?o[0].field:T.Mv,i=[],d=(0,E.A1)(n,r,y),m=[],h=Object.keys(d),f=h.length;for(let e=0;e<f;e+=1){const t=h[e],l=Array.from(d[t]).slice(0,T.rw),s=l.length;for(let e=0;e<s;e+=1){const s=l[e],n={query:s,index:[t],limit:z},{result:a}=b.search(n)[0];m.push({id:`${t}::${s}`,fsQuery:n,query:s,count:(0,u.y)(...Object.values({...r,[t]:new Set([...r[t]||[],...a])})).size,result:new Set(a)})}}m.sort((e,t)=>t.count-e.count);const R=m.slice(0,T.NZ).length;for(let e=0;e<R;e+=1){const{query:t,count:n,id:a,result:r,fsQuery:u}=m[e];i.push({id:a,label:s.createElement(A,{label:s.createElement(s.Fragment,null,t),count:n,hideSearchResultCount:U}),fsQuery:u,tag:`${t}`,result:new Set(r),modelName:l})}const S=(0,u.y)(...Object.values({...r,[c]:new Set([...r[c]||[],...a])})),C={id:`${c}::${t}::inputString`,label:s.createElement(A,{label:s.createElement(s.Fragment,null,t),count:S.size,hideSearchResultCount:U}),fsQuery:(0,E.pR)(o,t),tag:`${t}`,result:a,modelName:l};if(0===S.size&&i.length>0){const{count:e,id:l,result:n,fsQuery:a}=m[0],[r]=l.split("::");C.id=`${r}::${t}`,C.result=n,C.fsQuery.index=[...a.index],C.label=s.createElement(A,{label:s.createElement(s.Fragment,null,t),count:e,hideSearchResultCount:U})}L||i.unshift(C),oe(""===t?{value:"",searchResults:[]}:{value:t,searchResults:i})},onClear:me,onReset:he,onRemoveTag:Re,overflowTitleLabel:j,overflowTranslations:K,removeTagLabel:G,recentTerms:Te,recentTermsLabel:Y,recentTermsTitle:Z,resetButton:X,searchResults:ue.searchResults,searchResultsLabel:ee,tags:se,value:ue.value,...P}))}},17809:()=>{}}]);