import{j as s,G as b,r as g,L as B,s as k}from"./vendor-tanstack-BVzzyDEt.js";import{B as y,a as v,b as c,bq as l,bz as m,bB as _,dV as N,G as S,q as p,w as n,dW as E,c_ as w}from"./index-BJkJ93Lr.js";import{B as L}from"./block-type-details-CUkO-JbV.js";import{u as P,L as C}from"./lazy-schema-form-Clp5QfAW.js";import"./primitives-BxgEGUr4.js";import"./toggle-group-B18EYoB-.js";import"./vendor-react-Bce9NwRC.js";import"./vendor-radix-CTAic6HB.js";import"./vendor-recharts-Mwm2qLZp.js";import"./vendor-forms-BN3tpxM2.js";import"./vendor-date-2jFo9aCm.js";import"./block-type-logo-ESEG5U5y.js";import"./lazy-markdown-CwRqR_1U.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(_,{children:"Edit"})})]})}),G=({blockDocument:e})=>{const r=b(),{values:t,setValues:o,errors:x,validateForm:u}=P(),{updateBlockDocument:h,isPending:j}=N();g.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(F,{blockDocument:e}),s.jsxs(S,{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(C,{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(L,{blockType:e.block_type})]})]})};function K(){const{id:e}=E.useParams(),{data:r}=k(w(e));return s.jsx(G,{blockDocument:r})}export{K as component};
//# sourceMappingURL=block_._id.edit-zcLxsR8o.js.map
