"use strict";(self.webpackChunkunifiNetworkUi=self.webpackChunkunifiNetworkUi||[]).push([[55514],{694911(e,n,i){i.r(n),i.d(n,{default:()=>oe});var t=i(274934),o=i(977872),a=i(237725),_=i(42220),s=i(602086),r=i(159469),c=i(762542),d=i(43506),l=i(871808),O=i(436417),m=i(756782),I=i(205521),T=i(700444),A=i(291935),N=i(598990),u=i(897166),E=i(95857),S=i(890222),f=i(969288),G=i(115114);const R=(e,n)=>e._id===f.R6?{configuration_file:void 0,name:void 0,device_mac:void 0,unbind_wan_monitors:!1}:{configuration_file:e.frr_bgpd_config?{name:e.uploaded_file_name||"frr.conf",content:e.frr_bgpd_config}:void 0,name:e.description,device_mac:e.device_mac,unbind_wan_monitors:n.unbind_wan_monitors||!1};var p=i(241792),x=i(260334);const C=p.Ik({configuration_file:p.Ik({name:p.Yj().refine(e=>e.endsWith(".conf"),{message:(0,x.rn)("SETTINGS_ROUTING_BGP_CONFIGURATION_CONF_EXTENSION_VALIDATION")}),content:p.Yj({message:(0,x.rn)("SETTINGS_ROUTING_BGP_CONFIGURATION_CONF_EXTENSION_VALIDATION")}).min(1,{message:(0,x.rn)("SETTINGS_ROUTING_BGP_CONFIGURATION_FILE_EMPTY")})},{message:(0,x.rn)("SETTINGS_ROUTING_BGP_CONFIGURATION_CONF_EXTENSION_VALIDATION")}),name:p.Yj({required_error:(0,x.rn)("COMMON_VALIDATION_NAME_REQUIRED")}).nonempty({message:(0,x.rn)("COMMON_VALIDATION_NAME_REQUIRED")}),device_mac:p.Yj({required_error:(0,x.rn)("COMMON_VALIDATION_SELECT_A_DEVICE")}),unbind_wan_monitors:p.zM().optional()});var v=i(625133),j=i(470070);const g=({form:e})=>(0,t.jsx)(v.A,{control:e.control,name:"unbind_wan_monitors",tooltip:(0,t.jsx)(j.sA,{id:"SETTINGS_ROUTING_BGP_OVERRIDE_WAN_MONITORS_TOOLTIP"}),children:(0,t.jsx)(j.sA,{id:"SETTINGS_ROUTING_BGP_OVERRIDE_WAN_MONITORS"})});var h=i(635891);const P=({form:e})=>(0,t.jsx)(h.A,{control:e.control,name:"name",label:(0,t.jsx)(j.sA,{id:"COMMON_NAME"})});var U=i(689941),D=i(754924),M=i(741331),b=i(956978),B=i(901389);const F=({form:e,isExistingRecord:n})=>{const i=(0,o.d4)(D.UV),a=(0,o.d4)(M._V),r=(0,o.d4)(D.U$),c=(0,l.A)(E.Xj.BGP_ROUTING),d=(0,_.FH)({control:e.control,name:"device_mac"}),O=(0,s.useMemo)(()=>d?i.find(e=>e.mac===d):void 0,[i,d]),m=(0,s.useMemo)(()=>i.map(e=>({value:e.mac,label:e.name||""})).concat(c?[{value:r.mac,label:r.name||""}]:[]).map(e=>(n||(e.disabled=a.some(n=>n.device_mac===e.value),e.message=(0,t.jsx)(j.sA,{id:"SETTINGS_ROUTING_BGP_DISABLED_DEVICE_TOOLTIP"})),e)),[i,c,r,n,a]);return(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(U.A,{control:e.control,name:"device_mac",label:(0,t.jsx)(j.sA,{id:"COMMON_DEVICE"}),options:m}),O&&(0,b.cR8)(O)?(0,t.jsx)(B.A,{children:(0,t.jsx)(j.sA,{id:"SETTINGS_BGP_ECS_AGGREGATION_WARNING"})}):null]})};var L=i(948866),y=i(599110),Z=i(95032),w=i(135640),V=i(789577),Y=i(471567),k=i(435689),W=i(247816),X=i(296261),$=i(246798),H=i(833466),Q=i(309130),q=i(164487),z=i(597750),K=i(793442),J=i(100978),ee=i(726831);const ne=(0,W.A)(L.A)`
  /* Prevent overflowing the button for long file names and allow truncation. */
  max-width: 100%;
  height: 24px;
  overflow: hidden;
  align-items: center;
  display: flex;
  > div {
    max-width: 100%;
  }
`,ie=({form:e})=>{const{field:n}=(0,_.as)({control:e.control,name:"configuration_file"}),i=n.value?.name,o=n.value?.content,a=!!n.value,r=(0,s.useMemo)(()=>{if(!o)return null;try{return`data:application/octet-stream;charset=utf-8;base64,${btoa(o)}`}catch{return null}},[o]);return(0,t.jsxs)(z.A,{children:[(0,t.jsx)(q.A,{htmlFor:"configuration_file",tooltip:(0,t.jsx)(j.sA,{id:"SETTINGS_ROUTING_BGP_CONFIGURATION_FILE_TOOLTIP",values:{link:(0,t.jsx)(K.A,{id:"COMMON_LEARN_MORE",href:ee.A.bgpArticle,noWrap:!0})}}),tooltipProps:{isInteractive:!0},children:(0,t.jsx)(j.sA,{id:"SETTINGS_COMMON_CONFIGURATION_FILE"})}),(0,t.jsxs)(J.A,{maxWidth:"100%",flexDirection:"column",children:[(0,t.jsxs)(J.A,{gap:Q.xO,alignItems:"center",maxWidth:"100%",overflow:"hidden",minHeight:H.b,children:[(0,t.jsx)(ne,{onChange:async e=>{const i=e.target?.files?.[0];n.onChange(i?{name:i.name,content:await(0,X.Gu)(i).catch(()=>{})}:null)},variant:"inline",size:"medium",Icon:a?Y.A:w.A,iconProps:{isActive:!0},children:a?(0,t.jsx)(Z.A,{variant:"inherit",isTruncated:!0,children:i||(0,t.jsx)(j.sA,{id:"SETTINGS_COMMON_CONFIGURATION_FILE"})}):(0,t.jsx)(j.sA,{id:"COMMON_UPLOAD"})},i),a?(0,t.jsxs)(J.A,{gap:Q.YC,alignItems:"center",children:[r?(0,t.jsx)(y.A,{component:"a",href:r,download:i,Icon:k.A,variant:"inline"}):null,(0,t.jsx)(y.A,{Icon:V.A,variant:"inline",color:"danger",onClick:()=>n.onChange(null)})]}):null]}),(0,t.jsx)($.Ay,{form:e,name:"configuration_file",noMargin:!0})]}),(0,t.jsx)("input",{type:"hidden",...n,value:n.value?.content})]})},te="bgp-settings-form",oe=({activeItem:e,typeSelector:n})=>{const i=(0,o.wA)(),p=(0,a.W6)(),x=(0,d.A)(`${f.p7}?${f.Rp}=${f.O4}`),v=(0,o.d4)(u.vc),j=!e?._id||e._id?.startsWith(f.R6)?void 0:e,h=(0,o.d4)(A.oP),U=(0,l.A)(E.Xj.UNBOUND_WAN_MONITOR),D=!!j,M=(0,O.m)({schema:C,defaultValues:R(e,h)});(0,c.y)(M);const b=(0,_.FH)({control:M.control,name:"device_mac"}),B=(0,s.useMemo)(()=>M.handleSubmit(async e=>{const n=e.device_mac===v,t={_id:j?._id,enabled:!j?._id||j.enabled,frr_bgpd_config:e.configuration_file.content,uploaded_file_name:e.configuration_file.name,description:e.name,device_mac:n?void 0:e.device_mac},o=D?S.B7:S.kY;try{await i(o(n,t)),n&&U&&await i((0,N.fU)({...h,unbind_wan_monitors:e.unbind_wan_monitors})),i((0,S.kC)()),i((0,I.SQ)(!1)),i((0,I.K5)()),j||p.push(x)}catch{i((0,T.ox)({icon:r.C.danger,message:"SETTINGS_ROUTING_BGP_SAVE_ERROR"}))}}),[M,v,j,D,i,U,h,p,x]);return(0,t.jsxs)("form",{onSubmit:B,id:te,children:[(0,t.jsxs)(m.A,{children:[n,(0,t.jsx)(P,{form:M}),(0,t.jsx)(F,{form:M,isExistingRecord:!!j}),(0,t.jsx)(ie,{form:M}),U&&b===v?(0,t.jsx)(g,{form:M}):null]}),(0,t.jsx)(G.A,{onFormSubmit:B,onFormCancel:()=>M.reset(),isDirty:M.formState.isDirty||!j,hideCancelButton:!M.formState.isDirty,submitButtonText:j?void 0:"COMMON_ACTION_ADD",form:te,isSubmitting:M.formState.isSubmitting})]},e._id)}},155514(e,n,i){i.r(n),i.d(n,{default:()=>M});var t=i(274934),o=i(977872),a=i(602086),_=i(956976),s=i(724081),r=i(871808),c=i(846294),d=i(787481),l=i(470070),O=i(106047),m=i(897166),I=i(95857),T=i(754924),A=i(741331),N=i(969288),u=i(515215),E=i(129401),S=i(8834),f=i(122985),G=i(379727),R=i(233114),p=i(880976),x=i(699177),C=i(694911),v=i(277299);const j=[u.Z.OSPF,u.Z.BGP,u.Z.STATIC_ROUTE,u.Z.POLICY_BASED_ROUTE],g={[u.Z.BGP]:"SETTINGS_ROUTING_BGP_NAME",[u.Z.OSPF]:"SETTINGS_ROUTING_OSPF_NAME",[u.Z.STATIC_ROUTE]:"COMMON_STATIC",[u.Z.POLICY_BASED_ROUTE]:"COMMON_POLICY_BASED"},h={[u.Z.BGP]:C.default,[u.Z.OSPF]:R.default,[u.Z.STATIC_ROUTE]:E.A,[u.Z.POLICY_BASED_ROUTE]:f.A},P={[u.Z.BGP]:x.default.getDependencies(),[u.Z.OSPF]:p.default.getDependencies(),[u.Z.STATIC_ROUTE]:S.default.getDependencies(),[u.Z.POLICY_BASED_ROUTE]:G.default.getDependencies()},U=({type:e,typeSelector:n})=>{const i=(0,t.jsx)(h[e],{typeSelector:n,activeItem:{_id:N.R6}});return(0,s.A)(P[e]||[],i,{renderKey:e,placeholder:(0,t.jsx)(a.Fragment,{children:i},"fallback"),pastDelay:0})},D=({activeItem:e})=>{const n=(0,r.A)(I.Xj.OSPF_ROUTING),i=(0,r.A)(I.Xj.BGP_ROUTING),s=(0,r.A)(I.Xj.SWITCH_BGP_ROUTING),N=(0,o.d4)(O.Z0),E=(0,o.d4)(A._V),S=(0,o.d4)(m.vc),f=(0,o.d4)(T.n_),G=(0,a.useMemo)(()=>j.map(e=>({option:e,disabledReason:(0,v.x)(e,N,E,f,S,i,s,n)})),[f,E,i,n,s,N,S]),[R,p]=(0,a.useState)(()=>{const n=G.filter(({disabledReason:e})=>!e);return e.type&&n.some(({option:n})=>n===e.type)?e.type:n[0]?.option??u.Z.STATIC_ROUTE});return(0,t.jsx)(U,{type:R,typeSelector:(0,t.jsx)(d.A,{children:G.map(({option:e,disabledReason:n})=>(0,t.jsx)(c.A,{reason:R!==e&&n,children:(0,t.jsx)(_.A,{value:e,id:e,checked:R===e,onChange:()=>p(e),disabled:!!n&&R!==e,children:(0,t.jsx)(l.sA,{id:g[e]})})},e))})},R)},M=({activeItem:e})=>(0,t.jsx)(D,{activeItem:e},e.type)},277299(e,n,i){i.d(n,{x:()=>r});var t=i(274934),o=i(470070),a=i(788307),_=i(586566),s=i(515215);const r=(e,n,i,r,c,d,l,O)=>e===s.Z.STATIC_ROUTE||e===s.Z.POLICY_BASED_ROUTE?null:e!==s.Z.OSPF||O?e!==s.Z.OSPF||r.some(e=>(0,a.Y)(e,O,c)&&!n.some(n=>(n.device_mac??c)===e.mac))?e!==s.Z.BGP||d||l?e!==s.Z.BGP||r.filter(e=>(0,_.Et)(e.switch_caps?.feature_caps)).map(({mac:e})=>e).concat(d&&c?[c]:[]).some(e=>!i.some(({device_mac:n})=>n===e))?null:(0,t.jsx)(o.sA,{id:"SETTINGS_ROUTING_BGP_ALREADY_CONFIGURED_DEVICES"}):(0,t.jsx)(o.sA,{id:"SETTINGS_BGP_NOT_SUPPORTED"}):(0,t.jsx)(o.sA,{id:"SETTINGS_ROUTING_OSPF_ALREADY_CONFIGURED_DEVICES"}):(0,t.jsx)(o.sA,{id:"SETTINGS_OSPF_NOT_SUPPORTED"})}}]);