import{j as e,G as B,L as y,s as b}from"./vendor-tanstack-BVzzyDEt.js";import{B as N,a as v,b as n,bq as i,bz as d,bB as _,dS as F,ad as S,G as C,aj as L,ak as w,al as E,am as D,an as P,ao as T,ap as U,q as h,w as u,dT as A,cY as G,dU as R}from"./index-BJkJ93Lr.js";import{d as V,b as z,c as I}from"./vendor-forms-BN3tpxM2.js";import{B as Q}from"./block-type-details-CUkO-JbV.js";import{u as q,L as M}from"./lazy-schema-form-Clp5QfAW.js";import"./primitives-BxgEGUr4.js";import"./toggle-group-B18EYoB-.js";import"./vendor-react-Bce9NwRC.js";import"./vendor-radix-CTAic6HB.js";import"./vendor-recharts-Mwm2qLZp.js";import"./vendor-date-2jFo9aCm.js";import"./block-type-logo-ESEG5U5y.js";import"./lazy-markdown-CwRqR_1U.js";const $=({blockType:s})=>e.jsx(N,{children:e.jsxs(v,{children:[e.jsx(n,{children:e.jsx(i,{to:"/blocks",className:"text-xl font-semibold",children:"Blocks"})}),e.jsx(d,{}),e.jsx(n,{children:e.jsx(i,{to:"/blocks/catalog",className:"text-xl font-semibold",children:"Catalog"})}),e.jsx(d,{}),e.jsx(n,{children:e.jsx(i,{to:"/blocks/catalog",className:"text-xl font-semibold",children:s.name})}),e.jsx(d,{}),e.jsx(n,{className:"text-xl font-semibold",children:e.jsx(_,{children:"Create"})})]})}),H=/^[a-zA-Z0-9-]+$/,K=z({blockName:I().regex(H,{message:"Name must only contain lowercase letters, numbers, and dashes"})}),O={blockName:""},X=({blockSchema:s,blockType:a})=>{const l=B(),{values:o,setValues:j,errors:x,validateForm:p}=q(),{createBlockDocument:k,isPending:g}=F(),m=V({resolver:S(K),defaultValues:O}),f=async r=>{try{if(await p({schema:o}),x.length>0)return;k({block_schema_id:s.id,block_type_id:a.id,is_anonymous:!1,data:o,name:r.blockName},{onSuccess:c=>{u.success("Block created successfully"),l({to:"/blocks/block/$id",params:{id:c.id}})},onError:c=>{const t="Unknown error while creating block.";u.error(t),console.error(t,c)}})}catch(c){const t="Unknown error while validating block data.";u.error(t),console.error(t,c)}};return e.jsxs("div",{className:"flex flex-col gap-6",children:[e.jsx($,{blockType:a}),e.jsxs(C,{className:" p-6 grid grid-cols-[minmax(0,_1fr)_250px] gap-4 ",children:[e.jsx(L,{...m,children:e.jsxs("form",{className:"flex flex-col gap-4",onSubmit:r=>{m.handleSubmit(f)(r)},children:[e.jsx(w,{control:m.control,name:"blockName",render:({field:r})=>e.jsxs(E,{children:[e.jsx(D,{children:"Name"}),e.jsx(P,{children:e.jsx(T,{...r,value:r.value})}),e.jsx(U,{})]})}),e.jsx(M,{values:o,onValuesChange:j,errors:x,kinds:["json"],schema:s.fields}),e.jsxs("div",{className:"flex gap-3 justify-end",children:[e.jsx(h,{variant:"secondary",children:e.jsx(y,{to:"/blocks/catalog",children:"Cancel"})}),e.jsx(h,{loading:g,type:"submit",children:"Save"})]})]})}),e.jsx(Q,{blockType:a})]})]})};function me(){const{slug:s}=A.useParams(),{data:a}=b(G(s)),{data:l}=b(R({block_schemas:{block_type_id:{any_:[a.id]},operator:"and_"},offset:0})),o=l[0];if(!o)throw new Error("Block schema not found");return e.jsx(X,{blockSchema:o,blockType:a})}export{me as component};
//# sourceMappingURL=catalog_._slug_.create-DBoaVnUg.js.map
