import{d as L,r as v,b as u,eu as P,u as a,c,w as o,f as s,aJ as r,c4 as p,cH as A,ct as N,cz as D,ew as C,bg as T,eD as E,eE as S,e as U,x as B}from"./outputWidgets.f120b477.js";import{W as K}from"./workspaces.901e1f01.js";import{l as f}from"./DocsButton.vue_vue_type_script_setup_true_lang.a4b61028.js";import{p as M}from"./popupNotifcation.5f5cb1af.js";import{a as O}from"./asyncComputed.5ccd4614.js";import{A as x}from"./index.3ab4f365.js";import{A as j,M as F}from"./Title.3dc4e32d.js";import"./index.02055c13.js";import{F as V}from"./Form.ec892c10.js";(function(){try{var t=typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{},i=new Error().stack;i&&(t._sentryDebugIds=t._sentryDebugIds||{},t._sentryDebugIds[i]="2693c452-c38c-4a26-9322-a4ed09ff2b59",t._sentryDebugIdIdentifier="sentry-dbid-2693c452-c38c-4a26-9322-a4ed09ff2b59")}catch{}})();const G=t=>(E("data-v-5c1cce26"),t=t(),S(),t),W=G(()=>U("a",{href:"https://cloud.abstra.io",target:"_blank"},"cloud.abstra.io",-1)),$=L({__name:"LoginBlock",setup(t){const i=v(!1),e=v({state:"CLOSED"}),{loading:g,result:d,refetch:_}=O(()=>f.get());function m(){e.value={state:"INPUT",apiKey:"",loading:!1}}function I(){e.value={state:"CLOSED"}}async function b(){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(){!d.value||(await f.delete(),_())}async function w(){if(!!d.value){i.value=!0;try{await K.deploy(),window.open(`https://cloud.abstra.io/projects/${d.value.logged&&d.value.project_id}/builds`,"_blank")}catch(l){M("Deploy failed",String(l))}i.value=!1}}return(l,n)=>{var y;return u(),P(T,null,[(y=a(d))!=null&&y.logged?(u(),c(a(N),{key:0},{default:o(()=>[s(a(p),{href:`https://cloud.abstra.io/projects/${a(d).project_id}`,target:"_blank"},{default:o(()=>[r("Go to console ")]),_:1},8,["href"]),i.value?(u(),c(a(p),{key:1,loading:""},{default:o(()=>[r("Deploying")]),_:1})):(u(),c(a(A),{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:I,onOk:b},{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=B($,[["__scopeId","data-v-5c1cce26"]]);export{ee as L};
//# sourceMappingURL=LoginBlock.ed4c5734.js.map
