import{i as r}from"./_virtual___federation_fn_import-DB-0B1B_.js";import{a as R}from"./zod-DVFqTTZn.js";import{s as j}from"./sortBy-C9bvycg5.js";const{createModelBaseSchema:x,FeatureUtils:E,modelEntityType:g,ModelUtils:B}=await r("@baseplate-dev/project-builder-lib"),{useDefinitionSchema:D,useProjectDefinition:O,useResettableForm:T}=await r("@baseplate-dev/project-builder-lib/web"),{useEventCallback:k}=await r("@baseplate-dev/ui-components"),{useMemo:u,useRef:I}=await r("react");function N({onSubmitSuccess:h,omit:w,modelKey:y}){const{definition:i,saveDefinitionWithFeedback:m}=O(),v=g.idFromKey(y),e=B.byIdOrThrow(i,v),n=D(x),a=I(w),c=u(()=>a.current?n.omit(Object.fromEntries(a.current.map(o=>[o,!0]))):n,[n]),d=u(()=>a.current?c.parse(e):e,[e,c]),f=T({resolver:R(c),defaultValues:d}),{reset:b,handleSubmit:p,setError:M}=f,S=k(h),F=u(()=>p(o=>{const t={...e,...o};if(i.models.find(s=>s.id!==o.id&&s.name.toLowerCase()===t.name.toLowerCase())){M("name",{message:`Model with name ${t.name} already exists.`});return}return m(s=>{t.featureRef=E.ensureFeatureByNameRecursively(s,t.featureRef),s.models=j([...s.models.filter(l=>l.id!==t.id),t],[l=>l.name])},{successMessage:"Successfully saved model!",onSuccess:()=>{b(o),S?.()}})}),[b,M,p,m,S,i,e]);return{form:f,onSubmit:F,originalModel:e,defaultValues:d}}export{N as u};
//# sourceMappingURL=use-model-form-BPP1LIM-.js.map
