import{j as e,d as B,L as y,s as h}from"./vendor-tanstack-DE4ALVGD.js";import{B as N,g as v,h as n,bv as i,bE as d,bG as F,dj as _,C as S,p as C,q as b,y as u,dP as L,dh as E,di as w}from"./index-CNL5pSma.js";import{a as D}from"./zod-2_bJZbih.js";import{c as P,o as A,s as R}from"./vendor-forms-BvpM0AtX.js";import{B as T}from"./block-type-details-heMLWolY.js";import{u as U,L as V}from"./schema-form-input-string-format-datetime-B98i_B5d.js";import{F as G,b as I,c as Q,d as z,e as M,a as $}from"./form-_6uPI_KA.js";import"./vendor-react-HBv6Kpyp.js";import"./vendor-radix-K8EF6rBE.js";import"./vendor-recharts-B3wzJa9e.js";import"./vendor-date-Bck8LDfw.js";import"./block-type-logo-Ab-MB0rX.js";import"./lazy-markdown-Ds39cUgX.js";import"./use-debounce-callback-_1tAtOwa.js";import"./timezone-select-zsZ2PBlt.js";import"./dropdown-menu-D34zumpn.js";const q=({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(F,{children:"Create"})})]})}),H=/^[a-zA-Z0-9-]+$/,K=A({blockName:R().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:p,errors:x,validateForm:j}=U(),{createBlockDocument:k,isPending:f}=_(),m=P({resolver:D(K),defaultValues:O}),g=async r=>{try{if(await j({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:t=>{u.success("Block created successfully"),l({to:"/blocks/block/$id",params:{id:t.id}})},onError:t=>{const c="Unknown error while creating block.";u.error(c),console.error(c,t)}})}catch(t){const c="Unknown error while validating block data.";u.error(c),console.error(c,t)}};return e.jsxs("div",{className:"flex flex-col gap-6",children:[e.jsx(q,{blockType:a}),e.jsxs(S,{className:" p-6 grid grid-cols-[minmax(0,_1fr)_250px] gap-4 ",children:[e.jsx(G,{...m,children:e.jsxs("form",{className:"flex flex-col gap-4",onSubmit:r=>{m.handleSubmit(g)(r)},children:[e.jsx(I,{control:m.control,name:"blockName",render:({field:r})=>e.jsxs(Q,{children:[e.jsx(z,{children:"Name"}),e.jsx(M,{children:e.jsx(C,{...r,value:r.value})}),e.jsx($,{})]})}),e.jsx(V,{values:o,onValuesChange:p,errors:x,kinds:["json"],schema:s.fields}),e.jsxs("div",{className:"flex gap-3 justify-end",children:[e.jsx(b,{variant:"secondary",children:e.jsx(y,{to:"/blocks/catalog",children:"Cancel"})}),e.jsx(b,{loading:f,type:"submit",children:"Save"})]})]})}),e.jsx(T,{blockType:a})]})]})};function ue(){const{slug:s}=L.useParams(),{data:a}=h(E(s)),{data:l}=h(w({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{ue as component};
//# sourceMappingURL=catalog_._slug_.create-BgHq2Nyq.js.map
