import{j as s,d as g,r as b,L as B,s as k}from"./vendor-tanstack-CvGXetsl.js";import{B as y,g as v,h as n,bC as l,bM as m,bO as S,e1 as _,C as N,q as p,y as c,e2 as C,dj as E}from"./index-D51s66kn.js";import{B as L}from"./block-type-details-C_kNWwCY.js";import{u as w,L as P}from"./schema-form-input-string-format-datetime-Clw2ur0E.js";import"./vendor-react-HBv6Kpyp.js";import"./vendor-radix-y_Ik_hIG.js";import"./vendor-recharts-heKD2IVO.js";import"./vendor-forms-BVeRYtt6.js";import"./vendor-date-GSGg4LXF.js";import"./block-type-logo-DE7MqOhA.js";import"./lazy-markdown-J-Zn3RN0.js";import"./zod-CwzzXHlJ.js";import"./use-debounce-callback-BLKy1Dnx.js";import"./timezone-select-CZ0VB4eH.js";import"./dropdown-menu-0GXqpEoR.js";import"./form-D2Aou2qB.js";const F=({blockDocument:e})=>s.jsx(y,{children:s.jsxs(v,{children:[s.jsx(n,{children:s.jsx(l,{to:"/blocks",className:"text-xl font-semibold",children:"Blocks"})}),s.jsx(m,{}),s.jsx(n,{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(n,{className:"text-xl font-semibold",children:s.jsx(S,{children:"Edit"})})]})}),R=({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:()=>{c.success("Block updated successfully"),t({to:"/blocks/block/$id",params:{id:e.id}})},onError:d=>{const r="Unknown error while updating block.";c.error(r),console.error(r,d)}})}catch(d){const r="Unknown error while validating block data.";c.error(r),console.error(r,d)}};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})]})]})},X=function(){const{id:t}=C.useParams(),{data:a}=k(E(t));return s.jsx(R,{blockDocument:a})};export{X as component};
//# sourceMappingURL=block_._id.edit-CMJD6iYH.js.map
