import{j as e,d as B,L as y,s as p}from"./vendor-tanstack-CvGXetsl.js";import{B as N,g as v,h as m,bC as d,bM as u,bO as F,dv as _,C,p as S,q as b,y as x,e0 as L,dt as w,du as E}from"./index-D51s66kn.js";import{a as D}from"./zod-CwzzXHlJ.js";import{c as P,o as A,s as R}from"./vendor-forms-BVeRYtt6.js";import{B as T}from"./block-type-details-C_kNWwCY.js";import{u as U,L as V}from"./schema-form-input-string-format-datetime-Clw2ur0E.js";import{F as I,b as M,c as Q,d as z,e as G,a as O}from"./form-D2Aou2qB.js";import"./vendor-react-HBv6Kpyp.js";import"./vendor-radix-y_Ik_hIG.js";import"./vendor-recharts-heKD2IVO.js";import"./vendor-date-GSGg4LXF.js";import"./block-type-logo-DE7MqOhA.js";import"./lazy-markdown-J-Zn3RN0.js";import"./use-debounce-callback-BLKy1Dnx.js";import"./timezone-select-CZ0VB4eH.js";import"./dropdown-menu-0GXqpEoR.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:R().regex(q,{message:"Name must only contain lowercase letters, numbers, and dashes"})}),K={blockName:""},X=({blockSchema:o,blockType:a})=>{const n=B(),{values:r,setValues:l,errors:h,validateForm:j}=U(),{createBlockDocument:k,isPending:f}=_(),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:t=>{x.success("Block created successfully"),n({to:"/blocks/block/$id",params:{id:t.id}})},onError:t=>{const c="Unknown error while creating block.";x.error(c),console.error(c,t)}})}catch(t){const c="Unknown error while validating block data.";x.error(c),console.error(c,t)}};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(I,{...i,children:e.jsxs("form",{className:"flex flex-col gap-4",onSubmit:s=>{i.handleSubmit(g)(s)},children:[e.jsx(M,{control:i.control,name:"blockName",render:({field:s})=>e.jsxs(Q,{children:[e.jsx(z,{children:"Name"}),e.jsx(G,{children:e.jsx(S,{...s,value:s.value})}),e.jsx(O,{})]})}),e.jsx(V,{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(T,{blockType:a})]})]})},ue=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(X,{blockSchema:l,blockType:n})};export{ue as component};
//# sourceMappingURL=catalog_._slug_.create-CfbzMLiw.js.map
