import{p as w,e as _,u as C,v as k,x as S,j as y,c as b,g as P,a as i,f,t as g,h as B,i as p,o as h,_ as L}from"./DpdQcRr7.js";import{u as m}from"./D7eJvyae.js";import{c as M,a as x,b as A}from"./Ca4dpdo4.js";import"./BcpEzrWT.js";import"./DuJ0NDcC.js";import"./D1zzHZdQ.js";function I(){const c=w(),l=m(),a=()=>c.public.oauthRedirectUri;function u(t,s,r=!1){const o=c.public.mcpBaseUrl.replace(/\/$/,""),e=new URLSearchParams({client_id:c.public.mcpClientId,redirect_uri:a(),code_challenge:t,code_challenge_method:"S256",state:s});return r&&e.set("embed","1"),`${o}/auth/authorize?${e.toString()}`}function d(){var t,s;return typeof window<"u"&&!!((s=(t=window.electronAPI)==null?void 0:t.auth)!=null&&s.login)}async function n(){const{challenge:t,verifier:s,state:r}=await M();if(d()){const o=u(t,r,!0);try{const e=await window.electronAPI.auth.login(o,a());x();const v=A();return!e||e.error?{success:!1,error:(e==null?void 0:e.error)||"ログインがキャンセルされました"}:!e.state||e.state!==v?{success:!1,error:"state が一致しません"}:await l.loginWithCode(e.code,s,a())}catch(e){return console.error("Electron OAuth error:",e),{success:!1,error:(e==null?void 0:e.message)||"ログインに失敗しました"}}}return window.location.href=u(t,r),{success:!0}}return{startLogin:n,isElectron:d}}const U={class:"bb-login"},R={class:"bb-login-card"},V={key:0,class:"bb-login-error"},E=["disabled"],$=_({__name:"login",setup(c){C({title:"ログイン",meta:[{name:"description",content:"MCP アカウントで BlockBits にログインしてください"}]});const l=m(),a=k(),u=S(),{startLogin:d}=I(),n=p(""),t=p(!1),s=async()=>{n.value="",t.value=!0;const r=await d();if(!r.success){n.value=r.error||"ログインに失敗しました",t.value=!1;return}if(l.isLoggedIn){const o=u.query.redirect||"/user";await a.push(o)}};return y(()=>{l.isLoggedIn&&a.push("/user")}),(r,o)=>(h(),b("div",U,[o[2]||(o[2]=P('<div class="bb-login-head" data-v-6832fb1f><div class="bb-login-icon" data-v-6832fb1f><svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="currentColor" width="30" height="30" data-v-6832fb1f><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M11 16l-4-4m0 0l4-4m-4 4h14m-5 4v1a3 3 0 01-3 3H6a3 3 0 01-3-3V7a3 3 0 013-3h7a3 3 0 013 3v1" data-v-6832fb1f></path></svg></div><h1 class="bb-login-title" data-v-6832fb1f>おかえりなさい</h1><p class="bb-login-subtitle" data-v-6832fb1f>MCP アカウントでサインインしてください</p></div>',1)),i("div",R,[f(n)?(h(),b("div",V,[i("span",null,g(f(n)),1),i("button",{type:"button",class:"bb-login-error-close","aria-label":"閉じる",onClick:o[0]||(o[0]=e=>n.value="")},"×")])):B("",!0),i("button",{type:"button",class:"bb-login-btn",disabled:f(t),onClick:s},g(f(t)?"接続しています…":"MCP でログイン / 新規登録"),9,E),o[1]||(o[1]=i("p",{class:"bb-login-note"}," ログインすると MCP の認証画面に移動します。 アカウントをお持ちでない方も、同じボタンから新規登録できます。 ",-1))])]))}}),O=L($,[["__scopeId","data-v-6832fb1f"]]);export{O as default};
