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