(self.webpackChunkunifiNetworkUi=self.webpackChunkunifiNetworkUi||[]).push([[78610],{671909(e,s,t){"use strict";t.d(s,{A:()=>p});var l=t(274934),r=t(602086),n=t(977872),a=t(432180),o=t(714165),u=t(743178),i=t(482748),c=t(607856),d=t(303853),h=t(470070),m=t(976458),f=t(588769),R=t(519182),T=t(228837),g=t(160306),b=t(814557),y=t(706993),S=t(404302),A=t(675520),E=t(247816);const C=(0,E.A)("div")`
  // Raise above tabs in wifi scanner and wifi speed-test
  z-index: 1;
`,L=(0,E.A)(A.J)`
  &[aria-selected='true'] {
    background: ${({theme:{themeName:e}})=>b.Ay[`desktop-color-neutral-02-${e}`]};
  }
  &.hideSearchResultCount {
    > span:last-child {
      display: none;
    }
  }
`,M=({hideSearchResultCount:e=!1,...s})=>(0,l.jsx)(L,{...s,...e&&{className:"hideSearchResultCount"}}),v=(0,E.A)(S.F)`
  &[aria-selected='true'] {
    background: ${({theme:{themeName:e}})=>b.Ay[`desktop-color-neutral-02-${e}`]};
  }
`;function w(){return(0,l.jsx)(y.m,{children:(0,l.jsx)("style",{children:"\n        .multi-search-fix {\n          z-index: 25;\n        }\n    "})})}var _=t(170936);const p=({lsKey:e,getInitialSuggestions:s,searchModelName:t,searchIndex:b,enabledColumns:y,records:S,recordIdKey:A,omitAllResults:E=!1,resultsLimit:L=1e4,onFocus:p,onBlur:x,onAddTag:N,onReset:O,onRemoveTag:$,initialTags:k,placeholder:I,hideSearchResultCount:j=!1,enableMinifiedView:U=!1})=>{const{formatMessage:Q}=(0,h.tz)(),F=(0,d.Ay)().width<f.A.M.TO,V=(0,r.useMemo)(()=>({width:U&&F?g.q1:g.Em,expandedWidth:U&&F?g.Em:void 0}),[U,F]),z=(0,r.useMemo)(()=>new Set(S),[S]),H=(0,r.useMemo)(()=>z.size||L,[z.size,L]),P=(0,n.wA)(),q=(0,n.d4)(m.W1),B=(0,n.d4)(m.YL),W=(0,n.d4)(m.TP),J=(0,r.useMemo)(()=>(0,u.ns)(q,B,W),[W,B,q]),{usedPlaceholder:D,overflowTitleLabel:K,overflowTranslations:G,removeTagLabel:Y,recentTermsLabel:Z,recentTermsTitle:X,resetButton:ee,searchResultsLabel:se}=(0,r.useMemo)(()=>({usedPlaceholder:I||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"})}),[I,Q]),te=(0,r.useMemo)(()=>`${i.TA.PERSIST}:${i.TA.NETWORK}.${J}.${e}`,[J,e]),le=(0,r.useMemo)(()=>{try{const e=JSON.parse(c.D.getItem(te));return e.length?e:null}catch{return null}},[te]),re=(0,n.d4)((0,r.useMemo)(()=>(0,T.f)(t),[t])),ne=(0,r.useMemo)(()=>le||(s instanceof Function?s():s)||[],[s,le]),[ae,oe]=(0,r.useState)(()=>ne),[ue,ie]=(0,r.useState)({value:"",searchResults:[]}),ce=(0,r.useRef)(new Set(S.map(e=>e[A]))),de=(0,r.useCallback)(e=>{const{id:s,tag:t}=e,l=[{id:s,label:t},...ae.filter(e=>e.id!==s)].slice(0,g.om);oe(l),c.D.setItem(te,JSON.stringify(l))},[te,ae]),he=(0,r.useCallback)(e=>{const s=ae.filter(({id:s})=>s!==e);oe(s),c.D.setItem(te,JSON.stringify(s))},[te,ae]);(0,r.useEffect)(()=>{const e=new Set,s=Array.from(z),t=s.length;for(let l=0;l<t;l+=1){const t=s[l];b.addAsync(t,void 0),e.add(t[A])}const l=Array.from(ce.current),r=l.length;for(let s=0;s<r;s+=1){const t=l[s];e.has(t)||b.removeAsync(t)}ce.current=e},[A,z,b]);const me=(0,r.useCallback)(()=>{ie(e=>({...e,value:""}))},[]),fe=(0,r.useCallback)(()=>{ie({searchResults:[],value:""}),P((0,_.sV)(t)),O?.()},[P,O,t]),Re=(0,r.useCallback)(async e=>{N?.();const s=ue.searchResults?.find(({id:s})=>s===e);if(ue.searchResults.length>0&&s&&(P((0,_.tn)({modelName:t,id:s.id,fsQuery:s.fsQuery,result:s.result,label:s.tag})),de(s),ie(e=>({...e,searchResults:[]}))),0===ue.searchResults.length&&e){const[s,l]=e.split("::"),r="all"===s?y:[s],n=await b.searchAsync({query:l,index:r,limit:H});P((0,_.tn)({modelName:t,id:e,fsQuery:(0,R.pR)(n,l,r),result:(0,R.UV)(n),label:l})),de({id:e,tag:l})}},[de,P,y,H,N,b,t,ue.searchResults]),Te=(0,r.useCallback)(e=>{P((0,_.W1)(t,e)),$?.(e)},[P,$,t]);(0,r.useEffect)(()=>{const e=re.length;if(e)for(let s=0;s<e;s+=1){const e=re[s],l=(0,R.UV)(b.search(e.fsQuery.query,H,{index:y,enrich:!0,limit:H}));(0,o._)(e.result,l)||P((0,_.P8)({...e,result:l,label:`${e.fsQuery.query}`,modelName:t}))}},[P,S]),(0,r.useEffect)(()=>{if(k){fe();const e=k.length;for(let s=0;s<e;s+=1)Re(`${g.G_}${k[s]}`)}},[k]);const ge=(0,r.useCallback)(e=>s=>{s.stopPropagation(),he(e)},[he]),be=(0,r.useMemo)(()=>ae.map(({id:e,label:s})=>({id:e,label:(0,l.jsx)(v,{label:s,onRemove:ge(e)})})),[ge,ae]);return(0,l.jsxs)(C,{children:[(0,l.jsx)(w,{}),(0,l.jsx)(a.A,{dropdownPortalClassName:"multi-search-fix",placeholder:re.length?null:D,selectOnEnter:!0,onFocus:p,onBlur:x,onAddTag:Re,onChange:(e,s)=>{const r=b.search(s,H,{index:y,enrich:!0,limit:H}),n=(0,R.UV)(r),a=(0,R.Qp)(re),u=(0,R.lN)(r),i=1===u.length?u[0].field:g.Mv,c=[],d=(0,R.A1)(r,a,A),h=[],m=new Set,f=Object.keys(d),T=f.length;for(let e=0;e<T;e+=1){const t=f[e],l=Array.from(d[t]).slice(0,g.rw),r=l.length;for(let e=0;e<r;e+=1){const r=l[e],n=Array.isArray(r)?r:[r];for(let e=0;e<n.length;e+=1){const l=n[e],r={query:l,index:[t],limit:H},{result:u}=b.search(r)[0];if(1===n.length||(0,R.V9)(l,s)){const e=`${t}::${l}`;m.has(e)||(m.add(e),h.push({id:e,fsQuery:r,query:l,count:(0,o.y)(...Object.values({...a,[t]:new Set([...a[t]||[],...u])})).size,result:new Set(u)}))}}}}h.sort((e,s)=>s.count-e.count);const S=h.slice(0,g.NZ).length;for(let e=0;e<S;e+=1){const{query:s,count:r,id:n,result:a,fsQuery:o}=h[e];c.push({id:n,label:(0,l.jsx)(M,{label:(0,l.jsx)(l.Fragment,{children:s}),count:r,hideSearchResultCount:j}),fsQuery:o,tag:`${s}`,result:new Set(a),modelName:t})}const C=(0,o.y)(...Object.values({...a,[i]:new Set([...a[i]||[],...n])})),L={id:`${i}::${s}::inputString`,label:(0,l.jsx)(M,{label:(0,l.jsx)(l.Fragment,{children:s}),count:C.size,hideSearchResultCount:j}),fsQuery:(0,R.pR)(u,s),tag:`${s}`,result:n,modelName:t};if(0===C.size&&c.length>0){const{count:e,id:t,result:r,fsQuery:n}=h[0],[a]=t.split("::");L.id=`${a}::${s}`,L.result=r,L.fsQuery.index=[...n.index],L.label=(0,l.jsx)(M,{label:(0,l.jsx)(l.Fragment,{children:s}),count:e,hideSearchResultCount:j})}E||c.unshift(L),ie(""===s?{value:"",searchResults:[]}:{value:s,searchResults:c})},onClear:me,onReset:fe,onRemoveTag:Te,overflowTitleLabel:K,overflowTranslations:G,removeTagLabel:Y,recentTerms:be,recentTermsLabel:Z,recentTermsTitle:X,resetButton:ee,searchResults:ue.searchResults,searchResultsLabel:se,tags:re,value:ue.value,...V})]})}},160574(){}}]);