"use strict";(self.webpackChunkunifiNetworkUi=self.webpackChunkunifiNetworkUi||[]).push([[13243],{264963(e,t,a){a.d(t,{X2:()=>d,lX:()=>C,uC:()=>m});var E=a(516693),l=a(691189),n=a(742920),s=a(887831);const r=`${a(771805).w}/device/:mac:`,c=`${r}/replacement-candidates`,i=`${r}/replace?replacementDeviceMac=:replacement-mac:`,o=`${r}/replace`,C=(e={},t={})=>(0,l.Kd)("replacementCandidates",`${c.replace(":mac:",e.queryParams?.mac)}`,e.queryParams?.mac,e,{...t,idField:"mac"}),m=(e,t)=>a=>a((0,l.vB)(E.aC,null,null,s.A.POST,i.replace(":mac:",e).replace(":replacement-mac:",t),{},null,{})),d=e=>t=>t((0,l.vB)(E.aC,null,null,s.A.DELETE,o.replace(":mac:",e),{},null,{failureToast:()=>({icon:n.C.danger,message:"COMMON_UNKNOWN_ERROR"})}))},137625(e,t,a){a.d(t,{A:()=>i});var E=a(296540),l=a(353899),n=a(132196),s=a(372737),r=a(566723),c=a(916537);const i=({children:e=null,title:t,titleValues:a,message:i,messageValues:o,handleConfirm:C=()=>null,handleClose:m=()=>null,handleCancel:d,isOpen:u,buttonVariant:A="primary",cancelButtonVariant:N="tertiary",cancelButtonMessage:_="COMMON_ACTION_CANCEL",buttonMessage:M="COMMON_ACTION_CONFIRM",buttonDisabled:I=!1,position:T="top",offset:R,showHeaderClose:p=!1,contentClassName:v="",body:S,titleBody:D,className:O,rootClose:g=!1,footerActions:P})=>{const L=(0,E.useCallback)(e=>{u&&(e.stopPropagation(),e.key===s.U.ENTER?C():e.key===s.U.ESCAPE&&m(!1))},[u,C,m]);(0,E.useEffect)(()=>(window.addEventListener("keydown",L,!0),()=>{window.removeEventListener("keydown",L,!0)}),[L]);const h=(0,E.useCallback)(()=>{m(!1),d?.()},[m,d]),b=(0,E.useCallback)(()=>{m(!1),C()},[m,C]),k=(0,E.useMemo)(()=>[{text:E.createElement(c.sA,{id:_}),variant:N,onClick:h},{text:E.createElement(c.sA,{id:M}),disabled:I,variant:A,onClick:b}],[M,A,_,N,h,b,I]),w=(0,E.useCallback)(()=>{m(!1)},[m]),f=n.AH`
    ${t?"":`margin-top: ${r.xO}`}
  `;return E.createElement(l.A,{title:t?E.createElement(c.sA,{id:t,values:a}):D||null,...i?{body:E.createElement(E.Fragment,null,E.createElement(c.sA,{id:i,values:o}),S)}:{body:S},position:T,portal:!0,offset:R,actions:P||k,showHeaderClose:p,contentClassName:n.AH`
        ${f}
        ${v}
      `,onRequestClose:w,isOpen:u,allowOverflow:!0,rootClose:g,className:O},e)}},252093(e,t,a){a.d(t,{A:()=>r});var E=a(296540),l=a(271856),n=a(162420),s=a(916537);const r=({messageId:e,tooltipClassName:t,values:a,isInteractive:r,portal:c,variant:i="twoTone",size:o="medium"})=>E.createElement(l.A,{description:E.createElement(s.sA,{id:e,values:a}),width:210,isInteractive:r,portal:c,tooltipClassName:t},E.createElement(n.A,{isActive:!0,omitSvgMargin:!0,variant:i,size:o}))},211908(e,t,a){a.d(t,{A:()=>B});var E=a(469733),l=a(296540),n=a(353899),s=a(758649),r=a(742920),c=a(421130),i=a(675359),o=a(916537),C=a(801081),m=a(25553),d=a(87485),u=a(264963);var A,N,_=a(768195),M=a(546391);!function(e){e.EXISTING="existing",e.NEW="new"}(A||(A={})),function(e){e.MAC="mac",e.TYPE="type",e.MODEL="model"}(N||(N={}));var I,T=a(238761),R=a(271856),p=a(438628),v=a(162420),S=a(400261),D=a(874807);!function(e){e.DEVICE_REPLACEMENT_MODE="deviceReplacementMode",e.SET_DEVICE_REPLACEMENT_MODE="setDeviceReplacementMode",e.NEW_MAC="newMac",e.SET_NEW_MAC="setNewMac",e.EXISTING_MAC="existingMac",e.SET_EXISTING_MAC="setExistingMac",e.REPLACEMENT_CANDIDATES="replacementCandidates",e.ERROR="error",e.RESET_ERROR="resetError"}(I||(I={}));const O=(0,l.createContext)({[I.DEVICE_REPLACEMENT_MODE]:void 0,[I.SET_DEVICE_REPLACEMENT_MODE]:D.P1,[I.NEW_MAC]:void 0,[I.SET_NEW_MAC]:D.P1,[I.EXISTING_MAC]:void 0,[I.SET_EXISTING_MAC]:D.P1,[I.REPLACEMENT_CANDIDATES]:[],[I.ERROR]:void 0,[I.RESET_ERROR]:D.P1}),g=a(132196).AH`
  height: 54px;
`;var P=a(71479),L=a(566723),h=a(294303);const b=(0,P.A)(h.A)`
  align-items: center;
  gap: ${L.YC};
`,k=(0,l.memo)(()=>{const{newMac:e,setNewMac:t,error:a,resetError:E}=(0,l.useContext)(O),n=(0,l.useCallback)(({target:{value:e}})=>{t((0,S.Z)(e)),E()},[t,E]);return l.createElement(p.A,{className:g,value:e,onChange:n,onFocus:E,variant:"secondary",label:l.createElement(b,null,l.createElement(o.sA,{id:"COMMON_MAC_ADDRESS"}),l.createElement(R.A,{portal:!0,width:"100%",maxWidth:248,description:l.createElement(o.sA,{id:"DEVICE_REPLACEMENT_MAC_LOCATION"})},l.createElement(v.A,{isActive:!0}))),width:"100%",invalid:a})});var w=a(362412),f=a(6176);const V=(0,l.memo)(()=>{const{replacementCandidates:e,existingMac:t,setExistingMac:a,error:E,resetError:n}=(0,l.useContext)(O),s=(0,l.useMemo)(()=>e.map(({mac:e,model:t,name:a})=>({label:a,value:e,image:l.createElement(f.A,{model:t}),additionalInfo:e})),[e]),r=(0,l.useCallback)(({value:e})=>{a(String(e)),n()},[a,n]);return l.createElement(w.A.Sorted,{value:t,label:l.createElement(o.sA,{id:"COMMON_DEVICE"}),width:"100%",searchable:!0,onChange:r,onFocus:n,maxHeight:228,options:s,invalid:E})}),y=(0,P.A)(h.A)`
  flex-direction: column;
  gap: ${L.kc};
`,x=(0,l.memo)(()=>{const{replacementCandidates:e,deviceReplacementMode:t,setDeviceReplacementMode:a,resetError:E}=(0,l.useContext)(O),n=(0,l.useMemo)(()=>e.length?[{id:A.EXISTING,children:l.createElement(o.sA,{id:"COMMON_EXISTING"}),onChange:()=>{a(A.EXISTING),E()},checked:t===A.EXISTING},{id:A.NEW,children:l.createElement(o.sA,{id:"COMMON_NEW"}),onChange:()=>{a(A.NEW),E()},checked:t===A.NEW}]:[],[e.length,t,a,E]);return l.createElement(y,null,l.createElement(T.A,{direction:"row",items:n}),t===A.EXISTING?l.createElement(V,null):null,t===A.NEW?l.createElement(k,null):null)}),W=(0,P.A)(h.A)`
  align-items: center;
  gap: ${L.YC};
  width: fit-content;
`;var G=a(252093);const X={[_.gQ.INCOMPATIBLE_REPLACEMENT]:"DEVICE_REPLACEMENT_DEVICE_INCOMPATIBLE_REPLACEMENT_ERROR",[_.gQ.REPLACEMENT_ALREADY_ASSIGNED]:"DEVICE_REPLACEMENT_DEVICE_REPLACEMENT_ALREADY_ASSIGNED_ERROR"},$=({mac:e,hideTooltip:t=!1})=>{const{formatMessage:a}=(0,o.tz)(),c=(0,E.useDispatch)(),[N,T]=(0,l.useState)(!1),[R,p]=(0,l.useState)(!1),[v,S]=(0,l.useState)(A.NEW),[D,g]=(0,l.useState)(""),[P,L]=(0,l.useState)(""),[h,b]=(0,l.useState)(void 0),k=(0,E.useSelector)((0,l.useMemo)(()=>(e=>(0,C.Mz)((e=>(0,m.uh)((0,u.lX)({queryParams:{mac:e}})))(e),e=>(0,d.i6)(e)?.devices||[]))(e),[e])),w=(0,l.useCallback)(()=>{T(!0)},[]),f=(0,l.useCallback)(()=>{T(!1),g(""),L(""),p(!1),S(A.NEW),b(void 0)},[]),V=(0,l.useCallback)(()=>{switch(v){case A.EXISTING:return P;case A.NEW:return D;default:return}},[v,P,D]),y=(0,l.useCallback)(()=>{c((0,i.ox)({icon:r.C.success,message:"DEVICE_REPLACEMENT_DEVICE_SET",duration:3e3})),f()},[c,f]),$=(0,l.useCallback)(e=>{switch(e.apiData?.replacement_state){case _.gQ.INCOMPATIBLE_REPLACEMENT:case _.gQ.REPLACEMENT_ALREADY_ASSIGNED:b(a({id:X[e.apiData.replacement_state]}));break;default:c((0,i.ox)({icon:r.C.danger,message:"DEVICE_FAILED_TO_SET_REPLACEMENT_DEVICE",duration:3e3}))}},[c,a]),B=(0,l.useCallback)(()=>{p(!1)},[]),q=(0,l.useCallback)(()=>{p(!0),c((0,u.uC)(e,V())).then(y).catch($).finally(B)},[c,y,$,e,V,B]),U=(0,l.useMemo)(()=>Boolean(V().match(M.b8)),[V]),F=(0,l.useMemo)(()=>[{text:l.createElement(o.sA,{id:"COMMON_ACTION_CANCEL"}),variant:"tertiary",onClick:f},{text:l.createElement(o.sA,{id:"COMMON_ACTION_APPLY"}),variant:"primary",onClick:q,disabled:!U||R,loader:R?"spinner":void 0}],[f,q,U,R]),Y=(0,l.useCallback)(()=>{b(void 0)},[b]),H=(0,l.useMemo)(()=>({[I.DEVICE_REPLACEMENT_MODE]:v,[I.SET_DEVICE_REPLACEMENT_MODE]:S,[I.NEW_MAC]:D,[I.SET_NEW_MAC]:g,[I.EXISTING_MAC]:P,[I.SET_EXISTING_MAC]:L,[I.REPLACEMENT_CANDIDATES]:k,[I.ERROR]:h,[I.RESET_ERROR]:Y}),[v,D,P,k,h,Y]);return(0,l.useEffect)(()=>{c((0,u.lX)({queryParams:{mac:e}}))},[c,e]),l.createElement(O.Provider,{value:H},l.createElement(n.A,{allowOverflow:!0,title:l.createElement(o.sA,{id:"DEVICE_SET_REPLACEMENT_DEVICE"}),body:l.createElement(x,null),position:"top",portal:!0,actions:F,isOpen:N,onRequestClose:f},l.createElement(W,null,l.createElement(s.A,{type:"button",variant:"inline",size:"medium",onClick:w},l.createElement(o.sA,{id:"DEVICE_SET_REPLACEMENT_DEVICE"})),t?null:l.createElement(G.A,{messageId:"DEVICE_SET_REPLACEMENT_DEVICE_DESCRIPTION",variant:"outline"}))))},B=(0,l.memo)(({model:e,type:t,...a})=>(0,c.G)({type:t,model:e})?l.createElement($,{type:t,model:e,...a}):null)},842630(e,t,a){a.d(t,{A:()=>s});var E=a(296540),l=a(469733),n=a(602021);const s=({children:e=null})=>(0,l.useSelector)(n.EL)?null:E.createElement(E.Fragment,null,e)},421130(e,t,a){a.d(t,{G:()=>r});var E=a(780811),l=a(768195);const n=[l.bq.USW,l.bq.UAP,l.bq.USP],s=[l.W4.UDBA69F],r=({type:e,model:t})=>(n.includes(e)||s.includes(t))&&!(0,E.tNJ)({model:t})},400261(e,t,a){a.d(t,{Z:()=>l});var E=a(546391);const l=e=>e?e.replace(E.SD,"").replace(E.fA,"$&:").substring(0,17).toLowerCase():e}}]);