import{u as w,R as N,r as V,I as T,aK as $,d as q,a as D,e as p,g as L,j as r,o as d,h as S,w as g,i as O,aL as F,aM as J,aN as Q,q as W,aO as j,s as v,ab as A,aP as G,G as H}from"./index.ace9693c.js";import{u as I}from"./useRouteParam.1483cbc1.js";import{u as R}from"./useSubscriptionWithDependencies.3c89067d.js";import{u as K}from"./usePageTitle.12638eb5.js";function M(o,e=""){var m;const u=w(),n=N(),k=C(e,(m=B(n,o))!=null?m:e),c=V(k),b=T(c,(i,s)=>{x(i,s)||u.push({query:{...n.query,[o]:c.value}})}),t=T(n,(i,s)=>{var y,a;const h=(y=B(i,o))!=null?y:e,_=(a=B(s,o))!=null?a:e,f=C(_,h);f!==c.value&&(c.value=f)},{deep:!0});return $(()=>{b(),t()}),c}function B({query:o},e){return o[e]}function C(o,e){return Array.isArray(o)&&!Array.isArray(e)?[e]:typeof o=="string"&&Array.isArray(e)?e[0]:e}function x(o,e){return JSON.stringify(o)===JSON.stringify(e)}const Y=q({__name:"BlocksCatalogCreate",setup(o){const e=D(),u=w(),n=M("redirect"),k=I("blockTypeSlug"),c=p(()=>k.value?[k.value]:null),b=R(e.blockTypes.getBlockTypeBySlug,c),t=p(()=>b.response),m=p(()=>t.value?[t.value.id]:null),i=R(e.blockSchemas.getBlockSchemaForBlockType,m),s=p(()=>i.response);function h(a){e.blockDocuments.createBlockDocument(a).then(({id:l})=>f(l)).catch(l=>{A("Failed to create block","error"),console.error(l)})}function _(){u.back()}function f(a){if(A("Block created successfully","success"),n.value){const l=u.resolve(G(n.value));u.push(l);return}u.push(H.block(a))}const y=p(()=>t.value?`Create ${t.value.name} Block`:"Create Block");return K(y),(a,l)=>{const P=L("p-layout-default");return r(t)?(d(),S(P,{key:0,class:"blocks-catalog-create"},{header:g(()=>[O(r(F),{"block-type":r(t)},null,8,["block-type"])]),default:g(()=>[r(t)?(d(),S(r(J),{key:0,"block-type":r(t)},{default:g(()=>[r(s)?(d(),S(r(Q),W({key:0,key:r(s).id,"block-schema":r(s)},j({submit:h,cancel:_})),null,16,["block-schema"])):v("",!0)]),_:1},8,["block-type"])):v("",!0)]),_:1})):v("",!0)}}});export{Y as default};
