import{al as y,an as k,am as l,bJ as R,u as v,aD as B,r as c,s as T,j as a,bw as E,B as i,gP as F,y as K,b5 as m,b4 as q,bs as $,aE as D}from"./index-C1DmWO_C.js";import{F as S}from"./SingleSelect-DvF8BLvQ.js";import{g as J}from"./index-CxmfBMSc.js";import{u as M}from"./useKafkaSubjects-yrv5Kxme.js";const I=y().shape({name:k().label("Name").required(),schemaName:k().label("Schema Name"),numOfReplicas:l().label("Number of Replicas").required(),numOfPartitions:l().label("Number Of Partitions").required(),schemaVersion:l().nullable()}),A=()=>{var d,p,b,x,g;const u=R(),{id:N}=v(),{subjects:t}=M(),[C,{isLoading:P,isSuccess:f}]=J(),e=B({defaultValues:{name:"",schemaName:"",numOfReplicas:1,numOfPartitions:1,schemaVersion:null},resolver:D(I),shouldUnregister:!1,mode:"onChange"}),h=e.watch("schemaName"),r=c.useMemo(()=>{var s;return((s=t.find(n=>n.name===h))==null?void 0:s.versions)||[]},[t,h]),o=c.useCallback(()=>u(T.project.settings.kafka.view),[u]),V=s=>{var j;const n=((j=t.find(w=>w.name===s))==null?void 0:j.versions)||[];e.setValue("schemaVersion",String(n[n.length-1]))},O=e.handleSubmit(s=>C({id:N,data:s}));return c.useEffect(()=>{f&&o()},[f,o]),a.jsx(E,{...e,children:a.jsxs(i,{flexDirection:"column",children:[a.jsx(F,{mr:"auto",mode:"highlight",onClick:o,children:"<- back to all Kafka Topics"}),a.jsxs(K,{my:"20px",title:"Create a new Kafka topic",children:[a.jsxs(i,{mb:"20px",sx:{gap:"20px"},children:[a.jsx(m,{label:"Name",placeholder:"kafka topic name",labelProps:{flex:1},intent:(d=e.formState.errors)!=null&&d.name?"error":"default",...e.register("name")}),a.jsx(m,{width:"260px",label:"Number of partitions",intent:(p=e.formState.errors)!=null&&p.numOfPartitions?"error":"default",...e.register("numOfPartitions")}),a.jsx(m,{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:V,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:(g=e.formState.errors)!=null&&g.schemaVersion?"error":"default",control:e.control})]}),a.jsxs(i,{justifyContent:"flex-end",children:[a.jsx(q,{mr:"8px",intent:"secondary",onClick:o,children:"Back"}),a.jsx($,{disabled:P,onClick:O,children:"Create Topic"})]})]})]})})};export{A as default};
