import{Y as v,c as L,_ as $}from"./Dyb1gHC6.js";import{d as O,r as d,a as j,o as P,j as H,H as w,t as f,N as W,A as u,x as c,z as o,v as x,B as g,y as V,$ as C,a0 as Y,U as F,a1 as z,C as K,D as R}from"./BuiHH9If.js";import{u as q}from"./Ditas79l.js";import{u as J,V as Q,b as X,a as Z}from"./DgDmD7eB.js";import{_ as ee,V as ae}from"./VWuwDkxo.js";import{A as te}from"./PpeMCrAR.js";import{V as oe,a as ne}from"./CvoSsIOf.js";import{_ as le}from"./DlAUqK2U.js";const se=L($),re=i=>(K("data-v-bcf9afdb"),i=i(),R(),i),ue={class:"pb-5"},ie={key:0,class:"mb-0"},de={key:1,class:"mb-0"},ce=re(()=>c("span",{class:"headline"},"Create New Scanner",-1)),pe={class:"mb-4"},me="yaml",ve=O({__name:"AgentGroupForm",props:{agentGroup:{type:Object,default:()=>({id:"",key:"",name:"",description:"",agents:{agents:[]}})},isEditMode:{type:Boolean,default:!1},scanner:{type:Object,default:()=>({endpoint:"",name:"",apiKey:""})}},emits:["close-form"],setup(i,{emit:N}){const y={id:"",key:"",name:"",description:"",agents:{agents:[]}},n=i,h=d(),S=N,_=J(),l=d(y),s=d(""),k={theme:"vs",wordWrap:"on",wordWrapColumn:"on",fontFamily:"Fira Code",automaticLayout:!0,minimap:{enabled:!1},Placeholder:!0,PlaceholderText:"Start typing here"},{$axios:U}=j(),b=new te(U),r=d(null),G=d([]),p=d(!1);P(()=>{s.value="",n.agentGroup!==null&&n.agentGroup!==void 0&&n.agentGroup.yamlSource!==null&&n.agentGroup.yamlSource!==void 0&&(s.value=n.agentGroup.yamlSource),n.scanner!==null&&n.scanner!==void 0&&(r.value=n.scanner)});const m=H(()=>r.value!=null&&s.value.trim()!==""),E=a=>{const e=v.stringify(v.parse(a));if(e!=null)return e},I=async()=>{if(m.value==!0&&l.value!==null)try{const a=E(s.value);if(r.value!==null&&a!==null&&a!==void 0){const e=v.parse(a);n.isEditMode==!0&&await b.deleteAgentGroup(r.value,parseInt(l.value.id)),await b.createAgentGroup({scanner:r.value,agentGroup:{description:l.value.description||"",agents:e==null?void 0:e.agents,name:l.value.name}})}A(),S("close-form"),_.reportSuccess("Agent group saved successfully.")}catch(a){_.reportError((a==null?void 0:a.message)||"Failed to save Agent group information. Please try again.")}},A=()=>{l.value=y,s.value="",r.value=null},B=()=>{A(),S("close-form")},D=a=>{const e=(a.name||"").trim()!=="";return{title:e?a.name:a.endpoint,subtitle:e?a.endpoint:""}};w(()=>n.agentGroup,a=>{var e;l.value={...a},s.value=((e=n.agentGroup)==null?void 0:e.yamlSource)||""},{immediate:!0,deep:!0}),w(()=>s,a=>{s.value=a.value},{immediate:!0,deep:!0});const M=q();return G.value=M.scanners||[],(a,e)=>{const T=se;return f(),W(ae,{ref_key:"form",ref:h,modelValue:m.value,"onUpdate:modelValue":e[7]||(e[7]=t=>m.value=t),onSubmit:z(I,["prevent"])},{default:u(()=>[c("div",ue,[o(oe,{modelValue:r.value,"onUpdate:modelValue":e[1]||(e[1]=t=>r.value=t),items:G.value,"item-props":D,"hide-details":"",variant:"outlined","item-title":"endpoint",density:"compact",clearable:"","return-object":"",disabled:i.isEditMode,label:"Select a scanner",placeholder:"Select or create a scanner for the agent group"},{selection:u(({item:t})=>[(t.raw.name||"").trim()!==""?(f(),x("p",ie,[g(V(t.raw.name)+" (",1),c("code",null,V(t.raw.endpoint),1),g(") ")])):(f(),x("code",de,V(t.raw.endpoint),1))]),"no-data":u(()=>[c("p",{class:"create-scanner mb-0 pl-4 py-0",onClick:e[0]||(e[0]=t=>p.value=!0)}," Create New Scanner ")]),_:1},8,["modelValue","items","disabled"]),o(ne,{modelValue:p.value,"onUpdate:modelValue":e[3]||(e[3]=t=>p.value=t),persistent:"","max-width":"600px"},{default:u(()=>[o(Q,null,{default:u(()=>[o(X,null,{default:u(()=>[ce]),_:1}),o(Z,null,{default:u(()=>[o(ee,{onCloseForm:e[2]||(e[2]=t=>p.value=!1)})]),_:1})]),_:1})]),_:1},8,["modelValue"])]),o(C,{modelValue:l.value.name,"onUpdate:modelValue":e[4]||(e[4]=t=>l.value.name=t),variant:"outlined",density:"compact",label:"Agent Group Name",placeholder:"Agent Group Name"},null,8,["modelValue"]),o(C,{modelValue:l.value.description,"onUpdate:modelValue":e[5]||(e[5]=t=>l.value.description=t),variant:"outlined",density:"compact",label:"Agent Group Description",placeholder:"Agent Group Description"},null,8,["modelValue"]),c("div",pe,[o(Y,null,{default:u(()=>[g(" Agent Group Definition ")]),_:1}),o(T,{modelValue:s.value,"onUpdate:modelValue":e[6]||(e[6]=t=>s.value=t),lang:me,options:k,style:{"min-height":"300px"}},null,8,["modelValue"])]),o(F,{class:"me-2",type:"submit",color:"success",text:"Save","prepend-icon":"mdi-check",disabled:!m.value},null,8,["disabled"]),o(F,{text:"Cancel","prepend-icon":"mdi-close",onClick:B})]),_:1},8,["modelValue"])}}}),Ae=le(ve,[["__scopeId","data-v-bcf9afdb"]]);export{Ae as A};
