(self.webpackChunkunifiNetworkUi=self.webpackChunkunifiNetworkUi||[]).push([[9029],{879077:(e,t,l)=>{"use strict";l.d(t,{A:()=>_});var s=l(296540),n=l(469733),r=l(105925),a=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),g=l(883057),b=l(779185),S=l(71479),y=l(968154);const A=(0,S.A)("div")`
  // Raise above tabs in wifi scanner and wifi speed-test
  z-index: 1;
`,C=(0,S.A)(g.J)`
  &[aria-selected='true'] {
    background: ${({theme:{motifPalette:{neutral02:e}}})=>e};
  }
  &.hideSearchResultCount {
    > span:last-child {
      display: none;
    }
  }
`,L=({hideSearchResultCount:e=!1,...t})=>s.createElement(C,{...t,...e&&{className:"hideSearchResultCount"}}),M=(0,S.A)(b.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:g,enabledColumns:b,records:S,recordIdKey:y,omitAllResults:C=!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,a.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]),[re,ae]=(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},...re.filter(e=>e.id!==t)].slice(0,T.om);ae(s),o.D.setItem(te,JSON.stringify(s))},[te,re]),de=(0,s.useCallback)(e=>{const t=re.filter(({id:t})=>t!==e);ae(t),o.D.setItem(te,JSON.stringify(t))},[te,re]);(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];g.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)||g.removeAsync(l)}ce.current=e},[y,V,g]);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?b:[t],r=await g.searchAsync({query:s,index:n,limit:z});H((0,f.tn)({modelName:l,id:e,fsQuery:(0,E.pR)(r,s,n),result:(0,E.UV)(r),label:s})),ie({id:e,tag:s})}},[ie,H,b,z,N,g,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)(g.search(e.fsQuery.query,z,{index:b,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)(()=>re.map(({id:e,label:t})=>({id:e,label:s.createElement(M,{label:t,onRemove:Ee(e)})})),[Ee,re]);return s.createElement(A,null,s.createElement(v,null),s.createElement(r.A,{dropdownPortalClassName:"multi-search-fix",placeholder:se.length?null:J,selectOnEnter:!0,onFocus:p,onBlur:w,onAddTag:fe,onChange:(e,t)=>{const n=g.search(t,z,{index:b,enrich:!0,limit:z}),r=(0,E.UV)(n),a=(0,E.Qp)(se),o=(0,E.lN)(n),c=1===o.length?o[0].field:T.Mv,i=[],d=(0,E.A1)(n,a,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=Array.isArray(s)?s:[s];for(let e=0;e<n.length;e+=1){const l={query:n[e],index:[t],limit:z},{result:r}=g.search(l)[0];m.push({id:`${t}::${s}`,fsQuery:l,query:s,count:(0,u.y)(...Object.values({...a,[t]:new Set([...a[t]||[],...r])})).size,result:new Set(r)})}}}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:r,result:a,fsQuery:u}=m[e];i.push({id:r,label:s.createElement(L,{label:s.createElement(s.Fragment,null,t),count:n,hideSearchResultCount:U}),fsQuery:u,tag:`${t}`,result:new Set(a),modelName:l})}const S=(0,u.y)(...Object.values({...a,[c]:new Set([...a[c]||[],...r])})),A={id:`${c}::${t}::inputString`,label:s.createElement(L,{label:s.createElement(s.Fragment,null,t),count:S.size,hideSearchResultCount:U}),fsQuery:(0,E.pR)(o,t),tag:`${t}`,result:r,modelName:l};if(0===S.size&&i.length>0){const{count:e,id:l,result:n,fsQuery:r}=m[0],[a]=l.split("::");A.id=`${a}::${t}`,A.result=n,A.fsQuery.index=[...r.index],A.label=s.createElement(L,{label:s.createElement(s.Fragment,null,t),count:e,hideSearchResultCount:U})}C||i.unshift(A),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:()=>{}}]);