import{a7 as K,a9 as g,a8 as k,b1 as R,u as T,am as y,r as l,e as q,j as a,aW as E,a as i,hp as F,K as B,aG as c,fN as S,aT as N,an as D}from"./index-d6499a22.js";import{g as L}from"./index-0e1d5e0b.js";import{u as M}from"./useKafkaSubjects-67007d33.js";const $=K().shape({name:g().label("Name").required(),schemaName:g().label("Schema Name"),numOfReplicas:k().label("Number of Replicas").required(),numOfPartitions:k().label("Number Of Partitions").required()}),z=()=>{var d,h,p,x,b;const m=R(),{id:C}=T(),{subjects:r}=M(),[O,{isLoading:P,isSuccess:u}]=L(),e=y({defaultValues:{name:"",schemaName:"",numOfReplicas:1,numOfPartitions:1,schemaVersion:null},resolver:D($),shouldUnregister:!1,mode:"onChange"}),f=e.watch("schemaName"),t=l.useMemo(()=>{var s;return((s=r.find(o=>o.name===f))==null?void 0:s.versions)||[]},[r,f]),n=l.useCallback(()=>m(q.project.settings.kafka.view),[m]),V=s=>{var j;const o=((j=r.find(w=>w.name===s))==null?void 0:j.versions)||[];e.setValue("schemaVersion",String(o[o.length-1]))},v=e.handleSubmit(s=>O({id:C,data:s}));return l.useEffect(()=>{u&&n()},[u,n]),a.jsx(E,{...e,children:a.jsxs(i,{flexDirection:"column",children:[a.jsx(F,{mr:"auto",mode:"highlight",onClick:n,children:"<- back to all Kafka Topics"}),a.jsxs(B,{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:(h=e.formState.errors)!=null&&h.numOfPartitions?"error":"default",...e.register("numOfPartitions")}),a.jsx(c,{width:"260px",label:"Number of replicas",intent:(p=e.formState.errors)!=null&&p.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:r.map(s=>({label:s.name,key:s.name})),state:(x=e.formState.errors)!=null&&x.schemaName?"error":"default",onSelectionChange:V,control:e.control}),a.jsx(S,{width:"150px",label:"Version",name:"schemaVersion",placeholder:"pick a version",disabled:!t.length,options:t==null?void 0:t.map(s=>({label:String(s),key:String(s)})),state:(b=e.formState.errors)!=null&&b.schemaVersion?"error":"default",control:e.control})]}),a.jsxs(i,{justifyContent:"flex-end",children:[a.jsx(N,{mr:"8px",intent:"secondary",onClick:n,children:"Back"}),a.jsx(N,{disabled:P,onClick:v,children:"Create Topic"})]})]})]})})};export{z as default};
