import{r as m,j as e}from"./vendor-react-wBh_31cN.js";import{o as P}from"./yup-XkUC3UEH.js";import{r as R,G as w,ar as T,az as c,as as k}from"./index-dNe6i2rS.js";import{B as F}from"./back-button-CQo-pvZ0.js";import{C as y,a as K,b as q,c as E}from"./card-BeQtvmcJ.js";import{I as l}from"./input-DFI7JniT.js";import{L as n}from"./label-gPWmc6ow.js";import{u as L,F as $}from"./index.esm-CAGtek53.js";import{F as g}from"./SingleSelect-CAFSLL98.js";import{u as I}from"./useProjectNavigate-BM67yKhl.js";import{f as M}from"./index-DoDc9bBo.js";import{B as z}from"./ButtonWithRole-ruQLmPtQ.js";import{u as G}from"./useKafkaSubjects-BQ7CcrEP.js";import{c as H}from"./vendor-router-D1GqFWiT.js";import"./vendor-redux-CJZrIb6x.js";import"./vendor-utils-OeoE2qq_.js";import"./vendor-icons-BUUmD6ht.js";import"./vendor-radix-BRyWS4bQ.js";import"./vendor-grid-CeFlDWv4.js";import"./combobox-QqI9aNup.js";import"./input-group-gxy3DSmS.js";import"./textarea-BJVuSob1.js";import"./vendor-recharts-DmJlpLaF.js";import"./tooltip-DFFgUYh6.js";import"./project-eQY1xQe-.js";import"./useProjectRole-DpUIGfh9.js";import"./index-DURBtSjL.js";const U=T().shape({name:k().label("Name").required(),schemaName:k().label("Schema Name"),numOfReplicas:c().label("Number of Replicas").required(),numOfPartitions:c().label("Number Of Partitions").required(),schemaVersion:c().nullable()}),je=()=>{var u,h,x,b,j;const d=I(),{id:S}=H(),{subjects:r}=G(),[C,{isLoading:v,isSuccess:p}]=M(),a=L({defaultValues:{name:"",schemaName:"",numOfReplicas:1,numOfPartitions:1,schemaVersion:null},resolver:P(U),shouldUnregister:!1,mode:"onChange"}),f=a.watch("schemaName"),t=m.useMemo(()=>{var s;return((s=r.find(i=>i.name===f))==null?void 0:s.versions)||[]},[r,f]),o=m.useCallback(()=>d(R.project.settings.kafka.view),[d]),V=s=>{var N;const i=((N=r.find(B=>B.name===s))==null?void 0:N.versions)||[];a.setValue("schemaVersion",String(i[i.length-1]))},O=a.handleSubmit(s=>C({id:S,data:s}));return m.useEffect(()=>{p&&o()},[p,o]),e.jsx($,{...a,children:e.jsxs("div",{className:"flex flex-col",children:[e.jsx(F,{className:"mr-auto",onClick:o,children:"back to all Kafka Topics"}),e.jsxs(y,{className:"my-5",children:[e.jsx(K,{children:e.jsx(q,{children:"Create a new Kafka topic"})}),e.jsxs(E,{children:[e.jsxs("div",{className:"mb-5 flex gap-5",children:[e.jsxs("div",{className:"flex-1",children:[e.jsx(n,{className:"mb-1.5",children:"Name"}),e.jsx(l,{placeholder:"kafka topic name",className:(u=a.formState.errors)!=null&&u.name?"border-destructive":"",...a.register("name")})]}),e.jsxs("div",{className:"w-[260px]",children:[e.jsx(n,{className:"mb-1.5",children:"Number of partitions"}),e.jsx(l,{className:(h=a.formState.errors)!=null&&h.numOfPartitions?"border-destructive":"",...a.register("numOfPartitions")})]}),e.jsxs("div",{className:"w-[260px]",children:[e.jsx(n,{className:"mb-1.5",children:"Number of replicas"}),e.jsx(l,{className:(x=a.formState.errors)!=null&&x.numOfReplicas?"border-destructive":"",...a.register("numOfReplicas")})]})]}),e.jsxs("div",{className:"mb-5 flex gap-5",children:[e.jsx(g,{className:"flex-1",label:"Schema",name:"schemaName",placeholder:"pick a kafka schema",options:r.map(s=>({label:s.name,key:s.name})),state:(b=a.formState.errors)!=null&&b.schemaName?"error":"default",onSelectionChange:V,control:a.control}),e.jsx(g,{className:"w-[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=a.formState.errors)!=null&&j.schemaVersion?"error":"default",control:a.control})]}),e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx(w,{variant:"outline",onClick:o,children:"Back"}),e.jsx(z,{disabled:v,onClick:O,children:"Create Topic"})]})]})]})]})})};export{je as default};
