import{j as e,ak as r,c5 as y,cn as j,co as w,cp as C,T as k}from"./vendor-mui-core-DnR6WYuU.js";import{i as E,L}from"./vendor-react-CTtPmzVP.js";import{u as R,b7 as v,c}from"./index-BZxsCCR_.js";import{g as F,b as l,h as P}from"./vendor-hooks-qxhUUbW5.js";import{V as S,H as t,w as d}from"./vendor-ux-DTEmWsko.js";import{C as u}from"./vendor-utils-CxWN1dT3.js";import"./vendor-arcblock-CIBaEWEy.js";import"./lottie-web-4koyQiv_.js";function A(){const{api:f}=R(),m=E(),{t:n}=S(),s=new URLSearchParams(m.search).get("token"),i=F({error:"",finished:!1,loading:!1}),h=l(()=>{window.close(),window.location.replace("/")}),b=l(async()=>{try{i.loading=!0;const{data:o}=await f.post("/api/user/notification/unsubscribe",{token:s});o.success===!0?(i.finished=!0,t.success(n("notification.unsubscribeSucceed"))):(i.finished=!1,t.error(n("notification.unsubscribeFailed")))}catch(o){i.finished=!1,t.error(o.message||n("notification.unsubscribeFailed"))}finally{i.loading=!1}});P(()=>{if(!s)i.error=n("notification.unsubscribeTokenRequired");else{const o=v(s);if(!o)i.error=n("notification.unsubscribeTokenInvalid");else{const{exp:g}=o;g*1e3<=Date.now()&&(i.error=n("notification.unsubscribeTokenExpired"))}}});const a=window?.blocklet?.copyright,p=a?.owner||window?.blocklet?.appName,x=a?.year||new Date().getFullYear();return e.jsx(r,{sx:{display:"flex",flexDirection:"column",justifyContent:"center",alignItems:"center",minHeight:"100vh",backgroundColor:"background.default"},children:e.jsxs(r,{sx:{width:"450px",maxWidth:"90%"},children:[e.jsx(r,{sx:{width:"100%"},children:e.jsx("img",{style:{height:"40px"},src:u(c.WELLKNOWN_SERVICE_PATH_PREFIX,"/blocklet/logo-rect?imageFilter=convert&f=png"),alt:"blocklet logo"})}),e.jsxs(y,{variant:"outlined",sx:{my:1},children:[e.jsx(j,{title:i.finished?n("notification.unsubscribeSucceed"):n("notification.email.unsubscribe")}),e.jsxs(w,{sx:{minHeight:"10em"},children:[i.error?i.error:null,!i.error&&!i.finished?n("notification.email.unsubscribeDescription"):null,!i.error&&i.finished?e.jsxs(e.Fragment,{children:[n("notification.email.subscribeDescription")," ",e.jsx(L,{to:u(c.WELLKNOWN_SERVICE_PATH_PREFIX,"/user/settings"),color:"primary",children:n("notification.email.subscribe")})]}):null]}),e.jsxs(C,{sx:{justifyContent:"end!important"},children:[e.jsx(d,{size:"small",color:i.error?"error":"primary",variant:"outlined",onClick:h,children:n("common.close")}),i.error||i.finished?null:e.jsx(d,{size:"small",color:"primary",variant:"contained",onClick:b,loading:i.loading,children:n("notification.unsubscribe")})]})]}),e.jsxs(k,{variant:"body2",color:"gray",children:["Copyright © ",x," ",p]})]})})}export{A as default};
