import{i as s}from"./_virtual___federation_fn_import-DB-0B1B_.js";import{j as e}from"./jsx-runtime-u17CrQMm.js";import{a as S}from"./zod-DVFqTTZn.js";import{a as C}from"./index.esm-CTnR63pP.js";import{l as N}from"./error-formatter-B41KnHG1.js";import{M as k}from"./model-info-form-CeorchK4.js";import{s as B}from"./sortBy-C9bvycg5.js";const{createModelBaseSchema:I,FeatureUtils:R,modelEntityType:y,modelScalarFieldEntityType:E}=await s("@baseplate-dev/project-builder-lib"),{useBlockBeforeContinue:O,useDefinitionSchema:T,useProjectDefinition:L}=await s("@baseplate-dev/project-builder-lib/web"),{Button:p,Dialog:$,DialogClose:A,DialogContent:G,DialogDescription:H,DialogFooter:K,DialogHeader:P,DialogTitle:U,DialogTrigger:V,useControlledState:W}=await s("@baseplate-dev/ui-components"),{useNavigate:q}=await s("@tanstack/react-router"),{useMemo:g}=await s("react");function h(){const a=E.generateNewId();return{id:y.generateNewId(),name:"",featureRef:"",service:{create:{enabled:!1},update:{enabled:!1},delete:{enabled:!1},transformers:[]},model:{primaryKeyFieldRefs:[a],fields:[{id:a,name:"id",type:"uuid",isOptional:!1,options:{defaultGeneration:"uuidv7"}}]}}}function oe({trigger:a,open:x,onOpenChange:b}){const[j,r]=W(x,b,!1),{definition:l,saveDefinitionWithFeedback:d}=L(),M=T(I),w=g(()=>h(),[]),c=q(),{handleSubmit:m,reset:u,setError:f,control:D}=C({resolver:S(M),defaultValues:w}),v=g(()=>m(o=>{if(l.models.find(t=>t.name.toLowerCase()===o.name.toLowerCase())){f("name",{message:`Model with name ${o.name} already exists.`});return}return d(t=>{const i={...o};i.featureRef=R.ensureFeatureByNameRecursively(t,i.featureRef),t.models=B([...t.models.filter(n=>n.id!==i.id),i],[n=>n.name])},{successMessage:"Successfully created model!",onSuccess:()=>{c({to:"/data/models/edit/$key",params:{key:y.keyFromId(o.id)}}).catch(N),u(h()),r(!1)}})}),[u,f,m,d,c,l,r]),F=O();return e.jsxs($,{open:j,onOpenChange:o=>{o?F({onContinue:()=>{r(!0)}}):r(!1)},children:[e.jsx(V,{render:a}),e.jsxs(G,{children:[e.jsxs(P,{children:[e.jsx(U,{children:"New Model"}),e.jsx(H,{children:"Models define the structure of your data."})]}),e.jsxs("form",{onSubmit:v,className:"space-y-4",children:[e.jsx(k,{control:D}),e.jsxs(K,{children:[e.jsx(A,{render:e.jsx(p,{variant:"secondary"}),children:"Cancel"}),e.jsx(p,{type:"submit",children:"Create Model"})]})]})]})]})}export{oe as N};
//# sourceMappingURL=new-model-dialog-B_egJqp8.js.map
