import{d as z,i as w,a as P,V as T,u as F,X as W,r as h,az as N,c as O,o as n,f as g,g as i,t as f,b as k,z as $,x as I,y as S,A as V,W as A,S as D,ax as M,_ as x,ap as j,w as C,aw as q,a1 as U,D as K,E as Q,a3 as X}from"./index-tflVuual.js";import{u as G}from"./BuilderApp-Bc8bFIhZ.js";import"./WdsCheckbox-COE3JsDI.js";import"./marked.esm-273vDTCT.js";const H={class:"BuilderBlueprintLibraryItem"},J={class:"BuilderBlueprintLibraryItem__header"},R={class:"BuilderBlueprintLibraryItem__title"},Y={class:"BuilderBlueprintLibraryItem__version"},Z={class:"BuilderBlueprintLibraryItem__description"},ee={class:"BuilderBlueprintLibraryItem__actions"},re=z({__name:"BuilderBlueprintLibraryItem",props:{block:{}},emits:["installed","deleted"],setup(L,{emit:_}){const s=L,y=_,d=w(P.core),m=w(P.builderManager),{pushToast:r}=T(),v=F(d),{writerApi:u}=W(),{installSharedBlueprint:b}=M(d,m),c=h(!1),p=h(!1),{user:o}=N(),t=O(()=>o.value!==void 0&&s.block.createdBy===o.value.id);async function e(){const l=d.writerOrgId.value;if(!l){r({type:"error",message:"Organization ID is required. Please set up your environment variable."});return}c.value=!0;try{const a=await u.getSharedBlueprint(l,s.block.id),B=a.version.components,ce=b({id:a.id,title:a.title,version:a.version.version,description:a.version.description||void 0,components:B});r({type:"success",message:`Blueprint "${s.block.title}" installed successfully`}),y("installed")}catch(a){r({type:"error",message:`Failed to install blueprint: ${a instanceof Error?a.message:String(a)}`})}finally{c.value=!1}}async function E(){const l=d.writerOrgId.value;if(!l){r({type:"error",message:"Organization ID is required. Please set up your environment variable."});return}if(confirm(`Are you sure you want to delete "${s.block.title}"? This will permanently remove it from the shared blueprint library.`)){p.value=!0;try{await u.deleteSharedBlueprint(l,s.block.id),r({type:"success",message:`Blueprint "${s.block.title}" deleted successfully`}),v.track("blueprints_block_deleted",{blueprintId:s.block.id}),y("deleted")}catch(B){r({type:"error",message:`Failed to delete blueprint: ${B instanceof Error?B.message:String(B)}`})}finally{p.value=!1}}}return(l,a)=>(n(),g("div",H,[i("div",J,[i("h3",R,f(l.block.title),1),i("span",Y,"v"+f(l.block.version_number),1)]),i("p",Z,f(l.block.description),1),i("div",ee,[t.value?(n(),k(A,{key:0,variant:"neutral",size:"small",disabled:p.value,onClick:E},{default:$(()=>[I(S,{name:"trash-2"}),V(" "+f(p.value?"Deleting...":"Delete"),1)]),_:1},8,["disabled"])):D("",!0),I(A,{variant:"primary",size:"small",disabled:c.value,onClick:e},{default:$(()=>[I(S,{name:"download"}),V(" "+f(c.value?"Installing...":"Install"),1)]),_:1},8,["disabled"])])]))}}),te=x(re,[["__scopeId","data-v-0b2963ff"]]),se={class:"BuilderBlueprintLibraryPanel"},ae={class:"BuilderBlueprintLibraryPanel__header"},ie={class:"BuilderBlueprintLibraryPanel__search"},le={class:"BuilderBlueprintLibraryPanel__content"},ne={key:1,class:"BuilderBlueprintLibraryPanel__empty"},oe={key:0,class:"BuilderBlueprintLibraryPanel__empty__hint"},ue={key:2,class:"BuilderBlueprintLibraryPanel__grid"},de=z({__name:"BuilderBlueprintLibraryPanel",props:{modelValue:{type:Boolean},modelModifiers:{}},emits:["update:modelValue"],setup(L){const _=j(L,"modelValue"),s=w(P.core),{pushToast:y}=T(),{writerApi:d}=W(),m=O(()=>Array.isArray(s.featureFlags.value)&&s.featureFlags.value.includes("blueprint_library")),r=h(""),v=h([]),u=h(!1);async function b(){if(!m.value)return;const o=s.writerOrgId.value;if(!o){y({type:"error",message:"Organization ID is required. Please set up your environment variable."}),u.value=!1;return}u.value=!0;try{const t=await d.listSharedBlueprints(o,r.value||void 0);v.value=t.map(e=>({id:e.id,title:e.title,description:e.description,category:e.category||"Shared Blueprints",version_number:e.version_number,createdBy:e.createdBy}))}catch(t){y({type:"error",message:`Failed to load blueprints: ${t instanceof Error?t.message:String(t)}`})}finally{u.value=!1}}const c=G(b,300);C(r,c);function p(){_.value=!1}return C(_,o=>{o&&m.value&&b()}),(o,t)=>_.value&&m.value?(n(),k(X,{key:0,title:"Blueprint Library",size:"wide","display-close-button":"",onClose:p},{default:$(()=>[i("div",se,[i("div",ae,[i("div",ie,[I(q,{modelValue:r.value,"onUpdate:modelValue":t[0]||(t[0]=e=>r.value=e),placeholder:"Search blueprints...","left-icon":"search"},null,8,["modelValue"])])]),i("div",le,[u.value?(n(),k(U,{key:0,class:"BuilderBlueprintLibraryPanel__loading"})):v.value.length===0?(n(),g("div",ne,[t[1]||(t[1]=i("p",null,"No blueprints found",-1)),r.value?(n(),g("p",oe," Try adjusting your search ")):D("",!0)])):(n(),g("div",ue,[(n(!0),g(K,null,Q(v.value,e=>(n(),k(te,{key:e.id,block:e,onDeleted:b},null,8,["block"]))),128))]))])])]),_:1})):D("",!0)}}),ve=x(de,[["__scopeId","data-v-007c1279"]]);export{ve as default};
