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