import{j as s,d as g,r as b,L as B,s as k}from"./vendor-tanstack-DE4ALVGD.js";import{B as y,g as v,h as c,bv as l,bE as m,bG as _,dQ as E,C as N,q as p,y as n,dR as S,d8 as L}from"./index-CNL5pSma.js";import{B as w}from"./block-type-details-heMLWolY.js";import{u as C,L as P}from"./schema-form-input-string-format-datetime-B98i_B5d.js";import"./vendor-react-HBv6Kpyp.js";import"./vendor-radix-K8EF6rBE.js";import"./vendor-recharts-B3wzJa9e.js";import"./vendor-forms-BvpM0AtX.js";import"./vendor-date-Bck8LDfw.js";import"./block-type-logo-Ab-MB0rX.js";import"./lazy-markdown-Ds39cUgX.js";import"./zod-2_bJZbih.js";import"./use-debounce-callback-_1tAtOwa.js";import"./timezone-select-zsZ2PBlt.js";import"./dropdown-menu-D34zumpn.js";import"./form-_6uPI_KA.js";const R=({blockDocument:e})=>s.jsx(y,{children:s.jsxs(v,{children:[s.jsx(c,{children:s.jsx(l,{to:"/blocks",className:"text-xl font-semibold",children:"Blocks"})}),s.jsx(m,{}),s.jsx(c,{children:s.jsx(l,{to:"/blocks/block/$id",params:{id:e.id},className:"text-xl font-semibold",children:e.name??e.block_type_name??e.id})}),s.jsx(m,{}),s.jsx(c,{className:"text-xl font-semibold",children:s.jsx(_,{children:"Edit"})})]})}),F=({blockDocument:e})=>{const r=g(),{values:t,setValues:o,errors:x,validateForm:u}=C(),{updateBlockDocument:h,isPending:j}=E();b.useEffect(()=>{e.data&&o(e.data)},[e.data,o]);const f=async i=>{i.preventDefault();try{await u({schema:t}),h({id:e.id,data:t,merge_existing_data:!1},{onSuccess:()=>{n.success("Block updated successfully"),r({to:"/blocks/block/$id",params:{id:e.id}})},onError:d=>{const a="Unknown error while updating block.";n.error(a),console.error(a,d)}})}catch(d){const a="Unknown error while validating block data.";n.error(a),console.error(a,d)}};return s.jsxs("div",{className:"flex flex-col gap-6",children:[s.jsx(R,{blockDocument:e}),s.jsxs(N,{className:" p-6 grid grid-cols-[minmax(0,_1fr)_250px] gap-4 ",children:[s.jsxs("form",{className:"flex flex-col gap-4",onSubmit:i=>{f(i)},children:[s.jsx(P,{values:t,onValuesChange:o,errors:x,kinds:["json"],schema:e?.block_schema?.fields??{}}),s.jsxs("div",{className:"flex gap-3 justify-end",children:[s.jsx(p,{variant:"secondary",children:s.jsx(B,{to:"/blocks/block/$id",params:{id:e.id},children:"Cancel"})}),s.jsx(p,{loading:j,type:"submit",children:"Save"})]})]}),e.block_type&&s.jsx(w,{blockType:e.block_type})]})]})};function X(){const{id:e}=S.useParams(),{data:r}=k(L(e));return s.jsx(F,{blockDocument:r})}export{X as component};
//# sourceMappingURL=block_._id.edit-RtJ1VzT9.js.map
