import{aj as B,al as g,ak as l,bL as R,u as w,az as y,r as c,s as T,j as a,bB as F,B as i,aX as K,m as q,aM as m,aG as E,aA as M}from"./index-dP1W1_bd.js";import{F as S}from"./SingleSelect-B8f6hurf.js";import{g as $}from"./index-D4-3j93o.js";import{B as L}from"./ButtonWithRole-CF64B_Or.js";import{u as z}from"./useKafkaSubjects-BmqeePeS.js";const A=B().shape({name:g().label("Name").required(),schemaName:g().label("Schema Name"),numOfReplicas:l().label("Number of Replicas").required(),numOfPartitions:l().label("Number Of Partitions").required(),schemaVersion:l().nullable()}),H=()=>{var h,d,x,b,j;const u=R(),{id:N}=w(),{subjects:r}=z(),[C,{isLoading:V,isSuccess:f}]=$(),e=y({defaultValues:{name:"",schemaName:"",numOfReplicas:1,numOfPartitions:1,schemaVersion:null},resolver:M(A),shouldUnregister:!1,mode:"onChange"}),p=e.watch("schemaName"),t=c.useMemo(()=>{var s;return((s=r.find(n=>n.name===p))==null?void 0:s.versions)||[]},[r,p]),o=c.useCallback(()=>u(T.project.settings.kafka.view),[u]),O=s=>{var k;const n=((k=r.find(v=>v.name===s))==null?void 0:k.versions)||[];e.setValue("schemaVersion",String(n[n.length-1]))},P=e.handleSubmit(s=>C({id:N,data:s}));return c.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(q,{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:(d=e.formState.errors)!=null&&d.numOfPartitions?"error":"default",...e.register("numOfPartitions")}),a.jsx(m,{width:"260px",label:"Number of replicas",intent:(x=e.formState.errors)!=null&&x.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:(b=e.formState.errors)!=null&&b.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:(j=e.formState.errors)!=null&&j.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(L,{disabled:V,onClick:P,children:"Create Topic"})]})]})]})})};export{H as default};
