"use strict";(self.webpackChunkunifiNetworkUi=self.webpackChunkunifiNetworkUi||[]).push([[19564],{389612(e,t,n){n.d(t,{AM:()=>o,Sm:()=>s});var r=n(296540),l=n(694595),i=n(780811),a=n(837612),c=n(916537);const o=(e,t)=>{const n=new Set(e.power_sources.map(e=>e.client_psu_index)),r=t.psu_table?.findIndex((e,t)=>!n.has(t+1))??-1;return-1!==r?r+1:-1},s=(e,t)=>{const n=t?.includes(e.mac),o="device"===e.type&&(0,i.Daf)(e.device),s="device"===e.type&&!(0,l.K_)((0,a.S9)(e.device));return n?r.createElement(c.sA,{id:"COMMON_DEVICE_ALREADY_HAS_SUPERVISOR"}):s?r.createElement(c.sA,{id:"COMMON_SUPERVISOR_DEVICE_STATE_NOT_AVAILABLE"}):o?r.createElement(c.sA,{id:"COMMON_DEVICE_SUPERVISOR_MESHING_DISABLED_TOOLTIP"}):void 0}},963253(e,t,n){n.d(t,{A:()=>o});var r=n(822336),l=n(71479),i=n(566723),a=n(294303),c=n(311785);const o=(0,l.A)(a.A,(0,c.A)("selected","disabled","allowGreyscale","noMargin"))`
  height: 32px;
  border-radius: ${r.Ay["desktop-radius-base"]};
  padding: ${i.YC} ${i.kc};
  margin-right: ${({noMargin:e})=>e?0:i.kc};
  border: ${({theme:{themeName:e}})=>r.Ay[`desktop-border-divider-${e}`]};
  align-items: center;
  justify-content: center;
  cursor: pointer;
  gap: ${i.kc};
  user-select: none;

  ${({selected:e,theme:{themeName:t}})=>e&&`border-color: ${r.Ay[`desktop-color-ublue-06-${t}`]};`}
  ${({disabled:e,allowGreyscale:t,selected:n})=>e||t&&!n?`> * { opacity: ${i.xN}; }`:void 0}
  ${({disabled:e})=>e&&"pointer-events: none;"}
  ${({allowGreyscale:e,selected:t})=>e&&!t&&"filter: grayscale(100%);"}
`},553432(e,t,n){n.d(t,{A:()=>c});var r=n(296540),l=n(454195),i=n(566723),a=n(294303);const c=e=>r.createElement(a.A,{paddingTop:i.YC,paddingBottom:i.YC,gap:i.Ln,rowGap:i.YC,flexWrap:"wrap",minHeight:l.b,alignItems:"center",...e})},519564(e,t,n){n.r(t),n.d(t,{default:()=>oe});var r=n(82960),l=n(469733),i=n(296540),a=n(951272),c=n(217439),o=n(71479),s=n(74750),m=n(592563),d=n(429252),u=n.n(d),p=n(180524),_=n(742920),E=n(870443),A=n(960407),v=n(860631),O=n(566723),C=n(143811),S=n(294303),w=n(845030),b=n(916537),h=n(170163),g=n(780811),M=n(171073),f=n(532419),N=n(286818),y=n(6510),I=n(317672),x=n(678419),D=n(223792),R=n(389612),T=n(416381),k=n(592510),P=n(816260),L=n(553432),$=n(945132),Y=n(451919),V=n(510497),U=n(92069),W=n(792042),z=n(239417),F=n(822336),G=n(382389),j=n(624070),K=n(757167),H=n(766624),B=n(963253),Q=n(124229),q=n(923515),X=n(837612),Z=n(641777),J=n(694595);const ee=(0,o.A)(S.A)`
  border: 1px solid ${({theme:{themeName:e}})=>F.Ay[`desktop-color-neutral-03-${e}`]};
  border-radius: 0 0 ${O.YC} ${O.YC};
  padding: ${O.kc};
`,te=(0,o.A)(S.A)`
  border: 1px solid ${({theme:{themeName:e}})=>F.Ay[`desktop-color-neutral-03-${e}`]};
  padding: ${O.kc};
`,ne=(0,o.A)("div")`
  div[class*='input__'] {
    margin-right: 0;
  }
`,re=(0,i.memo)(({linkedDeviceMac:e,outletInfo:t})=>{const{values:n,setFieldValue:r}=(0,a.j7)(),o=(0,l.useSelector)((0,f.tG)(e)),{themeName:s}=(0,G.u)(),m=!!o&&(0,g.Daf)(o),d=!!o&&!(0,J.K_)((0,X.S9)(o)),u=n.powerSupervisor.power_sources.find(e=>e.power_source_index===t.index),_=(0,i.useMemo)(()=>{const e=n.powerSupervisor.power_sources.map(e=>e.client_psu_index),t=o?.psu_table?.flatMap((t,n)=>e.includes(n+1)?[]:[n+1]);return[...t||[],u?.client_psu_index]},[o?.psu_table,n.powerSupervisor.power_sources,u?.client_psu_index]),E=(0,i.useCallback)(e=>_?.includes(e),[_]),A=(0,i.useMemo)(()=>m||d,[m,d]);return o?i.createElement(S.A,{flexDirection:"column",gap:4},o.psu_table&&o.psu_table.length>1?i.createElement(te,{flexDirection:"column",gap:O.kc},i.createElement(S.A,{flexDirection:"row",gap:O.YC,alignItems:"center",justifyContent:"space-between"},i.createElement(S.A,{gap:O.kc,width:"100%"},o.psu_table?.map((e,l)=>i.createElement(p.A,{key:e.index,description:E(l+1)?null:i.createElement(b.sA,{id:"COMMON_PSU_NOT_AVAILABLE_DESCRIPTION"})},i.createElement("div",{style:{width:"100%"}},i.createElement(B.A,{width:"100%",disabled:!E(l+1),style:{margin:0},selected:u?.client_psu_index===l+1,onClick:()=>{(e=>{const l=n.powerSupervisor.power_sources.map(n=>n.power_source_index===t.index?{...n,client_psu_index:e}:n);r("powerSupervisor.power_sources",l)})(l+1)}},i.createElement(c.A,{size:"medium"},e.label?(0,K.OU)(e.label):`PSU ${l+1}`)))))))):null,i.createElement(ee,{width:"100%"},i.createElement(S.A,{flexDirection:"column",gap:O.kc,width:"100%"},i.createElement(S.A,{justifyContent:"space-between",width:"100%"},i.createElement(S.A,{gap:O.YC},i.createElement(j.A,{color:F.Ay[`desktop-color-aqua-06-${s}`],variant:"fill",size:"original"}),i.createElement(c.A,{color:"text-2"},i.createElement(b.sA,{id:"COMMON_POWER_SUPERVISOR"})),i.createElement(H.A,{description:i.createElement(b.sA,{id:"COMMON_POWER_SUPERVISOR_DESCRIPTION"})})),i.createElement(q.A,{isMeshing:m,isNotReady:d},i.createElement(ne,null,i.createElement(C.A,{type:"checkbox",name:"powerSupervisor.enabled",size:"small",disabled:!n?.powerSupervisor?.enabled&&A})))),n.powerSupervisor.enabled?i.createElement(q.A,{isMeshing:m,isNotReady:d},i.createElement(Z.A,{isDisabled:A},i.createElement(Q.D,null))):null))):null});var le=n(194015),ie=n(268892);const ae=(0,o.A)(c.A)`
  margin-bottom: ${O.YC};
`,ce=(0,a.bk)({enableReinitialize:!0,mapPropsToValues:({outletInfo:{name:e,cycle_enabled:t,relay_state:n},powerSupervisor:r,devices:l})=>({name:r?.client_mac?(0,y.Q)(l.find(e=>e.mac===r.client_mac))||e||"":e||"",cycle_enabled:t,relay_state:n,powerSupervisor:r?.id?{id:r.id,site_id:r.site_id||"",enabled:r.enabled??!1,client_mac:r.client_mac||"",power_sources:r.power_sources||[],settings:r.settings||P.R4}:U.be}),validationSchema:E.A.object().shape({name:E.A.string().label("COMMON_NAME").max(128),cycle_enabled:E.A.boolean(),relay_state:E.A.boolean(),linked_device_mac:E.A.string()}),handleSubmit:(e,{props:{outletInfo:t,updateDeviceWithIdEndpoint:n,activeItem:r,activeItem:{mac:l,_id:i,outlet_overrides:a},onSubmitSuccess:c,powerSupervisor:o,dispatch:s},setSubmitting:m})=>{const d=[],{powerSupervisor:p,...E}=e,A=t.index??0,v=0===p.power_sources.length;v&&d.push(s((0,T.tI)(p.id)));const O=!o&&"new"!==p.id,C=o&&!u()(o,p);if(!O&&!C||v||d.push(s((0,T.TG)(p))),"new"===p.id){const{id:e,site_id:t,...n}=p;d.push(s((0,T.G)(n)))}return d.push(s(n({outlet_overrides:[...(a||[]).filter(e=>e.index!==A),{index:A,...E}].map(e=>A===(0,h.eq)(e,(0,g.Tl7)(r))?{...e,relay_state:E.relay_state}:e).sort((e,t)=>(e.index||0)-(t.index||0))},i,l,{failureToast:{icon:_.C.danger,message:"DEVICE_OUTLET_FORM_SAVE_ERROR"},mergeAndOverrideKeys:["outlet_overrides"],extend:!0}))),Promise.all(d).then(()=>{s((0,T.pX)()),m(!1),c?.()}).catch(e=>{throw m(!1),e})}}),oe=(0,r.Zz)((0,l.connect)((e,{activeItem:t,isInSection:n,subId:r})=>{const l=n?+r:+((0,A.Oh)(e)||0);return{outletInfo:(0,h.o3)(t,void 0,l),powerSupervisor:(0,x.qO)(t.mac,l)(e),propertyPanelActiveItemTab:(0,A.oI)(e),devices:(0,N.RM)(e)}},e=>({updateDeviceWithIdEndpoint:M.ex,showPropertyPanel:w.XP,dispatch:e})),ce)(({dirty:e,submitForm:t,outletInfo:n,activeItem:r,onFormCancel:o})=>{const{values:d,setFieldValue:u}=(0,a.j7)(),_=(0,l.useDispatch)(),E=(0,l.useSelector)(N.RM),A=(0,l.useSelector)(x.Lr),w=(0,l.useSelector)(f.m9),h=(0,l.useSelector)(le.f),g=(0,l.useSelector)(f.Kh),P=(0,l.useSelector)(z.Cx),U=(0,i.useMemo)(()=>d.powerSupervisor.power_sources.find(e=>e.power_source_index===n.index&&e.power_source_mac===r.mac),[d.powerSupervisor.power_sources,n.index,r.mac]),[F,G]=(0,i.useState)(!1),[j,K]=(0,i.useState)(0);(0,i.useEffect)(()=>{_((0,T.pX)(void 0,{crudCacheStrategy:{type:k.e.CACHE}}))},[_]);const H=(0,i.useCallback)((e,t)=>`${Y.lP.OUTLET_POWER_CYCLE_COOLDOWN}-${e}-${t??"na"}`,[]),B=(0,i.useCallback)(e=>{try{const t=V.u.getItem(e);if(!t)return null;const n=Number.parseInt(t,10);return Date.now()>=n?(V.u.removeItem(e),null):n}catch{return null}},[]),Q=(0,i.useCallback)((e,t)=>{try{V.u.setItem(e,t.toString()),K(e=>e+1)}catch{}},[]),q=(0,i.useCallback)(()=>{const e=H(r.mac,n.index),t=Date.now()+5*$.vl;Q(e,t),_((0,M.t)(r,n))},[r,n,_,H,Q]),X=(0,i.useMemo)(()=>H(r.mac,n.index),[r.mac,n.index,H]),Z=(0,i.useMemo)(()=>null!==B(X),[X,B,j]);(0,i.useEffect)(()=>{const e=B(X);if(null===e)return;const t=e-Date.now();if(t<=0)return void K(e=>e+1);const n=setTimeout(()=>{K(e=>e+1)},t);return()=>clearTimeout(n)},[X,B,j]);const ee=(0,i.useCallback)(e=>{const t=E.find(t=>t.mac===e),l=A.find(t=>t.client_mac===e);let i=1;l&&(i=(0,R.AM)(l,t));const a={power_source_mac:r.mac,power_source_type:D.F.OUTLET,power_source_index:n.index,client_psu_index:i};u("powerSupervisor",{...d.powerSupervisor,...l,power_sources:[...l?.power_sources||[],a]}),u("powerSupervisor.client_mac",e),u("name",(0,y.Q)(t)),G(!1)},[r.mac,E,n.index,A,u,d.powerSupervisor]),te=(0,i.useCallback)(()=>{const e=d.powerSupervisor.power_sources.filter(e=>e.power_source_index!==n.index);u("powerSupervisor.power_sources",e),u("name",`Outlet ${n.index}`),G(!1)},[n.index,u,d.powerSupervisor.power_sources]),ne=(0,i.useCallback)(e=>{e?ee(e):te()},[ee,te]),ce=(0,i.useMemo)(()=>{const e=A.map(e=>e.client_mac);return h.filter(e=>e.mac===d.powerSupervisor?.client_mac||e.mac!==r.mac&&!(0,ie.g)(e.mac,g,P,E)).map(t=>({supervisableDevice:t,disabledReason:(0,R.Sm)(t,e)}))},[r.mac,P,E,g,A,h,d.powerSupervisor.client_mac]);return i.createElement(i.Fragment,null,i.createElement(S.A,{flexDirection:"column",gap:O.kc},(0,J.AP)(n)?i.createElement(i.Fragment,null,F?i.createElement(W.A,{value:U?d.powerSupervisor.client_mac:void 0,onChange:ne,options:ce}):U?i.createElement(W.A,{value:d.powerSupervisor.client_mac,onChange:ne,options:ce}):i.createElement(s.A,{variant:"secondary-emphasis",style:{width:"100%"},onClick:()=>G(!0)},i.createElement(b.sA,{id:"COMMON_LINK_DEVICE"})),U?i.createElement(re,{linkedDeviceMac:d.powerSupervisor.client_mac,outletInfo:n}):null):null,U?null:i.createElement(C.A,{full:!0,name:"name",variant:"secondary",label:"COMMON_NAME"}),i.createElement(m.A,{type:"button",fontSize:"medium",style:{alignSelf:"flex-start"},onClick:q,isDisabled:Z},i.createElement(b.sA,Z?{id:"DEVICE_ACTIONS_POWER_CYCLE_IN_PROGRESS"}:{id:"COMMON_POWER_CYCLE"})),i.createElement(S.A,{flexDirection:"column"},i.createElement(I.A,null,i.createElement(b.sA,{id:"COMMON_OUTLET"})),i.createElement(L.A,null,i.createElement(C.A,{type:"radio",name:"relay_state",value:!0},i.createElement(b.sA,{id:"COMMON_ACTIVE"})),i.createElement(C.A,{type:"radio",name:"relay_state",value:!1},i.createElement(b.sA,{id:"COMMON_DISABLED"})))),i.createElement(p.A,{description:w?void 0:i.createElement(b.sA,{id:"COMMON_REQUIRES_GATEWAY"})},i.createElement(S.A,{marginBottom:O.kc},i.createElement(C.A,{type:"realCheckbox",name:"cycle_enabled",disabled:!w,tooltipMessage:i.createElement(b.sA,{id:"COMMON_POWER_CYCLE_ON_INTERNET_LOSS_DESCRIPTION"})},i.createElement(b.sA,{id:"COMMON_POWER_CYCLE_ON_INTERNET_LOSS"})))),(0,v.TT)(n,"POWER_METER")?i.createElement(S.A,{flexDirection:"column",justifyContent:"space-between",width:"100%",gap:O.kc},n.outlet_power?i.createElement(S.A,{justifyContent:"space-between"},i.createElement(ae,null,i.createElement(b.sA,{id:"COMMON_POWER"})),i.createElement(c.A,{color:"text-3"},i.createElement(b.sA,{id:"COMMON_UNIT_WATTS_SHORT",values:{value:Number(n.outlet_power).toFixed(2)}}))):null,n.outlet_current?i.createElement(S.A,{justifyContent:"space-between"},i.createElement(ae,null,i.createElement(b.sA,{id:"COMMON_CURRENT"})),i.createElement(c.A,{color:"text-3"},i.createElement(b.sA,{id:"COMMON_UNIT_AMPERES_SHORT",values:{value:Number(n.outlet_current||0).toFixed(2)}}))):null,n.outlet_voltage?i.createElement(S.A,{justifyContent:"space-between"},i.createElement(ae,null,i.createElement(b.sA,{id:"COMMON_VOLTAGE"})),i.createElement(c.A,{color:"text-3"},i.createElement(b.sA,{id:"COMMON_UNIT_VOLTAGE_SHORT",values:{value:Number(n.outlet_voltage).toFixed(2)}}))):null,n.outlet_power_factor?i.createElement(S.A,{justifyContent:"space-between"},i.createElement(ae,null,i.createElement(b.sA,{id:"COMMON_POWER_FACTOR"})),i.createElement(c.A,{color:"text-3"},Number(n.outlet_power_factor).toFixed(2))):null):null,i.createElement(S.A,{alignItems:"flex-start",gap:O.kc},i.createElement(s.A,{variant:"emphasis",onClick:t,size:"small",isDisabled:!e},i.createElement(b.sA,{id:"COMMON_ACTION_APPLY_CHANGES"})),i.createElement(s.A,{variant:"neutral",onClick:o,size:"small"},i.createElement(b.sA,{id:"COMMON_ACTION_CANCEL"})))))})},194015(e,t,n){n.d(t,{f:()=>E});var r=n(801081),l=n(784045),i=n(239417),a=n(532419),c=n(6510),o=n(951106),s=n(678419),m=n(780811),d=n(602021);const u=e=>!("unifi_device_info"in e)||Boolean(e.unifi_device_info?.view_in_application);var p=n(268892),_=n(694595);const E=(0,r.Mz)(i.A8,a.n_,d.vc,s.Lr,a.Kh,i.Cx,(e,t,n,r,i,a)=>{const s=e.filter(u),d=new Set(r.map(e=>e.client_mac));return(0,l.A)([...t.filter(e=>e.mac!==n&&((e=>!(0,m.uaO)(e)&&!(0,m.vqp)(e)&&!(0,m.Snx)(e))(e)||r.some(t=>t.client_mac===e.mac))).map(e=>({type:"device",mac:e.mac,device:e})),...s.filter(e=>"mac"in e).map(e=>({type:"clientDevice",mac:e.mac,clientDevice:e}))].filter(e=>{if(d.has(e.mac))return!0;const n=(0,p.g)(e.mac,i,a,t),r=(0,_.lD)("device"===e.type?e.device:e.clientDevice,void 0);return t.some(t=>{if(t.mac===e.mac)return!1;const l=(0,_.cL)(t,n,[],[]);return r.some(e=>"psu"===e.type?l.outlets.length>0:l.outlets.length>0||l.ports.length>0)})}),e=>"device"===e.type?(0,c.Q)(e.device):(0,o.tn)(e.clientDevice))})},792042(e,t,n){n.d(t,{A:()=>N});var r=n(296540),l=n(382389),i=n(592563),a=n(820764),c=n(217439),o=n(469733),s=n(239417),m=n(951106),d=n(532419),u=n(678419),p=n(6510),_=n(916537),E=n(703447),A=n(6176),v=n(876250),O=n(294303),C=n(268892),S=n(694595),w=n(115829),b=n(566723),h=n(132196);const g="link-device-link",M=h.AH`
  [data-uic-component='ChipContainer_Disclosed'] {
    display: none;
  }
`,f=h.AH`
  cursor: pointer;
  .${g} {
    visibility: hidden;
  }
  &:hover .${g} {
    visibility: visible;
  }
`,N=({value:e,onChange:t,isDisabled:n,options:h})=>{const N=(0,l.u)(),y=(0,o.useSelector)(u.Lr),I=(0,o.useSelector)(d.ID),x=(0,o.useSelector)(d.Kh),D=(0,o.useSelector)(s.Cx),R=(0,r.useMemo)(()=>h.map(({supervisableDevice:e,disabledReason:t})=>{const n=!!t;return{type:"OPTION",children:[],id:e.mac,title:"device"===e.type?(0,p.Q)(e.device):(0,m.tn)(e.clientDevice),optionProps:{symbol:"device"===e.type?r.createElement(A.A,{model:e.device.model,size:v.Xh.SMALL,width:b.Er,height:b.Er}):r.createElement(E.A,{client:e.clientDevice,width:20,height:20}),isDisabled:n,tooltipProps:t?{description:t,disableOnScroll:!0}:void 0,className:n?void 0:f,data:n?null:r.createElement(c.A,{size:"medium",color:"ublue-06",className:g},r.createElement(_.sA,{id:"COMMON_LINK_DEVICE"}))}}}),[h]),T=(0,r.useMemo)(()=>new Set(R.filter(e=>"OPTION"===e.type&&e.optionProps?.isDisabled).map(e=>e.id)),[R]),k=e?x.get(e)||D.get(e)||{mac:e}:null;return k?r.createElement(O.A,{width:"100%",padding:b.YC,gap:b.kc,alignItems:"center",borderRadius:b.YC,border:`1px solid ${N.motifPalette.neutral03}`},r.createElement(O.A,{width:b.Yc,height:b.Yc,borderRadius:5.5,background:N.motifPalette.neutral01,alignItems:"center",justifyContent:"center"},"model"in k?r.createElement(A.A,{height:b.tr,width:b.tr,model:k.model}):r.createElement(E.A,{client:k,width:b.tr,height:b.tr})),r.createElement(w.A,{variant:"heading-medium",size:"medium"},"model"in k?(0,p.Q)(k)||k.mac:"mac"in k?(0,m.tn)(k)||k.mac:e),n?null:r.createElement(O.A,{padding:b.YC},r.createElement(i.A,{fontSize:"medium",onClick:()=>t(void 0)},r.createElement(_.sA,{id:"COMMON_ACTION_UNLINK"})))):r.createElement(a.A,{className:M,isSelectAllDisabled:!0,items:R,treeProps:{selectionMode:"single",disabledKeys:T},onSelectionChange:e=>{const n="all"===e?void 0:[...e][0]?.toString();if(n){if(y.some(e=>e.client_mac===n&&e.enabled))return;const e=(0,C.g)(n,x,D,I),t=x.get(n)||D.get(n),r=(0,S.lD)(t,void 0);if(!I.some(t=>{if(t.mac===n)return!1;const l=(0,S.cL)(t,e,[],[]);return r.some(e=>"psu"===e.type?l.outlets.length>0:l.outlets.length>0||l.ports.length>0)}))return}t(n)},hasSelectAllControl:!1,setSelectedKeys:()=>{}})}}}]);