import{j as s,h as g,r as b,L as B,y as k}from"./vendor-tanstack-BpuysabX.js";import{B as y,g as v,h as c,bD as l,bQ as m,bS as S,e2 as _,C as N,q as p,y as d,e3 as E,cD as C}from"./index-CREafGO4.js";import{B as L}from"./block-type-details-CJxHA2oB.js";import{l as w,L as P}from"./schema-form-input-string-format-datetime-CtefOb8F.js";import"./vendor-radix-DIu41Ss_.js";import"./vendor-recharts-C2XeLr4O.js";import"./vendor-forms-Buh7U8Ay.js";import"./vendor-date-C1t37jsh.js";import"./block-type-logo-BNO1-Opd.js";import"./lazy-markdown-rmxkK4GI.js";import"./zod-CtcMvSO9.js";import"./use-debounce-callback-Bybo1_Zg.js";import"./timezone-select-DpL0avEm.js";import"./dropdown-menu-DZExFL3b.js";import"./form-DC8L1tSC.js";const F=({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(S,{children:"Edit"})})]})}),Q=({blockDocument:e})=>{const t=g(),{values:a,setValues:o,errors:x,validateForm:u}=w(),{updateBlockDocument:h,isPending:j}=_();b.useEffect(()=>{e.data&&o(e.data)},[e.data,o]);const f=async i=>{i.preventDefault();try{await u({schema:a}),h({id:e.id,data:a,merge_existing_data:!1},{onSuccess:()=>{d.success("Block updated successfully"),t({to:"/blocks/block/$id",params:{id:e.id}})},onError:n=>{const r="Unknown error while updating block.";d.error(r),console.error(r,n)}})}catch(n){const r="Unknown error while validating block data.";d.error(r),console.error(r,n)}};return s.jsxs("div",{className:"flex flex-col gap-6",children:[s.jsx(F,{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:a,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(L,{blockType:e.block_type})]})]})},W=function(){const{id:t}=E.useParams(),{data:a}=k(C(t));return s.jsx(Q,{blockDocument:a})};export{W as component};
//# sourceMappingURL=block_._id.edit-CyZMbjn4.js.map
