import{d as A,r as v,b as u,et as L,u as a,c,w as o,f as s,b2 as r,cd as p,cO as P,cA as N,cG as D,ew as C,bw as T,eD as E,eE as S,e as O,x as U}from"./outputWidgets.b9aa154a.js";import{W as B}from"./workspaces.157f78cb.js";import{l as f}from"./DocsButton.vue_vue_type_script_setup_true_lang.6e7114de.js";import{p as K}from"./popupNotifcation.77a0c0ca.js";import{a as M}from"./asyncComputed.9bda3979.js";import{A as x}from"./index.55488473.js";import{A as j,M as F}from"./Title.6cd833fd.js";import"./index.ab1855db.js";import{F as V}from"./Form.55f226f4.js";(function(){try{var t=typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{},d=new Error().stack;d&&(t._sentryDebugIds=t._sentryDebugIds||{},t._sentryDebugIds[d]="5c3deed3-7387-494b-9d86-c84199031b97",t._sentryDebugIdIdentifier="sentry-dbid-5c3deed3-7387-494b-9d86-c84199031b97")}catch{}})();const G=t=>(E("data-v-5c1cce26"),t=t(),S(),t),W=G(()=>O("a",{href:"https://cloud.abstra.io",target:"_blank"},"cloud.abstra.io",-1)),$=A({__name:"LoginBlock",setup(t){const d=v(!1),e=v({state:"CLOSED"}),{loading:g,result:i,refetch:_}=M(()=>f.get());function m(){e.value={state:"INPUT",apiKey:"",loading:!1}}function b(){e.value={state:"CLOSED"}}async function I(){if(e.value.state!=="INPUT")return;const l=e.value.apiKey;try{e.value={state:"INPUT",apiKey:l,loading:!0};const n=await f.create(l);n.logged?(e.value={state:"CLOSED"},_()):n.reason==="INVALID_API_TOKEN"?e.value={state:"INPUT",apiKey:l,errorMessage:"Invalid API Token",loading:!1}:n.reason==="NO_API_TOKEN"?e.value={state:"INPUT",apiKey:l,errorMessage:"No API Token provided",loading:!1}:e.value={state:"INPUT",apiKey:l,errorMessage:"Unknown error",loading:!1}}catch(n){e.value={state:"INPUT",apiKey:l,errorMessage:String(n),loading:!1}}}async function k(){!i.value||(await f.delete(),_())}async function w(){if(!!i.value){d.value=!0;try{await B.deploy(),window.open(`https://cloud.abstra.io/projects/${i.value.logged&&i.value.project_id}/builds`,"_blank")}catch(l){K("Deploy failed",String(l))}d.value=!1}}return(l,n)=>{var y;return u(),L(T,null,[(y=a(i))!=null&&y.logged?(u(),c(a(N),{key:0},{default:o(()=>[s(a(p),{href:`https://cloud.abstra.io/projects/${a(i).project_id}`,target:"_blank"},{default:o(()=>[r("Go to console ")]),_:1},8,["href"]),d.value?(u(),c(a(p),{key:1,loading:""},{default:o(()=>[r("Deploying")]),_:1})):(u(),c(a(P),{key:0,title:"Are you sure you want to deploy this project to Abstra Cloud?",onConfirm:w},{default:o(()=>[s(a(p),null,{default:o(()=>[r("Deploy")]),_:1})]),_:1})),s(a(p),{onClick:k},{default:o(()=>[r("Logout")]),_:1})]),_:1})):(u(),c(a(p),{key:1,loading:a(g),disabled:a(g),onClick:m},{default:o(()=>[r("Login to deploy")]),_:1},8,["loading","disabled"])),s(a(F),{open:e.value.state!=="CLOSED",title:"Login","confirm-loading":e.value.state!=="CLOSED"&&e.value.loading,onCancel:b,onOk:I},{default:o(()=>[e.value.state==="INPUT"?(u(),c(a(V),{key:0,layout:"vertical"},{default:o(()=>[s(a(x),null,{default:o(()=>[r(" Login to our console at "),W,r(" and get an API Key to deploy your Projects. ")]),_:1}),s(a(j),{label:"API Key",help:e.value.errorMessage,"validate-status":e.value.errorMessage&&"error"},{default:o(()=>[s(a(D),{value:e.value.apiKey,"onUpdate:value":n[0]||(n[0]=h=>e.value.apiKey=h),disabled:e.value.loading},null,8,["value","disabled"])]),_:1},8,["help","validate-status"])]),_:1})):C("",!0)]),_:1},8,["open","confirm-loading"])],64)}}});const ee=U($,[["__scopeId","data-v-5c1cce26"]]);export{ee as L};
//# sourceMappingURL=LoginBlock.e1f13e7e.js.map
