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