"use strict";(self.webpackChunkunifiNetworkUi=self.webpackChunkunifiNetworkUi||[]).push([[64631],{969279(e,t,n){n.d(t,{AM:()=>l,Sm:()=>c});var i=n(274934),o=n(113454),s=n(956978),r=n(434521),a=n(470070);const l=(e,t)=>{const n=new Set(e.power_sources.map(e=>e.client_psu_index)),i=t.psu_table?.findIndex((e,t)=>!n.has(t+1))??-1;return-1!==i?i+1:-1},c=(e,t)=>{const n=t?.includes(e.mac),l="device"===e.type&&(0,s.Daf)(e.device),c="device"===e.type&&!(0,o.K_)((0,r.S9)(e.device));return n?(0,i.jsx)(a.sA,{id:"COMMON_DEVICE_ALREADY_HAS_SUPERVISOR"}):c?(0,i.jsx)(a.sA,{id:"COMMON_SUPERVISOR_DEVICE_STATE_NOT_AVAILABLE"}):l?(0,i.jsx)(a.sA,{id:"COMMON_DEVICE_SUPERVISOR_MESHING_DISABLED_TOOLTIP"}):void 0}},486061(e,t,n){n.d(t,{VT:()=>r,i9:()=>o,ng:()=>a,nt:()=>s});var i=n(241365);const o=n(409844).AH`
  font-size: ${i.Ay["font-size-m"]};
  font-weight: normal;
  border-radius: 0;
`,s=112,r=20,a=345},531984(e,t,n){n.d(t,{w:()=>r});var i=n(602086),o=n(977872),s=n(205521);const r=e=>{const t=(0,o.wA)();(0,i.useEffect)(()=>{t((0,s.SQ)(e))},[t,e])}},762542(e,t,n){n.d(t,{y:()=>o});var i=n(531984);const o=e=>(0,i.w)(e.formState.isDirty)},535322(e,t,n){n.d(t,{A:()=>_,I:()=>i});var i,o=n(274934),s=n(814557),r=n(158885),a=n(247816),l=n(565527),c=n(309130),d=n(100978),m=n(291508);!function(e){e.ACCORDION="accordion",e.BUTTON_LIST="buttonList"}(i||(i={}));const u=(0,a.A)(d.A,(0,m.A)("marginBottom","isButtonList","margin","flex","width","padding","nested","background"))`
  background-color: ${({background:e,nested:t,theme:{themeName:n}})=>e||s.Ay[n===l.S.DARK?`desktop-color-neutral-${t?"00":"01"}-${l.S.DARK}`:`desktop-color-neutral-${t?"01":"00"}-${l.S.LIGHT}`]};
  padding: ${({isButtonList:e,padding:t})=>t||(e?`0 ${c.Ln}`:c.Ln)};
  margin-bottom: ${({marginBottom:e})=>e||c.Ln};
  ${({margin:e})=>e?`margin: ${e};`:""}
  border-radius: 8px;
  flex-direction: column;
  width: ${({width:e="100%"})=>e};
  flex: ${({flex:e=0})=>e};
  > :last-child {
    margin-bottom: 0;
  }
  thead {
    tr {
      height: 32px !important;
    }
    th {
      text-transform: none;
    }
  }
  ${({isButtonList:e})=>e?`\n    > div {\n      display: flex;\n      height: 48px;\n      border-bottom: ${({theme:{themeName:e}})=>s.Ay[`desktop-border-divider-${e}`]};\n      &:last-child {\n        border-bottom: none;\n      }\n    }\n  `:""}
`,p=(0,a.A)(r.A,(0,m.A)("marginBottom","margin","flex","padding","nested","background"))`
  background-color: ${({background:e,nested:t,theme:{themeName:n}})=>e||s.Ay[n===l.S.DARK?`desktop-color-neutral-${t?"00":"01"}-${l.S.DARK}`:`desktop-color-neutral-${t?"01":"00"}-${l.S.LIGHT}`]};
  margin-bottom: ${({theme:e,marginBottom:t})=>t||e.spacing["spacing-l"]};
  ${({margin:e})=>e?`margin: ${e};`:""}
  ${({padding:e})=>e?`padding: ${e};`:""}
  border-radius: 8px;
  flex-direction: column;
  flex: ${({flex:e=0})=>e};
  > :last-child {
    margin-bottom: 0;
  }
  thead {
    tr {
      height: 32px !important;
    }
    th {
      text-transform: none;
    }
  }
  > li {
    > div:first-child {
      background: ${({background:e,theme:{themeName:t}})=>e||s.Ay[t===l.S.DARK?`desktop-color-neutral-01-${l.S.DARK}`:`desktop-color-neutral-00-${l.S.LIGHT}`]};
      height: 48px;
      padding: 0 ${c.Ln};
    }
    > div:nth-child(2) {
      margin-bottom: 0;
      padding: 0;
      > div {
        padding: 0 ${c.Ln} ${c.Ln};
      }
    }
  }
`,_=({type:e,marginBottom:t,margin:n,padding:s,flex:r,width:a,nested:l,...c})=>"items"in c?(0,o.jsx)(p,{marginBottom:t,margin:n,padding:s,flex:r,nested:l,...c}):(0,o.jsx)(u,{nested:l,width:a,marginBottom:t,margin:n,padding:s,flex:r,isButtonList:e===i.BUTTON_LIST,...c,children:c.children})},597750(e,t,n){n.d(t,{A:()=>r});var i=n(274934),o=n(486061),s=n(100978);const r=({maxWidth:e,label:t,children:n,...r})=>(0,i.jsxs)(s.A,{flexDirection:"column",width:"100%",maxWidth:"settingsGridContent"===e?o.ng:e,...r,children:[t,n]})},164487(e,t,n){n.d(t,{A:()=>c});var i=n(274934),o=n(632622),s=n(184931),r=n(309130),a=n(304151),l=n(100978);const c=({tooltip:e,htmlFor:t,children:n,labelProps:c,wrapperProps:d,tooltipProps:m})=>{const u=(0,s.iL)();return(0,i.jsxs)(l.A,{alignItems:"center",gap:r.YC,...d,children:[(0,i.jsx)(o.A,{as:"label",htmlFor:t,color:"tertiary",...c,style:{opacity:u?r.xN:void 0,...c?.style},children:n}),e?(0,i.jsx)(a.A,{description:e,...m}):null]})}},89469(e,t,n){n.d(t,{A:()=>a});var i=n(274934),o=n(602086),s=n(309130),r=n(100978);const a=(0,o.forwardRef)((e,t)=>(0,i.jsx)(r.A,{ref:t,flexDirection:"column",gap:s.kc,width:"100%",...e}))},199742(e,t,n){n.d(t,{A:()=>c});var i=n(274934),o=n(602086),s=n(558948),r=n(309130),a=n(100978),l=n(535322);const c=({actions:e})=>(0,i.jsx)(l.A,{marginBottom:"none",children:(0,i.jsx)(a.A,{flexDirection:"column",gap:r.kc,width:"100%",children:e.filter(Boolean).map((e,t,n)=>(0,i.jsxs)(o.Fragment,{children:[e,t<n.length-1?(0,i.jsx)(a.A,{width:"100%",flexDirection:"column",paddingTop:r.YC,paddingBottom:r.YC,children:(0,i.jsx)(s.A,{orientation:"horizontal"})}):null]},[t,e.toString()].join()))})})},963428(e,t,n){n.d(t,{A:()=>d});var i=n(274934),o=n(977872),s=n(602086),r=n(954702),a=n(669439),l=n(897166),c=n(100978);const d=(0,s.forwardRef)(({allowReadOnly:e,disabledReason:t,...n},s)=>{const d=(0,o.d4)(l.EL)&&!e;return(0,i.jsx)(c.A,{alignItems:"center",children:(0,i.jsx)(a.A,{description:t,placement:"left",children:(0,i.jsx)(r.A,{fontSize:"medium",type:"button",...n,isDisabled:d||n.isDisabled||!!t,ref:s})})})})},756782(e,t,n){n.d(t,{A:()=>A});var i=n(274934),o=n(814557),s=n(602086),r=n(938984),a=n(247816),l=n(309130),c=n(590979),d=n(147045),m=n(291508),u=n(304151),p=n(100978),_=n(535322),h=n(89469);const g=(0,a.A)(_.A,(0,m.A)("isOutlined"))`
  border: ${({theme:{themeName:e},isOutlined:t})=>`1px solid ${t?o.Ay[`desktop-color-ublue-06-${e}`]:"transparent"}`};
`,A=({children:e,title:t,tooltip:n,tooltipProps:o,[d.L]:a,titleAction:m,isOutlined:_})=>{const A=(e=>s.Children.toArray(e).length>0)(e);return(0,i.jsx)(g,{marginBottom:"none",...c.A.addDataTestId(a??""),isOutlined:_,children:(0,i.jsxs)(p.A,{flexDirection:"column",...A&&{gap:l.Ln},width:"100%",children:[t?(0,i.jsxs)(p.A,{alignItems:"center",gap:l.YC,justifyContent:"space-between",width:"100%",children:[(0,i.jsxs)(p.A,{gap:l.YC,alignItems:"center",children:[(0,i.jsx)(r.A,{variant:"heading-medium",children:t}),n?(0,i.jsx)(u.A,{description:n,portal:!0,...o}):null]}),m?(0,i.jsx)(p.A,{children:m}):null]}):null,A?(0,i.jsx)(h.A,{children:e}):null]})})}},480562(e,t,n){n.d(t,{i:()=>r});var i=n(274934),o=n(125799),s=n(767822);const r=e=>(0,i.jsx)(o.A,{description:e.option&&"tooltipDescription"in e.option?e.option.tooltipDescription:null,position:"left",portal:!0,children:(0,i.jsx)(s.q,{...e})})},594492(e,t,n){n.d(t,{A:()=>m});var i=n(274934),o=n(602086),s=n(599110),r=n(247816),a=n(309130),l=n(470070),c=n(291508);const d=(0,r.A)("footer",(0,c.A)("hasFormResetButton"))`
  display: flex;
  justify-content: ${({hasFormResetButton:e})=>e?"space-between":"flex-end"};
  padding: ${a.S2} ${a.fS};
  gap: ${a.kc};
`,m=({allowCancel:e,isDirty:t,isInvalid:n,isSubmitting:r,onFormSubmit:a,onFormReset:c,onFormCancel:m,className:u,submitButtonText:p,customButton:_,applyButton:h,applyButtonFirst:g,hideCancelButton:A,form:x})=>{const f=(0,o.useMemo)(()=>h||(0,i.jsx)(s.A,{name:"submit",variant:"primary",type:"submit",onClick:a,disabled:!t||n||r,form:x,children:(0,i.jsx)(l.sA,{id:p||"COMMON_ACTION_APPLY_CHANGES"})}),[h,x,t,n,r,a,p]);return(0,i.jsxs)(d,{className:u,hasFormResetButton:!!c,children:[g?f:_,A?null:(0,i.jsx)(s.A,{name:"cancel",variant:"default",type:"button",onClick:m,disabled:!e&&!t,children:(0,i.jsx)(l.sA,{id:"COMMON_ACTION_CANCEL"})}),c?(0,i.jsx)(s.A,{name:"reset",variant:"default",type:"button",onClick:c,disabled:!t,children:(0,i.jsx)(l.sA,{id:"COMMON_ACTION_RESET_TO_DEFAULT"})}):null,g?_:f]})}},115114(e,t,n){n.d(t,{A:()=>d});var i=n(274934),o=n(232932),s=n(247816),r=n(409844),a=n(594492);const l=(0,s.A)("div")`
  height: 66px;
`,c=r.AH`
  padding: 0px !important;
`,d=({isDirty:e,onFormSubmit:t,onFormCancel:n,isInvalid:s,...r})=>e?(0,i.jsx)(o.A,{children:(0,i.jsx)(a.A,{isDirty:e,onFormCancel:n,onFormSubmit:t,isInvalid:s,className:c,...r})}):(0,i.jsx)(l,{})},264631(e,t,n){n.r(t),n.d(t,{default:()=>me});var i=n(274934),o=n(602086),s=n(977872),r=n(42220),a=n(436417),l=n(756782),c=n(100978),d=n(969288),m=n(762542),u=n(877840),p=n(897166),_=n(205521),h=n(449339),g=n(309130),A=n(464920),x=n(700444),f=n(159469),O=n(67194),b=n(199742),v=n(754924),E=n(470070),S=n(232410),y=n(34118),j=n(455425),C=n(115114),I=n(325461),T=n(260334),M=n(164205),N=n(644026),w=n(113454);const R=I.Ay.object({mac:I.Ay.string({message:(0,T.rn)("COMMON_VALIDATION_SELECT_A_DEVICE")}).optional(),outlet_index:I.Ay.coerce.string({message:(0,T.rn)("SETTINGS_VALIDATION_SELECT_OUTLET")}).min(1,{message:(0,T.rn)("SETTINGS_VALIDATION_SELECT_OUTLET")})}),D=(e,t,n)=>I.Ay.object({client_mac:I.Ay.string({message:(0,T.rn)("COMMON_VALIDATION_SELECT_A_DEVICE")}).min(1,{message:(0,T.rn)("COMMON_VALIDATION_SELECT_A_DEVICE")}),power_sources:I.Ay.record(I.Ay.string().describe("Device MAC"),I.Ay.record(I.Ay.string().describe("Power Input Key"),R.partial().optional().catch(()=>{}))),settings:I.Ay.object({heartbeat_interval:I.Ay.coerce.number().min(M.KP.heartbeat_interval/j.gG).max(M.Av.heartbeat_interval/j.gG),silence_threshold:I.Ay.coerce.number().min(M.KP.silence_threshold/j.gG).max(M.Av.silence_threshold/j.gG),power_off_duration:I.Ay.coerce.number().min(M.KP.power_off_duration/j.gG).max(M.Av.power_off_duration/j.gG)})}).transform((i,o)=>{const s=i.power_sources[i.client_mac]||{},r=e.get(i.client_mac)||t.get(i.client_mac),a=(0,w.lD)(r,n),l=a.filter(e=>s[e.key]?.mac&&s[e.key]?.mac!==N.O).map(e=>({input:e,result:R.safeParse(s[e.key])})),c=l.flatMap(({input:e,result:t})=>t.success?[]:t.error.issues.map(t=>({...t,path:["power_sources",i.client_mac,e.key,...t.path||[]]})));if(c.length){for(const e of c)o.addIssue(e);return I.Ay.NEVER}return l.length?{...i,assignedInputs:l.flatMap(({input:e,result:t})=>"data"in t&&t.data?[{...e,mac:t.data.mac,outlet_index:t.data.outlet_index}]:[])}:(o.addIssue({code:I.Ay.ZodIssueCode.custom,path:["power_sources",i.client_mac,a[0]?.key||"","mac"],message:(0,T.rn)("COMMON_VALIDATION_SELECT_A_DEVICE")}),I.Ay.NEVER)}),L=(e,t,n)=>{const i=e?.client_mac?t.get(e.client_mac)||n.get(e.client_mac):void 0,o=(0,w.lD)(i,e);return{client_mac:e?.client_mac??"",power_sources:e?.client_mac?{[e.client_mac]:Object.fromEntries(o.map((t,n)=>{const i=e.power_sources[n];return[t.key,{mac:i?.power_source_mac??N.O,outlet_index:i?`${i.power_source_type}:${i.power_source_index}`:"",power_source_type:i?.power_source_type}]}))}:{},settings:{heartbeat_interval:(e?e.settings.heartbeat_interval:M.R4.heartbeat_interval)/j.gG,silence_threshold:(e?e.settings.silence_threshold:M.R4.silence_threshold)/j.gG,power_off_duration:(e?e.settings.power_off_duration:M.R4.power_off_duration)/j.gG}}};var $=n(35977),V=n(184931),k=n(597750),P=n(246798),B=n(20439),F=n(969279),G=n(170939);const U=({form:e,existingRecord:t})=>{const n=(0,V.mQ)(),a=(0,s.d4)(S.Lr),l=(0,s.d4)(v.ID),c=(0,s.d4)(v.Kh),d=(0,s.d4)(y.Cx),m=(0,s.d4)(G.f),{field:u}=(0,r.as)({control:e.control,name:"client_mac"}),p=(0,o.useCallback)(n=>{if(u.onChange(n),!n)return void e.setValue("power_sources",{});const i=a.find(e=>e.client_mac===n);if(i?.client_mac){const n=(0,w.lD)(c.get(i.client_mac)||d.get(i.client_mac),t);e.setValue("power_sources",{[i.client_mac]:Object.fromEntries(n.map(e=>{const t=i.power_sources?.find(t=>t.client_psu_index===e.index);return[e.key,{mac:t?.power_source_mac,outlet_index:`${t?.power_source_type}:${t?.power_source_index}`}]}))})}else{const i=(0,w.hr)(n,l,c,d);if(i){const o=(0,w.lD)(c.get(n)||d.get(n),t);e.setValue("power_sources",{[n]:Object.fromEntries(o.map(e=>[e.key,{mac:i.mac,outlet_index:`${$.F.POE_PORT}:${i.port_idx}`,power_source_type:$.F.POE_PORT}]))})}else e.setValue("power_sources",{})}},[u,a,e,c,d,t,l]),_=(0,o.useMemo)(()=>new Set(a.flatMap(e=>e.enabled?[e.client_mac]:[])),[a]),h=(0,o.useMemo)(()=>m.filter(e=>!_.has(e.mac)).map(e=>({supervisableDevice:e,disabledReason:(0,F.Sm)(e,[])})),[_,m]);return(0,i.jsxs)(k.A,{gap:g.YC,children:[(0,i.jsx)(B.A,{value:u.value,onChange:p,isDisabled:n,options:h}),(0,i.jsx)(P.Ay,{form:e,name:"client_mac"})]})};var H=n(689941),K=n(17722),Y=n(932093);const z=({form:e,existingRecord:t,input:n,hasMultiplePowerSources:o})=>{const s=(0,r.FH)({control:e.control,name:"client_mac"}),a=(0,r.FH)({control:e.control,name:`power_sources.${s}.${n.key}.mac`}),l=(0,r.FH)({control:e.control,name:`power_sources.${s}.${n.key}.outlet_index`}),d=(0,r.FH)({control:e.control,name:`power_sources.${s}.${n.key}.power_source_type`}),m=(0,Y.$)(s),u=d===$.F.POE_PORT&&!!a&&a!==N.O&&m,{powerSourceOptions:p,portOutletOptions:_}=(0,K.Ay)(s,a,l,t?.id,{showUnassign:o,includePoe:u});return(0,i.jsxs)(c.A,{width:"100%",alignItems:"flex-start",gap:g.kc,children:[(0,i.jsx)(c.A,{flex:3,alignItems:"flex-start",children:(0,i.jsx)(H.A,{searchable:!0,control:e.control,name:`power_sources.${s}.${n.key}.mac`,options:p,isReadOnly:u,label:(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)(E.sA,{id:"COMMON_POWER_SOURCE"}),"label"in n?` (${n.label})`:""]}),onAfterChange:t=>{if(e.trigger("power_sources"),t===a||t===N.O)return;const i=(0,w._Q)(t.toString(),p);e.setValue(`power_sources.${s}.${n.key}.outlet_index`,i,{shouldDirty:!0,shouldTouch:!0,shouldValidate:!0})}})}),a&&a!==N.O?(0,i.jsx)(c.A,{flex:2,alignItems:"flex-start",children:(0,i.jsx)(H.A,{searchable:!0,control:e.control,name:`power_sources.${s}.${n.key}.outlet_index`,options:_,label:(0,i.jsx)(E.sA,{id:d===$.F.POE_PORT?"COMMON_PORT":"COMMON_OUTLET"}),onAfterChange:()=>e.trigger("power_sources"),isReadOnly:u})}):null]})};var Q=n(725989),W=n(57174);const q=({form:e,label:t,tooltip:n,name:o})=>{const s=M.KP[o]/j.gG,a=M.Av[o]/j.gG;return(0,i.jsx)(r.xI,{control:e.control,name:`settings.${o}`,render:({field:r,fieldState:l})=>(0,i.jsxs)(k.A,{children:[(0,i.jsxs)(c.A,{gap:g.kc,alignItems:"flex-start",width:"100%",children:[(0,i.jsx)(c.A,{width:"100%",children:(0,i.jsx)(Q.A,{style:{width:"100%"},value:Math.min(a,Math.max(s,Number(r.value))),onChange:e=>r.onChange(Number(e)),minValue:s,maxValue:a,label:t,labelProps:{tooltipMessage:n},isInvalid:l.invalid})}),(0,i.jsx)(c.A,{width:160,children:(0,i.jsx)(W.A,{suffix:(0,i.jsx)(E.sA,{id:"COMMON_MIN"}),value:Number(r.value),onChange:e=>r.onChange(e),minValue:s,maxValue:a,isInvalid:l.invalid})})]}),(0,i.jsx)(P.Ay,{form:e,name:`settings.${o}`})]})})},X=({form:e})=>(0,i.jsx)(q,{form:e,name:"heartbeat_interval",label:(0,i.jsx)(E.sA,{id:"COMMON_HEARTBEAT"}),tooltip:(0,i.jsx)(E.sA,{id:"COMMON_HEARTBEAT_TOOLTIP"})}),J=({form:e})=>(0,i.jsx)(q,{form:e,name:"silence_threshold",label:(0,i.jsx)(E.sA,{id:"COMMON_SILENCE_THRESHOLD"}),tooltip:(0,i.jsx)(E.sA,{id:"COMMON_SILENCE_THRESHOLD_TOOLTIP"})});var Z=n(954702),ee=n(396489),te=n.n(ee);const ne={heartbeat_interval:M.R4.heartbeat_interval/j.gG,silence_threshold:M.R4.silence_threshold/j.gG,power_off_duration:M.R4.power_off_duration/j.gG},ie=({form:e})=>{const t=(0,r.FH)({control:e.control,name:"settings"}),n=(0,o.useMemo)(()=>te()(t,ne),[t]),s=(0,V.mQ)();return(0,i.jsx)(c.A,{alignItems:"center",justifyContent:"flex-start",children:(0,i.jsx)(Z.A,{isDisabled:s||n,onClick:()=>e.setValue("settings",ne,{shouldDirty:!0,shouldTouch:!0}),fontSize:"medium",type:"button",children:(0,i.jsx)(E.sA,{id:"SETTINGS_SECURITY_RESET_TO_DEFAULTS"})})})};var oe=n(831433),se=n(146215),re=n(963428),ae=n(347625);const le=({existingRecord:e})=>{const t=(0,s.wA)(),n=(0,s.d4)(v.Kh),r=(0,s.d4)(y.Cx),a=(0,o.useMemo)(()=>{const t=n.get(e.client_mac);if(t)return(0,ae.Q)(t);const i=r.get(e.client_mac);return i?(0,oe.tn)(i):e.client_mac},[n,r,e.client_mac]);return(0,i.jsx)(se.A,{trigger:(0,i.jsx)(re.A,{variant:"destructive",children:(0,i.jsx)(E.sA,{id:"SETTINGS_REMOVE_SUPERVISOR"})}),onConfirm:async()=>{e.power_sources?.some(e=>e.power_source_type===$.F.OUTLET)?await t((0,O.TG)({...e,enabled:!1})):await t((0,O.tI)(e.id)),t((0,O.pX)()),t((0,_.K5)())},title:(0,i.jsx)(E.sA,{id:"SETTINGS_REMOVE_SUPERVISOR_TITLE"}),message:(0,i.jsx)(E.sA,{id:"SETTINGS_POWER_SUPERVISOR_REMOVE_CONFIRMATION",values:{deviceName:a}})})};var ce=n(320018),de=n(113592);const me=({activeItem:e})=>{const t=e&&e.id!==d.R6?e:void 0,n=(0,s.wA)(),I=(0,s.d4)(p.EL),T=(0,s.d4)(v.Kh),M=(0,s.d4)(S.Lr),N=(0,s.d4)(y.Cx),R=(0,a.m)({defaultValues:L(t,T,N),schema:D(T,N,t)});(0,m.y)(R);const{isDirty:$,isSubmitting:V}=(0,r.lN)(R),k=(0,r.FH)({control:R.control,name:"client_mac"}),P=(0,o.useMemo)(()=>M.find(e=>e.client_mac===k),[k,M]),B=R.handleSubmit(async e=>{try{const i=t||P,o=((e,t)=>({...e,enabled:!0,power_sources:t.assignedInputs.flatMap(e=>{const t=e.outlet_index?.split(":")||[],n=t[0],i=Number(t[1]);return[{power_source_mac:e.mac,power_source_index:i,power_source_type:n,client_psu_index:e.psuIndex}]}),client_mac:t.client_mac,settings:{heartbeat_interval:Math.round(t.settings.heartbeat_interval*j.gG),silence_threshold:Math.round(t.settings.silence_threshold*j.gG),power_off_duration:Math.round(t.settings.power_off_duration*j.gG)}}))(i,e),s=await n(i?(0,O.TG)({id:i.id,...o},{},{resolveWithExisting:!1}):(0,O.G)(o,{},{resolveWithExisting:!1}));await n((0,O.pX)(void 0,{resolveWithExisting:!1}));const r=s?.data?.[0]?.id||s?.id||i?.id;n((0,_.SQ)(!1)),r&&n((0,_.XP)({type:h.H.POWER_SUPERVISOR,id:r})),R.reset()}catch(e){const t=(0,A.F)(e)?e:void 0;n((0,x.ox)({type:f.C.danger,message:"COMMON_POWER_SUPERVISOR_SAVE_ERROR",errorMessage:t?.msg,errorValues:{...t}}))}}),F=T.get(k)||N.get(k),G=k?(0,w.lD)(F,t):[];return(0,i.jsx)("form",{onSubmit:B,children:(0,i.jsxs)(u.A,{isDisabled:I,children:[(0,i.jsxs)(c.A,{flexDirection:"column",width:"100%",gap:g.kc,children:[(0,i.jsxs)(l.A,{title:(0,i.jsx)(E.sA,t?{id:"SETTINGS_LINKED_DEVICE"}:{id:"SETTINGS_SUPERVISED_DEVICE"}),children:[(0,i.jsx)(u.A,{isDisabled:!!t,children:(0,i.jsx)(U,{form:R,existingRecord:t})}),G.map(e=>(0,i.jsx)(z,{form:R,existingRecord:t||P,input:e,hasMultiplePowerSources:G.length>1},e.key))]}),(0,i.jsxs)(l.A,{title:(0,i.jsx)(E.sA,{id:"SETTINGS_SUPERVISOR_SETTINGS"}),children:[(0,i.jsx)(X,{form:R}),(0,i.jsx)(J,{form:R}),(0,i.jsx)(ie,{form:R})]}),t?(0,i.jsx)(ce.A,{id:t.id,logType:de.F.POWER_SUPERVISOR,label:"COMMON_ACTIVITY",mac:F&&"mac"in F?F.mac:void 0,marginBottom:"none"}):null,t?(0,i.jsx)(b.A,{actions:[(0,i.jsx)(le,{existingRecord:t})]}):null]}),(0,i.jsx)(C.A,{onFormSubmit:B,onFormCancel:()=>R.reset(),isDirty:$||!t,hideCancelButton:!$,submitButtonText:t?void 0:"COMMON_ACTION_CREATE",isSubmitting:V})]})})}},170939(e,t,n){n.d(t,{f:()=>h});var i=n(222102),o=n(117948),s=n(34118),r=n(754924),a=n(347625),l=n(831433),c=n(232410),d=n(956978),m=n(897166);const u=e=>!("unifi_device_info"in e)||Boolean(e.unifi_device_info?.view_in_application);var p=n(932093),_=n(113454);const h=(0,i.Mz)(s.A8,r.n_,m.vc,c.Lr,r.Kh,s.Cx,(e,t,n,i,s,r)=>{const c=e.filter(u),m=new Set(i.map(e=>e.client_mac));return(0,o.A)([...t.filter(e=>e.mac!==n&&((e=>!(0,d.uaO)(e)&&!(0,d.vqp)(e)&&!(0,d.Snx)(e))(e)||i.some(t=>t.client_mac===e.mac))).map(e=>({type:"device",mac:e.mac,device:e})),...c.filter(e=>"mac"in e).map(e=>({type:"clientDevice",mac:e.mac,clientDevice:e}))].filter(e=>{if(m.has(e.mac))return!0;const n=(0,p.g)(e.mac,s,r,t),i=(0,_.lD)("device"===e.type?e.device:e.clientDevice,void 0);return t.some(t=>{if(t.mac===e.mac)return!1;const o=(0,_.cL)(t,n,[],[]);return i.some(e=>"psu"===e.type?o.outlets.length>0:o.outlets.length>0||o.ports.length>0)})}),e=>"device"===e.type?(0,a.Q)(e.device):(0,l.tn)(e.clientDevice))})},20439(e,t,n){n.d(t,{A:()=>I});var i=n(274934),o=n(602086),s=n(263705),r=n(954702),a=n(794146),l=n(938984),c=n(977872),d=n(34118),m=n(831433),u=n(754924),p=n(232410),_=n(347625),h=n(470070),g=n(650632),A=n(974390),x=n(541819),f=n(100978),O=n(932093),b=n(113454),v=n(421314),E=n(309130),S=n(409844);const y="link-device-link",j=S.AH`
  [data-uic-component='ChipContainer_Disclosed'] {
    display: none;
  }
`,C=S.AH`
  cursor: pointer;
  .${y} {
    visibility: hidden;
  }
  &:hover .${y} {
    visibility: visible;
  }
`,I=({value:e,onChange:t,isDisabled:n,options:S})=>{const I=(0,s.u)(),T=(0,c.d4)(p.Lr),M=(0,c.d4)(u.ID),N=(0,c.d4)(u.Kh),w=(0,c.d4)(d.Cx),R=(0,o.useMemo)(()=>S.map(({supervisableDevice:e,disabledReason:t})=>{const n=!!t;return{type:"OPTION",children:[],id:e.mac,title:"device"===e.type?(0,_.Q)(e.device):(0,m.tn)(e.clientDevice),optionProps:{symbol:"device"===e.type?(0,i.jsx)(A.A,{model:e.device.model,size:x.Xh.SMALL,width:E.Er,height:E.Er}):(0,i.jsx)(g.A,{client:e.clientDevice,width:20,height:20}),isDisabled:n,tooltipProps:t?{description:t,disableOnScroll:!0}:void 0,className:n?void 0:C,data:n?null:(0,i.jsx)(l.A,{size:"medium",color:"ublue-06",className:y,children:(0,i.jsx)(h.sA,{id:"COMMON_LINK_DEVICE"})})}}}),[S]),D=(0,o.useMemo)(()=>new Set(R.filter(e=>"OPTION"===e.type&&e.optionProps?.isDisabled).map(e=>e.id)),[R]),L=e?N.get(e)||w.get(e)||{mac:e}:null;return L?(0,i.jsxs)(f.A,{width:"100%",padding:E.YC,gap:E.kc,alignItems:"center",borderRadius:E.YC,border:`1px solid ${I.motifPalette.neutral03}`,children:[(0,i.jsx)(f.A,{width:E.Yc,height:E.Yc,borderRadius:5.5,background:I.motifPalette.neutral01,alignItems:"center",justifyContent:"center",children:"model"in L?(0,i.jsx)(A.A,{height:E.tr,width:E.tr,model:L.model}):(0,i.jsx)(g.A,{client:L,width:E.tr,height:E.tr})}),(0,i.jsx)(v.A,{variant:"heading-medium",size:"medium",children:"model"in L?(0,_.Q)(L)||L.mac:"mac"in L?(0,m.tn)(L)||L.mac:e}),n?null:(0,i.jsx)(f.A,{padding:E.YC,children:(0,i.jsx)(r.A,{fontSize:"medium",onClick:()=>t(void 0),children:(0,i.jsx)(h.sA,{id:"COMMON_ACTION_UNLINK"})})})]}):(0,i.jsx)(a.A,{className:j,isSelectAllDisabled:!0,items:R,treeProps:{selectionMode:"single",disabledKeys:D},onSelectionChange:e=>{const n="all"===e?void 0:[...e][0]?.toString();if(n){if(T.some(e=>e.client_mac===n&&e.enabled))return;const e=(0,O.g)(n,N,w,M),t=N.get(n)||w.get(n),i=(0,b.lD)(t,void 0);if(!M.some(t=>{if(t.mac===n)return!1;const o=(0,b.cL)(t,e,[],[]);return i.some(e=>"psu"===e.type?o.outlets.length>0:o.outlets.length>0||o.ports.length>0)}))return}t(n)},hasSelectAllControl:!1,setSelectedKeys:()=>{}})}},246798(e,t,n){n.d(t,{Ay:()=>c});var i=n(274934),o=n(42220),s=n(104669),r=n(976888),a=n(260334);const l=e=>{if(!e)return[];const t=Object.values(e).map(e=>(e=>"object"==typeof e&&null!==e&&"type"in e&&"string"==typeof e.type)(e)?l(e):[]);return[e.message,...t.flat()].filter(r.z)},c=function({name:e,form:t,noMargin:n}){const r=(0,a.L_)();return(0,i.jsx)(o.xI,{name:e,control:t.control,render:({fieldState:e})=>{const t=l(e.error)[0];return(0,i.jsx)(i.Fragment,{children:e.invalid&&t?(0,i.jsx)(s.A,{isInvalid:!0,style:n?{paddingTop:0,paddingBottom:0}:void 0,label:r(t)}):null})}})}},436417(e,t,n){n.d(t,{m:()=>a});var i=n(602086),o=n(42220),s=n(369289),r=n(721533);function a({schema:e,defaultValues:t,presets:n}){const a=(0,i.useMemo)(()=>n?(0,s.A)(n,e=>e.defaultValues):{},[n]),l=(0,i.useMemo)(()=>({...t,...a}),[a,t]),c=(0,o.mN)({resolver:(0,r.u)(e),shouldFocusError:!0,defaultValues:l,shouldUseNativeValidation:!1,mode:"onTouched"}),d=(0,i.useRef)(l);d.current=l;const m=(0,i.useCallback)((...e)=>{const[t,...n]=e;return c.reset(t?{...t,...a}:d.current,...n)},[a,c]);return{...c,reset:m,formState:{...c.formState,isDirty:!!Object.keys(c.formState.dirtyFields).length,isSubmitting:c.formState.isSubmitting},handleSubmit:(...e)=>c.handleSubmit(e[0],(t,...n)=>{const i=Object.keys(t)[0];if(i)try{const e=document.getElementsByName(i)?.[0];e?.scrollIntoView?.({behavior:"smooth",block:"center"}),e?.focus?.({preventScroll:!0})}catch{}e[1]?.(t,...n)})}}},260334(e,t,n){n.d(t,{L_:()=>d,MS:()=>c,rn:()=>l});var i=n(602086),o=n(949812),s=n(765282),r=n(470070);const a="{::}",l=(e,t)=>`${e}${a}${JSON.stringify(t??{})}`,c=(e,t)=>{if("string"!=typeof t)return;const[n,...i]=t.split(a);if(!n||!i.length)return t;let o={};try{o=Object.fromEntries(Object.entries(JSON.parse(i.join(a))).map(([t,n])=>[t,"string"==typeof n?c(e,n):n]))}catch{}return e.formatMessage({id:n},o)};function d(){const{formatMessage:e}=(0,r.tz)();return(0,i.useCallback)(t=>c({formatMessage:e},t),[e])}o.pJ((e,t)=>e.message?{message:e.message}:e.code===s.eq.too_small&&"string"===e.type?{message:l("COMMON_MIN_CHARS",{min:Number(e.minimum)})}:e.code===s.eq.too_big&&"string"===e.type?{message:l("COMMON_MAX_CHARS",{name:l("COMMON_VALUE"),max:Number(e.maximum)})}:e.code===s.eq.invalid_type&&"array"===e.expected&&"undefined"===e.received?{message:l("COMMON_SELECT_AT_LEAST_ONE_ITEM")}:e.code===s.eq.too_small&&"array"===e.type?{message:l("COMMON_ADD_AT_LEAST_X_ITEMS",{min:Number(e.minimum)})}:e.code===s.eq.invalid_type&&"undefined"===e.received?{message:l("COMMON_VALIDATION_VALUE_REQUIRED")}:e.code===s.eq.invalid_type&&"number"===e.expected?{message:l("COMMON_VALIDATION_PLEASE_ENTER_A_NUMBER")}:{message:t.defaultError})},689941(e,t,n){n.d(t,{A:()=>u});var i=n(274934),o=n(693371),s=n(42220),r=n(480562),a=n(164487),l=n(597750),c=n(147045),d=n(260334),m=n(184931);const u=function({control:e,name:t,label:n,options:u,tooltip:p,tooltipProps:_,placeholder:h,renderOption:g,onChange:A,onAfterChange:x,searchable:f,searchableProps:O,portal:b,maxHeight:v,disableValidationMessage:E,isReadOnly:S,[c.L]:y}){const j=(0,m.mQ)(),C=(0,d.L_)();return(0,i.jsx)(s.xI,{control:e,name:t,render:({field:e,fieldState:c,formState:d})=>(0,i.jsxs)(l.A,{gap:2,children:[n?(0,i.jsx)(a.A,{htmlFor:t,tooltip:p,tooltipProps:{portal:!0,..._},children:n}):null,(0,i.jsx)(o.A,{variant:"secondary",width:"100%",renderOption:g??r.i,options:u,...e,readOnly:S,disabled:j,onChange:(t,n)=>{const i=A?A(n,{field:e,fieldState:c,formState:d}):e.onChange(n);return x?.(n),i},value:e.value??"",invalid:c.invalid&&!E?C((0,s.Jt)(d.errors,t)?.message)||!0:void 0,placeholder:h,searchable:f,searchableProps:O,portal:b,"data-testid":y,maxHeight:v})]})})}},976888(e,t,n){function i(e){return Boolean(e)}n.d(t,{z:()=>i})}}]);