"use strict";(self.webpackChunkunifiNetworkUi=self.webpackChunkunifiNetworkUi||[]).push([[7598],{697598:(e,l,t)=>{t.r(l),t.d(l,{default:()=>T});var a=t(296540),n=t(951272),r=t(469733),c=t(271856),i=t(617147),s=t(847883),_=t(459449),d=t(984652),A=t(691294),o=t(126457),m=t(532419),u=t(388151),C=t(501524),E=t(955161),O=t(198494),N=t(302167),p=t(239417),b=t(400261),M=t(96512),S=t(582724),D=t(592510),f=t(634229),h=t(566723),L=t(870443),k=t(546391),I=t(359858);const x={mac:"",name:"",use_fixedip:!1,local_dns_record_enabled:!1,local_dns_record:"",fixed_ip:""},g=(e,l,t)=>L.A.lazy(({fixed_ip:n})=>{let r=[];r=e?.map(e=>e?.ip_subnet).filter(Boolean);const c=r.map(e=>e.split("/").shift());return L.A.object().shape({mac:L.A.string().label("COMMON_MAC_ADDRESS").required().matches(k.b8,{message:a.createElement(_.sA,{id:"CLIENT_MODAL_INPUT_MAC_ADDRESS_PATTERN_VALIDATION"})}).test("Catch Null MAC",a.createElement(_.sA,{id:"CLIENT_MODAL_INPUT_MAC_ADDRESS_PATTERN_VALIDATION"}),e=>!k.$f.test(e)),name:L.A.string(),use_fixedip:L.A.bool(),fixed_ip:(0,I.q)(r,n,c,l,t),local_dns_record_enabled:L.A.bool(),local_dns_record:L.A.string().when("local_dns_record_enabled",{is:!0,then:L.A.string().label("COMMON_LOCAL_DNS_RECORD").matches(k.V2,{message:a.createElement(_.sA,{id:"COMMON_LOCAL_DNS_RECORD_HOSTNAME"})}).required()})})}),R=e=>a.createElement(c.A,{portal:!0,width:220,description:a.createElement(_.sA,{id:"COMMON_LOCAL_DNS_UNAVAILABLE"})},e),T=({enforcedFixedIp:e=!1})=>{const l=(0,r.useDispatch)(),t=(0,r.useSelector)(C.Zx),c=(0,r.useSelector)(C.nC),L=(0,r.useSelector)(p.GB),k=(0,r.useSelector)(m.C$),I=(0,r.useSelector)(O.lW),T=(0,r.useSelector)(N.Yk),y=(0,M.I)(),v=(0,a.useCallback)(({...e},{setSubmitting:t})=>{t(!0),e.use_fixedip||delete e.fixed_ip,e.local_dns_record_enabled||delete e.local_dns_record,l((0,d.UU)(e)).then(({_id:t,...a})=>{l((0,d.L5)(e.mac,a,A.N7.OFFLINE,{queryParams:{withinHours:I}})),l((0,o.AS)())}).catch(y).finally(()=>{t(!1)})},[l,y,I]),w=(0,a.useCallback)((e,t)=>[{text:a.createElement(_.sA,{id:"COMMON_ACTION_CANCEL"}),type:"button",disabled:e,onClick:()=>{l((0,o.AS)())}},{text:a.createElement(_.sA,{id:"COMMON_ADD_CLIENT"}),type:"submit",variant:"primary",disabled:e,onClick:()=>{t()}}],[l]),P=(0,a.useCallback)(e=>l=>{e("mac",(0,b.Z)(l?.currentTarget?.value))},[]),U=(0,a.useCallback)(e=>l=>{e("use_fixedip",l.target.checked),l.target.checked||e("local_dns_record_enabled",!1)},[]),F=(0,a.useMemo)(()=>({...x,use_fixedip:e}),[e]);return(0,S.A)([(0,f.Sk)(void 0,{crudCacheStrategy:{type:D.e.CACHE}})],a.createElement(n.l1,{initialValues:F,onSubmit:v,validationSchema:g(c,L,T)},({handleSubmit:l,isSubmitting:n,values:r,setFieldValue:c})=>a.createElement(i.A,{isOpen:!0,shouldCloseOnEsc:!0,allowOverflow:!0,size:"small",title:a.createElement(_.sA,{id:"COMMON_ADD_CLIENT"}),actions:w(n,l)},a.createElement(s.A,null,a.createElement(u.A,{label:"COMMON_MAC_ADDRESS",name:"mac",variant:"secondary",spellCheck:"false",full:!0,onChange:P(c)})),a.createElement(s.A,{marginBottom:h.kc},a.createElement(u.A,{full:!0,label:"CLIENT_MODAL_INPUT_ALIAS",name:"name",variant:"secondary"})),a.createElement(s.A,null,a.createElement(u.A,{type:"realCheckbox",name:"use_fixedip",onChange:U(c),disabled:!t||e},a.createElement(_.sA,{id:"COMMON_FIXED_IP_ADDRESS"}))),r.use_fixedip?a.createElement(s.A,{marginBottom:h.kc},a.createElement(u.A,{full:!0,label:"COMMON_IP_ADDRESS",name:"fixed_ip",variant:"secondary"})):null,k?null:a.createElement(a.Fragment,null,a.createElement(s.A,null,a.createElement(E.A,{condition:!r.use_fixedip,wrapper:R},a.createElement(u.A,{type:"realCheckbox",name:"local_dns_record_enabled",disabled:!r.use_fixedip},a.createElement(_.sA,{id:"COMMON_LOCAL_DNS_RECORD"})))),r.local_dns_record_enabled?a.createElement(s.A,null,a.createElement(u.A,{full:!0,name:"local_dns_record",variant:"secondary",helperMessage:"COMMON_LOCAL_DNS_RECORD_HELPER"})):null))))}}}]);