import{ae as v,ag as k,af as l,bg as w,u as y,au as T,r as c,q,j as a,ba as B,d as i,f_ as F,Q as K,aR as m,b6 as E,av as $}from"./index-CK33qGU_.js";import{F as S}from"./SingleSelect-CV8k2k_j.js";import{g as M}from"./index-CBcuRugC.js";import{B as Q}from"./ButtonWithRole-NHXEosto.js";import{u as D}from"./useKafkaSubjects-BADlktnE.js";const J=v().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 h,p,b,x,g;const u=w(),{id:N}=y(),{subjects:r}=D(),[C,{isLoading:V,isSuccess:f}]=M(),e=T({defaultValues:{name:"",schemaName:"",numOfReplicas:1,numOfPartitions:1,schemaVersion:null},resolver:$(J),shouldUnregister:!1,mode:"onChange"}),d=e.watch("schemaName"),t=c.useMemo(()=>{var s;return((s=r.find(n=>n.name===d))==null?void 0:s.versions)||[]},[r,d]),o=c.useCallback(()=>u(q.project.settings.kafka.view),[u]),P=s=>{var j;const n=((j=r.find(R=>R.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(B,{...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:(h=e.formState.errors)!=null&&h.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:r.map(s=>({label:s.name,key:s.name})),state:(x=e.formState.errors)!=null&&x.schemaName?"error":"default",onSelectionChange:P,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(Q,{disabled:V,onClick:O,children:"Create Topic"})]})]})]})})};export{A as default};
