"use strict";(self.webpackChunkunifiNetworkUi=self.webpackChunkunifiNetworkUi||[]).push([[14402],{969279(e,i,s){s.d(i,{AM:()=>c,Sm:()=>a});var t=s(274934),n=s(113454),r=s(956978),o=s(434521),l=s(470070);const c=(e,i)=>{const s=new Set(e.power_sources.map(e=>e.client_psu_index)),t=i.psu_table?.findIndex((e,i)=>!s.has(i+1))??-1;return-1!==t?t+1:-1},a=(e,i)=>{const s=i?.includes(e.mac),c="device"===e.type&&(0,r.Daf)(e.device),a="device"===e.type&&!(0,n.K_)((0,o.S9)(e.device));return s?(0,t.jsx)(l.sA,{id:"COMMON_DEVICE_ALREADY_HAS_SUPERVISOR"}):a?(0,t.jsx)(l.sA,{id:"COMMON_SUPERVISOR_DEVICE_STATE_NOT_AVAILABLE"}):c?(0,t.jsx)(l.sA,{id:"COMMON_DEVICE_SUPERVISOR_MESHING_DISABLED_TOOLTIP"}):void 0}},708406(e,i,s){s.d(i,{A:()=>c});var t=s(814557),n=s(247816),r=s(309130),o=s(100978),l=s(291508);const c=(0,n.A)(o.A,(0,l.A)("selected","disabled","allowGreyscale","noMargin"))`
  height: 32px;
  border-radius: ${t.Ay["desktop-radius-base"]};
  padding: ${r.YC} ${r.kc};
  margin-right: ${({noMargin:e})=>e?0:r.kc};
  border: ${({theme:{themeName:e}})=>t.Ay[`desktop-border-divider-${e}`]};
  align-items: center;
  justify-content: center;
  cursor: pointer;
  gap: ${r.kc};
  user-select: none;

  ${({selected:e,theme:{themeName:i}})=>e&&`border-color: ${t.Ay[`desktop-color-ublue-06-${i}`]};`}
  ${({disabled:e,allowGreyscale:i,selected:s})=>e||i&&!s?`> * { opacity: ${r.xN}; }`:void 0}
  ${({disabled:e})=>e&&"pointer-events: none;"}
  ${({allowGreyscale:e,selected:i})=>e&&!i&&"filter: grayscale(100%);"}
`},787481(e,i,s){s.d(i,{A:()=>l});var t=s(274934),n=s(833466),r=s(309130),o=s(100978);const l=e=>(0,t.jsx)(o.A,{paddingTop:r.YC,paddingBottom:r.YC,gap:r.Ln,rowGap:r.YC,flexWrap:"wrap",minHeight:n.b,alignItems:"center",...e})},314402(e,i,s){s.r(i),s.d(i,{default:()=>ae});var t=s(274934),n=s(418398),r=s(977872),o=s(602086),l=s(843871),c=s(938984),a=s(247816),d=s(642687),u=s(954702),p=s(396489),m=s.n(p),_=s(669439),x=s(159469),A=s(950804),h=s(254585),v=s(586566),O=s(309130),C=s(120197),j=s(100978),w=s(205521),b=s(470070),S=s(708861),g=s(956978),M=s(795206),f=s(754924),N=s(20049),E=s(347625),y=s(164487),I=s(232410),D=s(35977),R=s(969279),T=s(67194),k=s(244081),P=s(164205),L=s(787481),$=s(455425),Y=s(482748),V=s(607856),U=s(260288),W=s(20439),z=s(34118),F=s(814557),G=s(263705),K=s(960105),H=s(314229),B=s(304151),Q=s(708406),q=s(427431),X=s(527206),Z=s(434521),J=s(877840),ee=s(113454);const ie=(0,a.A)(j.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};
`,se=(0,a.A)(j.A)`
  border: 1px solid
    ${({theme:{themeName:e}})=>F.Ay[`desktop-color-neutral-03-${e}`]};
  padding: ${O.kc};
`,te=(0,a.A)("div")`
  div[class*='input__'] {
    margin-right: 0;
  }
`,ne=(0,o.memo)(({linkedDeviceMac:e,outletInfo:i})=>{const{values:s,setFieldValue:n}=(0,l.j7)(),a=(0,r.d4)((0,f.tG)(e)),{themeName:d}=(0,G.u)(),u=!!a&&(0,g.Daf)(a),p=!!a&&!(0,ee.K_)((0,Z.S9)(a)),m=s.powerSupervisor.power_sources.find(e=>e.power_source_index===i.index),x=(0,o.useMemo)(()=>{const e=s.powerSupervisor.power_sources.map(e=>e.client_psu_index),i=a?.psu_table?.flatMap((i,s)=>e.includes(s+1)?[]:[s+1]);return[...i||[],m?.client_psu_index]},[a?.psu_table,s.powerSupervisor.power_sources,m?.client_psu_index]),A=(0,o.useCallback)(e=>x?.includes(e),[x]),h=(0,o.useMemo)(()=>u||p,[u,p]);return a?(0,t.jsxs)(j.A,{flexDirection:"column",gap:4,children:[a.psu_table&&a.psu_table.length>1?(0,t.jsx)(se,{flexDirection:"column",gap:O.kc,children:(0,t.jsx)(j.A,{flexDirection:"row",gap:O.YC,alignItems:"center",justifyContent:"space-between",children:(0,t.jsx)(j.A,{gap:O.kc,width:"100%",children:a.psu_table?.map((e,r)=>(0,t.jsx)(_.A,{description:A(r+1)?null:(0,t.jsx)(b.sA,{id:"COMMON_PSU_NOT_AVAILABLE_DESCRIPTION"}),children:(0,t.jsx)("div",{style:{width:"100%"},children:(0,t.jsx)(Q.A,{width:"100%",disabled:!A(r+1),style:{margin:0},selected:m?.client_psu_index===r+1,onClick:()=>{(e=>{const t=s.powerSupervisor.power_sources.map(s=>s.power_source_index===i.index?{...s,client_psu_index:e}:s);n("powerSupervisor.power_sources",t)})(r+1)},children:(0,t.jsx)(c.A,{size:"medium",children:e.label?(0,H.OU)(e.label):`PSU ${r+1}`})})})},e.index))})})}):null,(0,t.jsx)(ie,{width:"100%",children:(0,t.jsxs)(j.A,{flexDirection:"column",gap:O.kc,width:"100%",children:[(0,t.jsxs)(j.A,{justifyContent:"space-between",width:"100%",children:[(0,t.jsxs)(j.A,{gap:O.YC,children:[(0,t.jsx)(K.A,{color:F.Ay[`desktop-color-aqua-06-${d}`],variant:"fill",size:"original"}),(0,t.jsx)(c.A,{color:"text-2",children:(0,t.jsx)(b.sA,{id:"COMMON_POWER_SUPERVISOR"})}),(0,t.jsx)(B.A,{description:(0,t.jsx)(b.sA,{id:"COMMON_POWER_SUPERVISOR_DESCRIPTION"})})]}),(0,t.jsx)(X.A,{isMeshing:u,isNotReady:p,children:(0,t.jsx)(te,{children:(0,t.jsx)(C.A,{type:"checkbox",name:"powerSupervisor.enabled",size:"small",disabled:!s?.powerSupervisor?.enabled&&h})})})]}),s.powerSupervisor.enabled?(0,t.jsx)(X.A,{isMeshing:u,isNotReady:p,children:(0,t.jsx)(J.A,{isDisabled:h,children:(0,t.jsx)(q.D,{})})}):null]})})]}):null});var re=s(170939),oe=s(932093);const le=(0,a.A)(c.A)`
  margin-bottom: ${O.YC};
`,ce=(0,l.bk)({enableReinitialize:!0,mapPropsToValues:({outletInfo:{name:e,cycle_enabled:i,relay_state:s},powerSupervisor:t,devices:n})=>({name:t?.client_mac?(0,E.Q)(n.find(e=>e.mac===t.client_mac))||e||"":e||"",cycle_enabled:i,relay_state:s,powerSupervisor:t?.id?{id:t.id,site_id:t.site_id||"",enabled:t.enabled??!1,client_mac:t.client_mac||"",power_sources:t.power_sources||[],settings:t.settings||P.R4}:U.be}),validationSchema:A.A.object().shape({name:A.A.string().label("COMMON_NAME").max(128),cycle_enabled:A.A.boolean(),relay_state:A.A.boolean(),linked_device_mac:A.A.string()}),handleSubmit:(e,{props:{outletInfo:i,updateDeviceWithIdEndpoint:s,activeItem:t,activeItem:{mac:n,_id:r,outlet_overrides:o},onSubmitSuccess:l,powerSupervisor:c,dispatch:a},setSubmitting:d})=>{const u=[],{powerSupervisor:p,..._}=e,A=i.index??0,h=0===p.power_sources.length;h&&u.push(a((0,T.tI)(p.id)));const v=!c&&"new"!==p.id,O=c&&!m()(c,p);if(!v&&!O||h||u.push(a((0,T.TG)(p))),"new"===p.id){const{id:e,site_id:i,...s}=p;u.push(a((0,T.G)(s)))}return u.push(a(s({outlet_overrides:[...(o||[]).filter(e=>e.index!==A),{index:A,..._}].map(e=>A===(0,S.eq)(e,(0,g.Tl7)(t))?{...e,relay_state:_.relay_state}:e).sort((e,i)=>(e.index||0)-(i.index||0))},r,n,{failureToast:{icon:x.C.danger,message:"DEVICE_OUTLET_FORM_SAVE_ERROR"},mergeAndOverrideKeys:["outlet_overrides"],extend:!0}))),Promise.all(u).then(()=>{a((0,T.pX)()),d(!1),l?.()}).catch(e=>{throw d(!1),e})}}),ae=(0,n.Zz)((0,r.Ng)((e,{activeItem:i,isInSection:s,subId:t})=>{const n=s?+t:+((0,h.Oh)(e)||0);return{outletInfo:(0,S.o3)(i,void 0,n),powerSupervisor:(0,I.qO)(i.mac,n)(e),propertyPanelActiveItemTab:(0,h.oI)(e),devices:(0,N.RM)(e)}},e=>({updateDeviceWithIdEndpoint:M.ex,showPropertyPanel:w.XP,dispatch:e})),ce)(({dirty:e,submitForm:i,outletInfo:s,activeItem:n,onFormCancel:a})=>{const{values:p,setFieldValue:m}=(0,l.j7)(),x=(0,r.wA)(),A=(0,r.d4)(N.RM),h=(0,r.d4)(I.Lr),w=(0,r.d4)(f.m9),S=(0,r.d4)(re.f),g=(0,r.d4)(f.Kh),P=(0,r.d4)(z.Cx),U=(0,o.useMemo)(()=>p.powerSupervisor.power_sources.find(e=>e.power_source_index===s.index&&e.power_source_mac===n.mac),[p.powerSupervisor.power_sources,s.index,n.mac]),[F,G]=(0,o.useState)(!1),[K,H]=(0,o.useState)(0);(0,o.useEffect)(()=>{x((0,T.pX)(void 0,{crudCacheStrategy:{type:k.e.CACHE}}))},[x]);const B=(0,o.useCallback)((e,i)=>`${Y.lP.OUTLET_POWER_CYCLE_COOLDOWN}-${e}-${i??"na"}`,[]),Q=(0,o.useCallback)(e=>{try{const i=V.u.getItem(e);if(!i)return null;const s=Number.parseInt(i,10);return Date.now()>=s?(V.u.removeItem(e),null):s}catch{return null}},[]),q=(0,o.useCallback)((e,i)=>{try{V.u.setItem(e,i.toString()),H(e=>e+1)}catch{}},[]),X=(0,o.useCallback)(()=>{const e=B(n.mac,s.index),i=Date.now()+5*$.vl;q(e,i),x((0,M.t)(n,s))},[n,s,x,B,q]),Z=(0,o.useMemo)(()=>B(n.mac,s.index),[n.mac,s.index,B]),J=(0,o.useMemo)(()=>null!==Q(Z),[Z,Q,K]);(0,o.useEffect)(()=>{const e=Q(Z);if(null===e)return;const i=e-Date.now();if(i<=0)return void H(e=>e+1);const s=setTimeout(()=>{H(e=>e+1)},i);return()=>clearTimeout(s)},[Z,Q,K]);const ie=(0,o.useCallback)(e=>{const i=A.find(i=>i.mac===e),t=h.find(i=>i.client_mac===e);let r=1;t&&(r=(0,R.AM)(t,i));const o={power_source_mac:n.mac,power_source_type:D.F.OUTLET,power_source_index:s.index,client_psu_index:r};m("powerSupervisor",{...p.powerSupervisor,...t,power_sources:[...t?.power_sources||[],o]}),m("powerSupervisor.client_mac",e),m("name",(0,E.Q)(i)),G(!1)},[n.mac,A,s.index,h,m,p.powerSupervisor]),se=(0,o.useCallback)(()=>{const e=p.powerSupervisor.power_sources.filter(e=>e.power_source_index!==s.index);m("powerSupervisor.power_sources",e),m("name",`Outlet ${s.index}`),G(!1)},[s.index,m,p.powerSupervisor.power_sources]),te=(0,o.useCallback)(e=>{e?ie(e):se()},[ie,se]),ce=(0,o.useMemo)(()=>{const e=h.map(e=>e.client_mac);return S.filter(e=>e.mac===p.powerSupervisor?.client_mac||e.mac!==n.mac&&!(0,oe.g)(e.mac,g,P,A)).map(i=>({supervisableDevice:i,disabledReason:(0,R.Sm)(i,e)}))},[n.mac,P,A,g,h,S,p.powerSupervisor.client_mac]);return(0,t.jsx)(t.Fragment,{children:(0,t.jsxs)(j.A,{flexDirection:"column",gap:O.kc,children:[(0,ee.AP)(s)?(0,t.jsxs)(t.Fragment,{children:[F?(0,t.jsx)(W.A,{value:U?p.powerSupervisor.client_mac:void 0,onChange:te,options:ce}):U?(0,t.jsx)(W.A,{value:p.powerSupervisor.client_mac,onChange:te,options:ce}):(0,t.jsx)(d.A,{variant:"secondary-emphasis",style:{width:"100%"},onClick:()=>G(!0),children:(0,t.jsx)(b.sA,{id:"COMMON_LINK_DEVICE"})}),U?(0,t.jsx)(ne,{linkedDeviceMac:p.powerSupervisor.client_mac,outletInfo:s}):null]}):null,U?null:(0,t.jsx)(C.A,{full:!0,name:"name",variant:"secondary",label:"COMMON_NAME"}),(0,t.jsx)(u.A,{type:"button",fontSize:"medium",style:{alignSelf:"flex-start"},onClick:X,isDisabled:J,children:(0,t.jsx)(b.sA,J?{id:"DEVICE_ACTIONS_POWER_CYCLE_IN_PROGRESS"}:{id:"COMMON_POWER_CYCLE"})}),(0,t.jsxs)(j.A,{flexDirection:"column",children:[(0,t.jsx)(y.A,{children:(0,t.jsx)(b.sA,{id:"COMMON_OUTLET"})}),(0,t.jsxs)(L.A,{children:[(0,t.jsx)(C.A,{type:"radio",name:"relay_state",value:!0,children:(0,t.jsx)(b.sA,{id:"COMMON_ACTIVE"})}),(0,t.jsx)(C.A,{type:"radio",name:"relay_state",value:!1,children:(0,t.jsx)(b.sA,{id:"COMMON_DISABLED"})})]})]}),(0,t.jsx)(_.A,{description:w?void 0:(0,t.jsx)(b.sA,{id:"COMMON_REQUIRES_GATEWAY"}),children:(0,t.jsx)(j.A,{marginBottom:O.kc,children:(0,t.jsx)(C.A,{type:"realCheckbox",name:"cycle_enabled",disabled:!w,tooltipMessage:(0,t.jsx)(b.sA,{id:"COMMON_POWER_CYCLE_ON_INTERNET_LOSS_DESCRIPTION"}),children:(0,t.jsx)(b.sA,{id:"COMMON_POWER_CYCLE_ON_INTERNET_LOSS"})})})}),(0,v.TT)(s,"POWER_METER")?(0,t.jsxs)(j.A,{flexDirection:"column",justifyContent:"space-between",width:"100%",gap:O.kc,children:[s.outlet_power?(0,t.jsxs)(j.A,{justifyContent:"space-between",children:[(0,t.jsx)(le,{children:(0,t.jsx)(b.sA,{id:"COMMON_POWER"})}),(0,t.jsx)(c.A,{color:"text-3",children:(0,t.jsx)(b.sA,{id:"COMMON_UNIT_WATTS_SHORT",values:{value:Number(s.outlet_power).toFixed(2)}})})]}):null,s.outlet_current?(0,t.jsxs)(j.A,{justifyContent:"space-between",children:[(0,t.jsx)(le,{children:(0,t.jsx)(b.sA,{id:"COMMON_CURRENT"})}),(0,t.jsx)(c.A,{color:"text-3",children:(0,t.jsx)(b.sA,{id:"COMMON_UNIT_AMPERES_SHORT",values:{value:Number(s.outlet_current||0).toFixed(2)}})})]}):null,s.outlet_voltage?(0,t.jsxs)(j.A,{justifyContent:"space-between",children:[(0,t.jsx)(le,{children:(0,t.jsx)(b.sA,{id:"COMMON_VOLTAGE"})}),(0,t.jsx)(c.A,{color:"text-3",children:(0,t.jsx)(b.sA,{id:"COMMON_UNIT_VOLTAGE_SHORT",values:{value:Number(s.outlet_voltage).toFixed(2)}})})]}):null,s.outlet_power_factor?(0,t.jsxs)(j.A,{justifyContent:"space-between",children:[(0,t.jsx)(le,{children:(0,t.jsx)(b.sA,{id:"COMMON_POWER_FACTOR"})}),(0,t.jsx)(c.A,{color:"text-3",children:Number(s.outlet_power_factor).toFixed(2)})]}):null]}):null,(0,t.jsxs)(j.A,{alignItems:"flex-start",gap:O.kc,children:[(0,t.jsx)(d.A,{variant:"emphasis",onClick:i,size:"small",isDisabled:!e,children:(0,t.jsx)(b.sA,{id:"COMMON_ACTION_APPLY_CHANGES"})}),(0,t.jsx)(d.A,{variant:"neutral",onClick:a,size:"small",children:(0,t.jsx)(b.sA,{id:"COMMON_ACTION_CANCEL"})})]})]})})})},170939(e,i,s){s.d(i,{f:()=>x});var t=s(222102),n=s(117948),r=s(34118),o=s(754924),l=s(347625),c=s(831433),a=s(232410),d=s(956978),u=s(897166);const p=e=>!("unifi_device_info"in e)||Boolean(e.unifi_device_info?.view_in_application);var m=s(932093),_=s(113454);const x=(0,t.Mz)(r.A8,o.n_,u.vc,a.Lr,o.Kh,r.Cx,(e,i,s,t,r,o)=>{const a=e.filter(p),u=new Set(t.map(e=>e.client_mac));return(0,n.A)([...i.filter(e=>e.mac!==s&&((e=>!(0,d.uaO)(e)&&!(0,d.vqp)(e)&&!(0,d.Snx)(e))(e)||t.some(i=>i.client_mac===e.mac))).map(e=>({type:"device",mac:e.mac,device:e})),...a.filter(e=>"mac"in e).map(e=>({type:"clientDevice",mac:e.mac,clientDevice:e}))].filter(e=>{if(u.has(e.mac))return!0;const s=(0,m.g)(e.mac,r,o,i),t=(0,_.lD)("device"===e.type?e.device:e.clientDevice,void 0);return i.some(i=>{if(i.mac===e.mac)return!1;const n=(0,_.cL)(i,s,[],[]);return t.some(e=>"psu"===e.type?n.outlets.length>0:n.outlets.length>0||n.ports.length>0)})}),e=>"device"===e.type?(0,l.Q)(e.device):(0,c.tn)(e.clientDevice))})},20439(e,i,s){s.d(i,{A:()=>N});var t=s(274934),n=s(602086),r=s(263705),o=s(954702),l=s(794146),c=s(938984),a=s(977872),d=s(34118),u=s(831433),p=s(754924),m=s(232410),_=s(347625),x=s(470070),A=s(650632),h=s(974390),v=s(541819),O=s(100978),C=s(932093),j=s(113454),w=s(421314),b=s(309130),S=s(409844);const g="link-device-link",M=S.AH`
  [data-uic-component='ChipContainer_Disclosed'] {
    display: none;
  }
`,f=S.AH`
  cursor: pointer;
  .${g} {
    visibility: hidden;
  }
  &:hover .${g} {
    visibility: visible;
  }
`,N=({value:e,onChange:i,isDisabled:s,options:S})=>{const N=(0,r.u)(),E=(0,a.d4)(m.Lr),y=(0,a.d4)(p.ID),I=(0,a.d4)(p.Kh),D=(0,a.d4)(d.Cx),R=(0,n.useMemo)(()=>S.map(({supervisableDevice:e,disabledReason:i})=>{const s=!!i;return{type:"OPTION",children:[],id:e.mac,title:"device"===e.type?(0,_.Q)(e.device):(0,u.tn)(e.clientDevice),optionProps:{symbol:"device"===e.type?(0,t.jsx)(h.A,{model:e.device.model,size:v.Xh.SMALL,width:b.Er,height:b.Er}):(0,t.jsx)(A.A,{client:e.clientDevice,width:20,height:20}),isDisabled:s,tooltipProps:i?{description:i,disableOnScroll:!0}:void 0,className:s?void 0:f,data:s?null:(0,t.jsx)(c.A,{size:"medium",color:"ublue-06",className:g,children:(0,t.jsx)(x.sA,{id:"COMMON_LINK_DEVICE"})})}}}),[S]),T=(0,n.useMemo)(()=>new Set(R.filter(e=>"OPTION"===e.type&&e.optionProps?.isDisabled).map(e=>e.id)),[R]),k=e?I.get(e)||D.get(e)||{mac:e}:null;return k?(0,t.jsxs)(O.A,{width:"100%",padding:b.YC,gap:b.kc,alignItems:"center",borderRadius:b.YC,border:`1px solid ${N.motifPalette.neutral03}`,children:[(0,t.jsx)(O.A,{width:b.Yc,height:b.Yc,borderRadius:5.5,background:N.motifPalette.neutral01,alignItems:"center",justifyContent:"center",children:"model"in k?(0,t.jsx)(h.A,{height:b.tr,width:b.tr,model:k.model}):(0,t.jsx)(A.A,{client:k,width:b.tr,height:b.tr})}),(0,t.jsx)(w.A,{variant:"heading-medium",size:"medium",children:"model"in k?(0,_.Q)(k)||k.mac:"mac"in k?(0,u.tn)(k)||k.mac:e}),s?null:(0,t.jsx)(O.A,{padding:b.YC,children:(0,t.jsx)(o.A,{fontSize:"medium",onClick:()=>i(void 0),children:(0,t.jsx)(x.sA,{id:"COMMON_ACTION_UNLINK"})})})]}):(0,t.jsx)(l.A,{className:M,isSelectAllDisabled:!0,items:R,treeProps:{selectionMode:"single",disabledKeys:T},onSelectionChange:e=>{const s="all"===e?void 0:[...e][0]?.toString();if(s){if(E.some(e=>e.client_mac===s&&e.enabled))return;const e=(0,C.g)(s,I,D,y),i=I.get(s)||D.get(s),t=(0,j.lD)(i,void 0);if(!y.some(i=>{if(i.mac===s)return!1;const n=(0,j.cL)(i,e,[],[]);return t.some(e=>"psu"===e.type?n.outlets.length>0:n.outlets.length>0||n.ports.length>0)}))return}i(s)},hasSelectAllControl:!1,setSelectedKeys:()=>{}})}}}]);