import{ba as v,u as w,aA as q,aB as y,r as l,x as B,j as a,bF as F,q as i,gS as T,f as K,aH as c,aJ as $,bB as E,Z as M,a0 as m,as as k}from"./index-Cox3ZWL0.js";import{F as S}from"./SingleSelect-BT2eGsJi.js";import{f as A}from"./index-DFIJFuHt.js";import{u as D}from"./useKafkaSubjects-LNl6JsdO.js";const H=M().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()}),Z=()=>{var d,p,x,b,j;const u=v(),{id:N}=w(),{subjects:t}=D(),[C,{isLoading:P,isSuccess:f}]=A(),e=q({defaultValues:{name:"",schemaName:"",numOfReplicas:1,numOfPartitions:1,schemaVersion:null},resolver:y(H),shouldUnregister:!1,mode:"onChange"}),h=e.watch("schemaName"),r=l.useMemo(()=>{var s;return((s=t.find(n=>n.name===h))==null?void 0:s.versions)||[]},[t,h]),o=l.useCallback(()=>u(B.project.settings.kafka.view),[u]),V=s=>{var g;const n=((g=t.find(R=>R.name===s))==null?void 0:g.versions)||[];e.setValue("schemaVersion",String(n[n.length-1]))},O=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(T,{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(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:(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:t.map(s=>({label:s.name,key:s.name})),state:(b=e.formState.errors)!=null&&b.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:(j=e.formState.errors)!=null&&j.schemaVersion?"error":"default",control:e.control})]}),a.jsxs(i,{justifyContent:"flex-end",children:[a.jsx($,{mr:"8px",intent:"secondary",onClick:o,children:"Back"}),a.jsx(E,{disabled:P,onClick:O,children:"Create Topic"})]})]})]})})};export{Z as default};
