import{ab as R,ac as j,a as T,a7 as S,ad as D,d as I,u as P,c as b,r as V,e as t,o as k,b as f,w as v,i as $,ae as N,af as O,ag as U,ah as W,ai as F,f as y,aa as H,aj as J,a6 as q,W as _,p as z}from"./index.a93ec448.js";import{u as E}from"./useRouteParam.ba3137c3.js";const G=()=>{};function h(){const o=w(T(G));return o.executed=S(!1),o}function w(o){return D(o)}function g(...[o,n,u={}]){const e=R(h());return j(n,(r,d)=>{var a,l;if(r===null&&d===void 0)return;if(e.isSubscribed()&&e.unsubscribe(),r===null){Object.assign(e,h());return}const c=w(T(o,n,u));(l=(a=c.response).value)!=null||(a.value=e.response),c.executed.value=c.executed.value||e.executed,Object.assign(e,c)},{immediate:!0}),e}const M=I({__name:"BlocksCatalogCreate",setup(o){const n=P(),u=S({}),e=S(""),r=E("blockTypeSlug"),d=b(()=>r.value?[r.value]:null),c=g(H.getBlockTypeBySlug,d),a=b(()=>c.response),l=b(()=>a.value?[{blockSchemas:{blockTypeId:{any_:[a.value.id]}}}]:null),x=g(J.getBlockSchemas,l),i=b(()=>{var s;return(s=x.response)==null?void 0:s[0]});function B(){!i.value||!a.value||q.createBlockDocument({name:e.value,data:u.value,blockSchemaId:i.value.id,blockTypeId:a.value.id}).then(({id:s})=>{_("Block created successfully","success"),n.push(z.block(s))}).catch(s=>{_("Failed to create block","error"),console.error(s)})}function A(){n.back()}return(s,p)=>{const C=V("p-layout-default");return t(a)?(k(),f(C,{key:0,class:"blocks-catalog-create"},{header:v(()=>[$(t(N),{"block-type":t(a)},null,8,["block-type"])]),default:v(()=>[t(a)?(k(),f(t(O),{key:0,"block-type":t(a)},{default:v(()=>[t(i)?(k(),f(t(U),W({key:0,data:u.value,"onUpdate:data":p[0]||(p[0]=m=>u.value=m),name:e.value,"onUpdate:name":p[1]||(p[1]=m=>e.value=m),"block-schema":t(i)},F({submit:B,cancel:A})),null,16,["data","name","block-schema"])):y("",!0)]),_:1},8,["block-type"])):y("",!0)]),_:1})):y("",!0)}}});export{M as default};
