"use strict";(self.webpackChunkunifiNetworkUi=self.webpackChunkunifiNetworkUi||[]).push([[1709],{161709:(e,t,a)=>{a.r(t),a.d(t,{default:()=>D});var n=a(296540),s=a(951272),c=a(469733),l=a(126457),i=a(780811),o=a(171073),r=a(532419),m=a(675359),d=a(742920),A=a(463486),T=a(776309),h=a(927099),E=a(71479),u=a(81126),_=a(842151),S=a(847883),p=a(388151),b=a(459449),w=a(6510),C=a(294303),g=a(598274),N=a(252093),M=a(566723),I=a(480695),f=a(705426);const v=(0,E.A)(f.A)`
  width: 415px;
  .contentClassName {
    > div span {
      line-height: 24px;
    }
  }
`,y=(0,E.A)(h.A)`
  margin: ${M.Ln} 0;
`,O=(0,E.A)(C.A)`
  gap: 6px;
`,R=(0,E.A)(u.A)`
  flex: 1;
`,x=({onChange:e,onClose:t,withTest:a})=>{const{values:{batteryMac:l,targetMac:i},handleSubmit:o}=(0,s.j7)(),m=(0,c.useSelector)(r.qD),d=(0,c.useSelector)(r.ID).find(({mac:e})=>e===l),A=m.map(({name:e,model:t,mac:a})=>({value:a,label:(0,w.Q)({name:e,model:t,mac:a})}));return n.createElement(v,{allowOverflow:!0,title:n.createElement(h.A,{weight:"bold",size:"header-xs"},n.createElement(b.sA,{id:"ASSIGN_BATTERY_MODAL_TITLE"})),size:"small",contentClassName:"contentClassName",actions:[{variant:"tertiary",text:n.createElement(b.sA,{id:"COMMON_ACTION_CANCEL"}),onClick:t,type:"button"},{variant:"primary",text:n.createElement(b.sA,{id:a?"ASSIGN_AND_TEST_BATTERY_ACTION":"ASSIGN_BATTERY_ACTION"}),onClick:()=>o(),type:"button",disabled:!i}],onRequestClose:t},n.createElement(y,{size:"body"},n.createElement(b.sA,{id:"ASSIGN_BATTERY_MODAL_CONTENT"})),n.createElement(O,{alignItems:"center"},n.createElement(g.A,{device:d,labelId:"DEVICE_ACTIONS_LOCATE_BATTERY"}),n.createElement(N.A,{messageId:"DEVICE_ACTIONS_LOCATE_DEVICE_DESCRIPTION",tooltipClassName:"tooltip-position-fixer"})),n.createElement(_.A,{padding:"none"},n.createElement(S.A,null,n.createElement(I.A,{style:{flex:1},type:"input",label:n.createElement(b.sA,{id:"ASSIGN_BATTERY_ITEM",values:{id:(0,w.Q)(d)}})}),n.createElement(R,{column:!0,width:"50%"},n.createElement(p.A,{name:"targetMac",type:"dropdown",variant:"secondary",translateLabel:!0,label:"COMMON_ASSIGN_TO",options:A,onChange:e,width:"100%"})))))},k=(e,t,a,n)=>{const s=new Set([...n||[],...t.connected_battery_overrides||[]].map(({mac:e})=>e));a&&s.add(a);const c=[...s].map(e=>({mac:e}));return e((0,o.ex)({connected_battery_overrides:c},t._id,t.mac,{extend:!0})),c},D=({activeMacs:e,selectedHost:t})=>{const a=(0,c.useSelector)((0,r.nH)(e)).filter(i.OF),h=(0,c.useDispatch)(),E=(0,c.useSelector)(r.ID),u=(0,c.useSelector)(r.qD),_=t?[t]:u,[S,p]=(0,n.useState)({withTest:1===a.length,hostMac:void 0}),[b,w]=(0,n.useState)(void 0),[C,g]=(0,n.useState)(a.map(({mac:e})=>e)),N=(0,n.useCallback)(()=>{h((0,l.AS)())},[]);(0,n.useEffect)(()=>{if(!_.length)return h((0,l.AS)()),void h((0,m.ox)({icon:d.C.warning,message:"ASSIGN_BATTERY_MODAL_NO_HOSTS_WARNING"}));const e={withTest:1===a.length,hostMac:_[0].mac};a.forEach(e=>{!e.adopted&&h((0,o.Hk)(e))});const t=a.filter(e=>!(0,A.rs)(e.mac,E)).map(({mac:e})=>({mac:e}));if(t.length){const n=k(h,_[0],void 0,t);e.withTest=e.withTest&&1===n.length,1===_.length?(h((0,l.AS)()),e.withTest&&h((0,l.to)({modalType:T.A.TEST_SMART_BATTERY,modalProps:{batteryMac:a[0].mac,hostMac:e.hostMac}}))):p(e)}},[]);const M={batteryMac:C[0],targetMac:b||(0,A.rs)(C[0],E)?.mac||_[0].mac};return _.length?n.createElement(s.l1,{enableReinitialize:!0,initialValues:M,onSubmit:({batteryMac:e,targetMac:t})=>{const n=(0,A.rs)(e,E),s={withTest:S.withTest,hostMac:t};if(n?.mac!==t){n&&(0,A.jq)(e,n,h);const a=E.find(({mac:e})=>e===t),c=k(h,a,e);s.withTest=s.withTest&&1===c.length}else s.withTest=s.withTest&&1===n.connected_battery_overrides.length;p(s),w(void 0),C.shift(),0===C.length?(h((0,l.AS)()),s.withTest&&h((0,l.to)({modalType:T.A.TEST_SMART_BATTERY,modalProps:{batteryMac:a[0].mac,hostMac:s.hostMac}}))):g(C)}},n.createElement(x,{onClose:N,onChange:e=>{const t=E.find(({mac:t})=>t===e.value);p({...S,withTest:1===a.length&&0===(t.connected_battery_overrides||[]).filter(({mac:e})=>e!==C[0]).length}),w(e.value)},withTest:S.withTest})):null}},480695:(e,t,a)=>{a.d(t,{A:()=>l});var n=a(296540),s=a(269333);const c=e=>{if(e)switch(e){case"picklist":case"realCheckbox":case"radio":case"input":case"dropdown":case"tabs":case"button":case"link":case"table":case"label":case"text":default:return;case"dropdownWithLabel":case"inputWithLabel":return"withLabel"}},l=({type:e,...t})=>n.createElement(s.A,{alignWith:c(e),...t})}}]);