import{b9 as R,u as w,aC as y,aD as T,ar as $,r as l,q,j as a,bv as F,$ as i,gQ as K,b as B,b2 as c,b1 as E,br as D,av as m,au as k}from"./index-46ma1THH.js";import{F as S}from"./SingleSelect-DyMHGSBW.js";import{g as M}from"./index-DIN48ET6.js";import{u as I}from"./useKafkaSubjects-ChuajI4E.js";const J=$().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()}),X=()=>{var d,p,b,x,g;const u=R(),{id:N}=w(),{subjects:r}=I(),[C,{isLoading:V,isSuccess:f}]=M(),e=y({defaultValues:{name:"",schemaName:"",numOfReplicas:1,numOfPartitions:1,schemaVersion:null},resolver:T(J),shouldUnregister:!1,mode:"onChange"}),h=e.watch("schemaName"),t=l.useMemo(()=>{var s;return((s=r.find(n=>n.name===h))==null?void 0:s.versions)||[]},[r,h]),o=l.useCallback(()=>u(q.project.settings.kafka.view),[u]),O=s=>{var j;const n=((j=r.find(v=>v.name===s))==null?void 0:j.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(F,{...e,children:a.jsxs(i,{flexDirection:"column",children:[a.jsx(K,{mr:"auto",mode:"highlight",onClick:o,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:(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:r.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:!t.length,options:t==null?void 0:t.map(s=>({label:String(s),key:String(s)})),state:(g=e.formState.errors)!=null&&g.schemaVersion?"error":"default",control:e.control})]}),a.jsxs(i,{justifyContent:"flex-end",children:[a.jsx(E,{mr:"8px",intent:"secondary",onClick:o,children:"Back"}),a.jsx(D,{disabled:V,onClick:P,children:"Create Topic"})]})]})]})})};export{X as default};
