import{b9 as w,u as y,aC as R,aD as T,ar as F,r as l,t as K,j as a,bw as q,a as i,gS as B,W as E,aH as c,aJ as W,bs as $,av as m,au as k}from"./index-_eM6l4Nf.js";import{F as S}from"./SingleSelect-DCo75wUx.js";import{g as D}from"./index-CmVntchS.js";import{u as J}from"./useKafkaSubjects-BGC8dCvd.js";const M=F().shape({name:k().label("Name").required(),schemaName:k().label("Schema Name"),numOfReplicas:m().label("Number of Replicas").required(),numOfPartitions:m().label("Number Of Partitions").required(),schemaVersion:m().nullable()}),z=()=>{var d,p,b,x,j;const u=w(),{id:N}=y(),{subjects:t}=J(),[C,{isLoading:V,isSuccess:f}]=D(),e=R({defaultValues:{name:"",schemaName:"",numOfReplicas:1,numOfPartitions:1,schemaVersion:null},resolver:T(M),shouldUnregister:!1,mode:"onChange"}),h=e.watch("schemaName"),r=l.useMemo(()=>{var s;return((s=t.find(n=>n.name===h))==null?void 0:s.versions)||[]},[t,h]),o=l.useCallback(()=>u(K.project.settings.kafka.view),[u]),O=s=>{var g;const n=((g=t.find(v=>v.name===s))==null?void 0:g.versions)||[];e.setValue("schemaVersion",String(n[n.length-1]))},P=e.handleSubmit(s=>C({id:N,data:s}));return l.useEffect(()=>{f&&o()},[f,o]),a.jsx(q,{...e,children:a.jsxs(i,{flexDirection:"column",children:[a.jsx(B,{mr:"auto",mode:"highlight",onClick:o,children:"<- back to all Kafka Topics"}),a.jsxs(E,{my:"20px",title:"Create a new Kafka topic",children:[a.jsxs(i,{mb:"20px",sx:{gap:"20px"},children:[a.jsx(c,{label:"Name",placeholder:"kafka topic name",labelProps:{flex:1},intent:(d=e.formState.errors)!=null&&d.name?"error":"default",...e.register("name")}),a.jsx(c,{width:"260px",label:"Number of partitions",intent:(p=e.formState.errors)!=null&&p.numOfPartitions?"error":"default",...e.register("numOfPartitions")}),a.jsx(c,{width:"260px",label:"Number of replicas",intent:(b=e.formState.errors)!=null&&b.numOfReplicas?"error":"default",...e.register("numOfReplicas")})]}),a.jsxs(i,{mb:"20px",sx:{gap:"20px"},children:[a.jsx(S,{flex:"1",label:"Schema",name:"schemaName",placeholder:"pick a kafka schema",options:t.map(s=>({label:s.name,key:s.name})),state:(x=e.formState.errors)!=null&&x.schemaName?"error":"default",onSelectionChange:O,control:e.control}),a.jsx(S,{width:"150px",label:"Version",name:"schemaVersion",placeholder:"pick a version",disabled:!r.length,options:r==null?void 0:r.map(s=>({label:String(s),key:String(s)})),state:(j=e.formState.errors)!=null&&j.schemaVersion?"error":"default",control:e.control})]}),a.jsxs(i,{justifyContent:"flex-end",children:[a.jsx(W,{mr:"8px",intent:"secondary",onClick:o,children:"Back"}),a.jsx($,{disabled:V,onClick:P,children:"Create Topic"})]})]})]})})};export{z as default};
