import{i as e}from"./chunk-B3pr0VN8.js";import{n as t,t as n}from"./jsx-runtime-wTfS3W87.js";import{d as r}from"./chunk-6CSD65Y2-Dj7xjS5D.js";import{s as i}from"./authSession-CrP9lMPq.js";import{r as a}from"./norm-CeclA1Tu.js";var o=e(t(),1),s=async()=>({mode:`login`,session:null,pendingLocalToken:null,error:`feature_disabled`,isNewUser:!1,signupGiftPoints:0,token:``,expiresAt:``,user:null,extRelay:``,mergedFrom:``}),c=n(),l=`/tools/resume-heatmap`,u=e=>{try{let t=a(new URLSearchParams(window.location.search).get(e));if(t)return t}catch{}try{let t=window.location.hash||``,n=t.indexOf(`?`);if(n>=0)return a(new URLSearchParams(t.slice(n+1)).get(e))}catch{}return``};function d(){let e=r(),[t,n]=(0,o.useState)(`processing`),[d,f]=(0,o.useState)(``),[p,m]=(0,o.useState)(``);return(0,o.useEffect)(()=>{let t=!0;return(async()=>{try{if(a(u(`provider`)).toLowerCase()===`wechat`)throw Error(`该登录方式已下线，请返回登录页使用手机号验证码登录。`);let r=await s();if(!t)return;if(r.mode===`login`){let a=r.isNewUser?Math.max(0,Number(r.signupGiftPoints||0)||0):0;if(!r.token||!r.expiresAt||!r.user?.id)throw Error(`登录失败：会话数据不完整`);if(r.extRelay){n(`success`),f(a>0?`注册成功，已赠送 ${a} 积分体验额度，正在同步到插件…`:`登录成功，正在同步到插件…`);try{let e=String(sessionStorage.getItem(`jdt_ext_bridge_nonce_v1`)||``).trim();window.postMessage({type:`JDT_AUTH_SESSION`,extId:r.extRelay,nonce:e,session:{token:r.token,accessToken:r.token,expiresAt:r.expiresAt,accessExpiresAt:r.expiresAt,refreshToken:String(r.refreshToken||``).trim()||void 0,refreshExpiresAt:String(r.refreshExpiresAt||``).trim()||void 0,user:{id:r.user?.id,email:r.user?.email,phone:r.user?.phone,identityRole:r.user?.identityRole}}},window.location.origin)}catch{}m(`chrome-extension://${r.extRelay}/index.html#/me`);return}await i({token:r.token,expiresAt:r.expiresAt,user:{id:r.user.id,email:r.user.email,phone:r.user.phone}}),n(`success`),f(a>0?`注册成功，已赠送 ${a} 积分体验额度，正在跳转…`:`登录成功，正在跳转…`),setTimeout(()=>{t&&e(l)},a>0?1200:800)}else{if(r.extRelay){n(`success`),f(r.mergedFrom?`绑定成功，已合并账号 ${r.mergedFrom}，正在返回插件…`:`绑定成功，正在返回插件…`),m(`chrome-extension://${r.extRelay}/index.html#/me`);try{window.postMessage({type:`JDT_AUTH_ACK`,ok:!0},window.location.origin)}catch{}return}n(`success`),f(r.mergedFrom?`绑定成功，已合并账号 ${r.mergedFrom}`:`绑定成功`),setTimeout(()=>{t&&e(`/tools`)},1200)}}catch(e){if(!t)return;n(`error`),f(String(e?.message||`回调处理失败`))}})(),()=>{t=!1}},[e]),(0,o.useEffect)(()=>{let e=e=>{try{if(e.source!==window||String(e.origin||``)!==window.location.origin||String(e.data?.type||``).trim()!==`JDT_AUTH_ACK`||!e.data?.ok)return;f(`已同步到插件，你可以关闭此页面。`),window.setTimeout(()=>{try{window.close()}catch{}},800)}catch{}};return window.addEventListener(`message`,e),()=>window.removeEventListener(`message`,e)},[]),(0,c.jsx)(`div`,{className:`w-full min-h-screen bg-gray-50 flex items-center justify-center`,children:(0,c.jsx)(`div`,{className:`w-full max-w-sm text-center px-6`,children:t===`processing`?(0,c.jsxs)(c.Fragment,{children:[(0,c.jsx)(`div`,{className:`mx-auto w-8 h-8 border-2 border-gray-300 border-t-gray-900 rounded-full animate-spin`}),(0,c.jsx)(`div`,{className:`mt-4 text-sm text-gray-600`,children:`正在处理登录…`})]}):t===`success`?(0,c.jsxs)(c.Fragment,{children:[(0,c.jsx)(`div`,{className:`mx-auto w-10 h-10 rounded-full bg-gray-100 border border-gray-300 flex items-center justify-center text-gray-900 text-lg font-bold`,children:`✓`}),(0,c.jsx)(`div`,{className:`mt-3 text-sm font-medium text-gray-900`,children:d}),p?(0,c.jsx)(`a`,{href:p,className:`mt-4 inline-flex h-9 px-4 rounded-lg bg-gray-900 text-white text-xs font-medium hover:bg-black transition-colors items-center justify-center`,children:`如果未同步，点此返回插件`}):null]}):(0,c.jsxs)(c.Fragment,{children:[(0,c.jsx)(`div`,{className:`mx-auto w-10 h-10 rounded-full bg-rose-50 border border-rose-200 flex items-center justify-center text-rose-600 text-lg font-bold`,children:`!`}),(0,c.jsx)(`div`,{className:`mt-3 text-sm font-medium text-gray-900`,children:`处理失败`}),(0,c.jsx)(`div`,{className:`mt-2 text-xs text-gray-500 leading-relaxed`,children:d}),(0,c.jsx)(`button`,{type:`button`,onClick:()=>e(`/auth`),className:`mt-5 h-9 px-5 rounded-lg bg-gray-900 text-white text-xs font-medium hover:bg-black transition-colors`,children:`返回登录页`})]})})})}export{d as default};