import{d as $,an as j,ap as z,i as I,a as S,V as U,u as G,X as K,c as o,r as V,Y as R,w as X,o as y,b as Y,z as g,g as u,f as k,x as d,y as x,A as H,t as J,aw as L,s as Q,G as Z,a6 as ee,a3 as te,S as ae,ax as re,_ as ne}from"./index-tflVuual.js";import{W as w}from"./WdsFieldWrapper-CH9Jr2FR.js";const se={class:"DeploySharedBlueprint"},ie={key:0,class:"DeploySharedBlueprint__versionInfo"},le={key:1,class:"DeploySharedBlueprint__versionInfo"},oe=$({__name:"BuilderSettingsDeploySharedBlueprint",props:j({blueprintId:{}},{modelValue:{type:Boolean},modelModifiers:{}}),emits:["update:modelValue"],setup(_){const r=_,p=z(_,"modelValue"),s=I(S.core),C=I(S.builderManager),{pushToast:c}=U(),{setContentValue:m,extractBlueprintComponents:N}=re(s,C),W=G(s),{writerApi:M}=K(),v=o(()=>s.getComponentById(r.blueprintId)),B=o(()=>{var e,t;return((t=(e=v.value)==null?void 0:e.content)==null?void 0:t.deployedVersion)||null}),P=o(()=>{var e,t;return((t=(e=v.value)==null?void 0:e.content)==null?void 0:t.key)||"Shared Blueprint"}),T=o(()=>{var e,t;return((t=(e=v.value)==null?void 0:e.content)==null?void 0:t.deployedDescription)||""}),a=V({name:"",description:""}),f=R({}),i=V(!1);function q(){const e={};return a.value.name.trim()||(e.name="Name is required"),a.value.description.trim()||(e.description="Description is required"),f.value=e,Object.keys(e).length===0}function A(e){r.blueprintId&&e.trim()&&m(r.blueprintId,"key",e.trim())}async function E(){var t,n;if(!q())return;const e=s.writerOrgId.value;if(!e){c({type:"error",message:"Organization ID is required. Please set up your environment variable."});return}i.value=!0;try{const l=N(r.blueprintId),O=((n=(t=v.value)==null?void 0:t.content)==null?void 0:n.publishedSnippetId)||null,b=await M.publishSharedBlueprint(e,{title:a.value.name.trim(),description:a.value.description.trim(),components:l,metadata:{},existingSnippetId:O});m(r.blueprintId,"publishedSnippetId",b.snippet_id),m(r.blueprintId,"deployedVersion",String(b.version)),m(r.blueprintId,"deployedDescription",a.value.description.trim()),c({type:"success",message:`Blueprint "${a.value.name.trim()}" published (v${b.version})`}),W.track("blueprints_shared_published"),h(),p.value=!1;try{await s.init()}catch{c({type:"error",message:"Blueprint published but failed to reload. Please refresh the page."})}}catch(l){c({type:"error",message:`Error publishing blueprint: ${l instanceof Error?l.message:String(l)}`})}finally{i.value=!1}}function D(){i.value||(h(),p.value=!1)}function h(){a.value={name:P.value,description:T.value},f.value={}}const F=o(()=>[{desc:"Cancel",fn:D},{desc:i.value?"Publishing...":"Publish",fn:E,disabled:i.value}]);return X(p,e=>{e&&h()}),(e,t)=>p.value?(y(),Y(te,{key:0,actions:F.value,title:"Publish Blueprint","display-close-button":"",onClose:D},{default:g(()=>[u("div",se,[B.value?(y(),k("div",ie,[d(x,{name:"package"}),u("span",null,[t[2]||(t[2]=H("Currently published: ")),u("strong",null,"v"+J(B.value),1)])])):(y(),k("div",le,[d(x,{name:"package"}),t[3]||(t[3]=u("span",null,"Not yet published",-1))])),d(w,{label:"Name",required:""},{default:g(()=>[d(L,{modelValue:a.value.name,"onUpdate:modelValue":[t[0]||(t[0]=n=>a.value.name=n),A],placeholder:"e.g., Data Fetch Pipeline",error:f.value.name},null,8,["modelValue","error"])]),_:1}),d(w,{label:"Description",required:""},{default:g(()=>[Q(u("textarea",{"onUpdate:modelValue":t[1]||(t[1]=n=>a.value.description=n),placeholder:"Describe what this shared blueprint does",class:Z(["DeploySharedBlueprint__textarea",{"DeploySharedBlueprint__textarea--error":f.value.description}])},null,2),[[ee,a.value.description]])]),_:1})])]),_:1},8,["actions"])):ae("",!0)}}),ce=ne(oe,[["__scopeId","data-v-e0cee897"]]);export{ce as default};
