"use strict";(self.webpackChunkunifiNetworkUi=self.webpackChunkunifiNetworkUi||[]).push([[7714],{432680:(e,t,i)=>{i.d(t,{XR:()=>c,jq:()=>r,ll:()=>m,rt:()=>l});var n=i(691189),a=i(800126);const l=(e={},t={})=>(0,n.t9)(a.A2,a.VD,e,{...t,idField:"id"}),r=e=>(0,n.vL)(a.A2,e.id,`${a.gI}/${e.id}`,e,void 0,{idField:"id"}),m=e=>e.id?r(e):(e=>(0,n.eC)(a.A2,a.gI,e,void 0,{idField:"id",fetchConfig:{getAllPostData:!0}}))(e),c=e=>(0,n.LK)(a.A2,e,`${a.gI}/${e}`,void 0,{idField:"id"})},800126:(e,t,i)=>{i.d(t,{$j:()=>r,A2:()=>n,VD:()=>l,gI:()=>a});const n="object",a="/v2/api/site/{site}/object-oriented-network-config",l=`${a}s`,r=999},677714:(e,t,i)=>{i.r(t),i.d(t,{default:()=>z});var n=i(296540),a=i(469733),l=i(183970),r=i(949147),m=i(48925),c=i(641777),o=i(602021),s=i(294303),d=i(566723),u=i(459449),E=i(845030),A=i(398300),f=i(38671),O=i(675359),h=i(742920),v=i(895424),_=i(642597),b=i(959341),p=i(689965),C=i(853801),g=i(376618),S=i(784045),M=i(349785),I=i(239417),N=i(951106),T=i(703447),y=i(92828);const k=function({form:e,name:t,additionalInfo:i="mac",excludeUnifiDevices:l,getGroup:r,groups:m,...c}){const o=(0,M.FH)({control:e.control,name:t}),d=(0,a.useSelector)(I.GB),u=(0,n.useMemo)(()=>{const e=d.filter(e=>!(l&&"unifi_device"in e&&e.unifi_device)),t=(o||[]).filter(t=>!e.some(e=>"mac"in e&&e.mac===t)).map(e=>({mac:e,name:e})),i=[...e,...t].flatMap(e=>"mac"in e?[e]:[]);return(m&&r?(0,S.A)(Object.entries((0,g.A)(i,r)),([e])=>m[e]?.order??0).map(([e,t])=>({id:e,label:m[e]?.label,options:t})).filter(e=>e.options.length>0):[{id:void 0,label:void 0,options:i}]).flatMap(({options:e,label:t,id:i})=>[...t&&i?[{type:"SECTION",title:t,id:i,children:[]}]:[],...e.map(e=>({type:"CHECKBOX",title:(0,N.tn)(e),id:e.mac,checkboxProps:{symbol:n.createElement(s.A,{maxWidth:24,maxHeight:24},n.createElement(T.A,{client:e}))},children:[]}))])},[i,d.length,o,l]),E=(0,n.useCallback)(()=>{e.setValue(t,u.map(e=>e.id),{shouldDirty:!0,shouldTouch:!0,shouldValidate:!0})},[u,e,t]),A=(0,n.useCallback)(()=>{const i=new Set(e.getValues(t));return u.length>0&&u.every(e=>i.has(e.id))},[u,e,t]);return n.createElement(y.A,{control:e.control,name:t,options:u,isVirtualized:!0,onSelectAll:E,isAllSelected:A,...c})};var R=i(861509),D=i(360847),V=i(705483);var w=i(329109),x=i(592563),F=i(900956),L=i(117982),U=i(732881),G=i(217439),P=i(74750),$=i(432680);const j=({existingRecord:e})=>{const t=(0,a.useDispatch)();return n.createElement("div",null,n.createElement(F.A,null,n.createElement(L.A,null,n.createElement(x.A,{fontSize:"medium",variant:"destructive"},n.createElement(u.sA,{id:"COMMON_ACTION_REMOVE"}))),n.createElement(U.A,{actionButtons:n.createElement(P.A,{variant:"destructive",onPress:async()=>{await t((0,_.aX)(e.id)),await t((0,$.rt)())}},n.createElement(u.sA,{id:"COMMON_ACTION_REMOVE"})),title:n.createElement(u.sA,{id:"COMMON_ARE_YOU_SURE"})},n.createElement(G.A,{variant:"inherit",size:"medium"},n.createElement(u.sA,{id:"SETTINGS_CLIENT_GROUP_DELETE_CONFIRMATION",values:{name:e?.name}})))))},B="network-members-group-form",H=({activeItem:e})=>{const t=e&&e.id!==b.R6?e:void 0,i=(0,a.useDispatch)(),g=(0,a.useSelector)(o.EL),S=(0,a.useSelector)(R.y),M=(0,n.useMemo)(()=>S.filter(e=>e.id!==t?.id),[t?.id,S]),I=(0,n.useMemo)(()=>(e=>D.Ik({name:(0,V.z)(e),member_macs:D.YO(D.Yj()).min(1)}))(M),[M]),N=(0,r.m)({schema:I,defaultValues:{name:t?.name||"",member_macs:t?.members||[]}});(0,C.y)(N);const T=N.handleSubmit(e=>i((0,_.YH)({id:t?.id,name:e.name,members:e.member_macs,type:t?.type||l.k.CLIENTS})).then(async e=>(await i((0,_.O$)(void 0,{resolveWithExisting:!1})),e)).then(e=>{i((0,E.SQ)(!1)),i((0,E.XP)({type:A.H.NETWORK_MEMBERS_GROUP,id:e.id}))}).then(()=>N.reset()).catch(e=>{const t=(0,f.F)(e)?e:void 0;i((0,O.ox)({icon:h.C.danger,message:"SETTINGS_CLIENT_GROUP_FAILED_SAVE",errorMessage:t?.msg,errorValues:t?.details}))}));return n.createElement("form",{onSubmit:T,id:B},n.createElement(c.A,{isDisabled:g},n.createElement(s.A,{gap:d.kc,flexDirection:"column",width:"100%"},n.createElement(m.A,null,n.createElement(v.A,{control:N.control,name:"name",label:n.createElement(u.sA,{id:"COMMON_NAME"})}),n.createElement(k,{form:N,name:"member_macs"})),t?n.createElement(p.A,null,n.createElement(j,{existingRecord:t})):null),n.createElement(w.A,{onFormCancel:()=>N.reset(),isDirty:N.formState.isDirty||!t,hideCancelButton:!N.formState.isDirty,form:B,isSubmitting:N.formState.isSubmitting,submitButtonText:t?"COMMON_ACTION_SAVE":"COMMON_ACTION_CREATE"})))},z=({activeItem:e})=>n.createElement(H,{key:e.id,activeItem:e})}}]);