import{j as e,h as B,L as y,y as p}from"./vendor-tanstack-BpuysabX.js";import{B as N,g as v,h as m,bD as d,bQ as u,bS as F,cY as S,C as _,p as C,q as b,y as x,e1 as L,cW as w,cX as E}from"./index-CREafGO4.js";import{a as D}from"./zod-CtcMvSO9.js";import{c as P,o as A,s as Q}from"./vendor-forms-Buh7U8Ay.js";import{B as R}from"./block-type-details-CJxHA2oB.js";import{l as T,L as U}from"./schema-form-input-string-format-datetime-CtefOb8F.js";import{F as V,b as I,c as z,d as G,e as M,a as X}from"./form-DC8L1tSC.js";import"./vendor-radix-DIu41Ss_.js";import"./vendor-recharts-C2XeLr4O.js";import"./vendor-date-C1t37jsh.js";import"./block-type-logo-BNO1-Opd.js";import"./lazy-markdown-rmxkK4GI.js";import"./use-debounce-callback-Bybo1_Zg.js";import"./timezone-select-DpL0avEm.js";import"./dropdown-menu-DZExFL3b.js";const $=({blockType:o})=>e.jsx(N,{children:e.jsxs(v,{children:[e.jsx(m,{children:e.jsx(d,{to:"/blocks",className:"text-xl font-semibold",children:"Blocks"})}),e.jsx(u,{}),e.jsx(m,{children:e.jsx(d,{to:"/blocks/catalog",className:"text-xl font-semibold",children:"Catalog"})}),e.jsx(u,{}),e.jsx(m,{children:e.jsx(d,{to:"/blocks/catalog",className:"text-xl font-semibold",children:o.name})}),e.jsx(u,{}),e.jsx(m,{className:"text-xl font-semibold",children:e.jsx(F,{children:"Create"})})]})}),q=/^[a-zA-Z0-9-]+$/,H=A({blockName:Q().regex(q,{message:"Name must only contain lowercase letters, numbers, and dashes"})}),K={blockName:""},O=({blockSchema:o,blockType:a})=>{const n=B(),{values:r,setValues:l,errors:h,validateForm:j}=T(),{createBlockDocument:k,isPending:f}=S(),i=P({resolver:D(H),defaultValues:K}),g=async s=>{try{if(await j({schema:r}),h.length>0)return;k({block_schema_id:o.id,block_type_id:a.id,is_anonymous:!1,data:r,name:s.blockName},{onSuccess:c=>{x.success("Block created successfully"),n({to:"/blocks/block/$id",params:{id:c.id}})},onError:c=>{const t="Unknown error while creating block.";x.error(t),console.error(t,c)}})}catch(c){const t="Unknown error while validating block data.";x.error(t),console.error(t,c)}};return e.jsxs("div",{className:"flex flex-col gap-6",children:[e.jsx($,{blockType:a}),e.jsxs(_,{className:" p-6 grid grid-cols-[minmax(0,_1fr)_250px] gap-4 ",children:[e.jsx(V,{...i,children:e.jsxs("form",{className:"flex flex-col gap-4",onSubmit:s=>{i.handleSubmit(g)(s)},children:[e.jsx(I,{control:i.control,name:"blockName",render:({field:s})=>e.jsxs(z,{children:[e.jsx(G,{children:"Name"}),e.jsx(M,{children:e.jsx(C,{...s,value:s.value})}),e.jsx(X,{})]})}),e.jsx(U,{values:r,onValuesChange:l,errors:h,kinds:["json"],schema:o.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(R,{blockType:a})]})]})},de=function(){const{slug:a}=L.useParams(),{data:n}=p(w(a)),{data:r}=p(E({block_schemas:{block_type_id:{any_:[n.id]},operator:"and_"},offset:0})),l=r[0];if(!l)throw new Error("Block schema not found");return e.jsx(O,{blockSchema:l,blockType:n})};export{de as component};
//# sourceMappingURL=catalog_._slug_.create-DgOqqnfz.js.map
