import{j as e,d as B,L as y,s as h}from"./vendor-tanstack-BdLtprmr.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 p,y as u,dP as L,dh as E,di as w}from"./index-CPpeVt8m.js";import{a as D}from"./zod-B1GLD-Zc.js";import{c as P,o as A,s as R}from"./vendor-forms-BlFSCfFw.js";import{B as T}from"./block-type-details-tAkUWqs1.js";import{u as U,L as V}from"./schema-form-input-string-format-datetime-Dg3zVAp5.js";import"./toggle-group-EMgSOoYH.js";import{F as G,b as I,c as Q,d as z,e as M,a as $}from"./form-Cl5Hk9bq.js";import"./vendor-react-HBv6Kpyp.js";import"./vendor-radix-CJc458uP.js";import"./vendor-recharts-CY3PKigC.js";import"./vendor-date-Cl1Jav-N.js";import"./block-type-logo-scnMsyY5.js";import"./lazy-markdown-D_y73qoD.js";import"./use-debounce-callback-Dk7Ebi48.js";import"./timezone-select-NViFNNLz.js";import"./dropdown-menu-fRiq5bS-.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:o})=>{const l=B(),{values:a,setValues:b,errors:x,validateForm:j}=U(),{createBlockDocument:k,isPending:f}=_(),m=P({resolver:D(K),defaultValues:O}),g=async r=>{try{if(await j({schema:a}),x.length>0)return;k({block_schema_id:s.id,block_type_id:o.id,is_anonymous:!1,data:a,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:o}),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:a,onValuesChange:b,errors:x,kinds:["json"],schema:s.fields}),e.jsxs("div",{className:"flex gap-3 justify-end",children:[e.jsx(p,{variant:"secondary",children:e.jsx(y,{to:"/blocks/catalog",children:"Cancel"})}),e.jsx(p,{loading:f,type:"submit",children:"Save"})]})]})}),e.jsx(T,{blockType:o})]})]})};function xe(){const{slug:s}=L.useParams(),{data:o}=h(E(s)),{data:l}=h(w({block_schemas:{block_type_id:{any_:[o.id]},operator:"and_"},offset:0})),a=l[0];if(!a)throw new Error("Block schema not found");return e.jsx(X,{blockSchema:a,blockType:o})}export{xe as component};
//# sourceMappingURL=catalog_._slug_.create-rboQmoyW.js.map
