import{d as N,an as O,ap as U,i as S,a as x,V as z,u as E,X as F,c,r as f,Y as j,w as R,o as k,b as $,z as h,g as r,x as y,aw as H,s as w,G as K,a6 as X,aU as Y,f as J,t as L,S as C,a3 as Q,ax as Z,_ as ee}from"./index-dyx4v2bZ.js";import{W as I}from"./WdsFieldWrapper-DRQKJkmD.js";const ae={class:"DeploySharedBlueprint"},le={class:"DeploySharedBlueprint__globalOption"},te={class:"DeploySharedBlueprint__checkbox"},re={key:0,class:"DeploySharedBlueprint__success"},se=["href"],oe=N({__name:"BuilderSettingsDeploySharedBlueprint",props:O({blueprintId:{}},{modelValue:{type:Boolean},modelModifiers:{}}),emits:["update:modelValue"],setup(g){const o=g,p=U(g,"modelValue"),n=S(x.core),V=S(x.builderManager),{pushToast:i}=z(),{setContentValue:m,extractBlueprintComponents:A}=Z(n,V),_=E(n),{writerApi:B}=F(),D=c(()=>n.getComponentById(o.blueprintId)),G=c(()=>{var a,e;return((e=(a=D.value)==null?void 0:a.content)==null?void 0:e.key)||"Shared Blueprint"}),P=c(()=>{var a,e;return((e=(a=D.value)==null?void 0:a.content)==null?void 0:e.deployedDescription)||""}),l=f({name:"",description:"",proposeAsGlobal:!1}),d=j({}),u=f(!1),s=f(null);function q(){const a={};return l.value.name.trim()||(a.name="Name is required"),l.value.description.trim()||(a.description="Description is required"),d.value=a,Object.keys(a).length===0}function M(a){o.blueprintId&&a.trim()&&m(o.blueprintId,"key",a.trim())}async function T(){if(!q())return;const a=n.writerOrgId.value;if(!a){i({type:"error",message:"Organization ID is required. Please set up your environment variable."});return}u.value=!0,s.value=null;try{const e=A(o.blueprintId);if(l.value.proposeAsGlobal){const t=await B.proposeSharedBlueprintGlobal({title:l.value.name.trim(),description:l.value.description.trim(),components:e,metadata:{}});s.value=t.pr_url,i({type:"success",message:"Global blueprint proposed! A PR has been created for review."}),_.track("blueprints_global_proposed")}else{const t=await B.publishSharedBlueprint(a,{title:l.value.name.trim(),description:l.value.description.trim(),components:e,metadata:{}});m(o.blueprintId,"publishedSnippetId",t.snippet_id),m(o.blueprintId,"deployedDescription",l.value.description.trim()),i({type:"success",message:`Blueprint "${l.value.name.trim()}" published successfully`}),_.track("blueprints_shared_published"),v(),p.value=!1;try{await n.init()}catch{i({type:"error",message:"Blueprint published but failed to reload. Please refresh the page."})}}}catch(e){i({type:"error",message:`Error publishing blueprint: ${e instanceof Error?e.message:String(e)}`})}finally{u.value=!1}}function b(){u.value||(v(),p.value=!1)}function v(){l.value={name:G.value,description:P.value,proposeAsGlobal:!1},d.value={},s.value=null}const W=c(()=>{const a=l.value.proposeAsGlobal?"Propose":"Publish",e=l.value.proposeAsGlobal?"Proposing...":"Publishing...";return s.value?[{desc:"Close",fn:b}]:[{desc:"Cancel",fn:b},{desc:u.value?e:a,fn:T,disabled:u.value}]});return R(p,a=>{a&&v()}),(a,e)=>p.value?(k(),$(Q,{key:0,actions:W.value,title:"Publish Blueprint","display-close-button":"",onClose:b},{default:h(()=>[r("div",ae,[y(I,{label:"Name",required:""},{default:h(()=>[y(H,{modelValue:l.value.name,"onUpdate:modelValue":[e[0]||(e[0]=t=>l.value.name=t),M],placeholder:"e.g., Data Fetch Pipeline",error:d.value.name},null,8,["modelValue","error"])]),_:1}),y(I,{label:"Description",required:""},{default:h(()=>[w(r("textarea",{"onUpdate:modelValue":e[1]||(e[1]=t=>l.value.description=t),placeholder:"Describe what this shared blueprint does",class:K(["DeploySharedBlueprint__textarea",{"DeploySharedBlueprint__textarea--error":d.value.description}])},null,2),[[X,l.value.description]])]),_:1}),r("div",le,[r("label",te,[w(r("input",{"onUpdate:modelValue":e[2]||(e[2]=t=>l.value.proposeAsGlobal=t),type:"checkbox"},null,512),[[Y,l.value.proposeAsGlobal]]),e[3]||(e[3]=r("span",null,"Propose as global blueprint",-1))]),e[4]||(e[4]=r("p",{class:"DeploySharedBlueprint__hint"}," Global blueprints are available to all organizations and require approval via GitHub PR. ",-1))]),s.value?(k(),J("div",re,[e[5]||(e[5]=r("p",null,"Pull request created successfully!",-1)),r("a",{href:s.value,target:"_blank",rel:"noopener noreferrer"},L(s.value),9,se)])):C("",!0)])]),_:1},8,["actions"])):C("",!0)}}),pe=ee(oe,[["__scopeId","data-v-1ad841f6"]]);export{pe as default};
