import{j as e,al as r,bX as y,cm as j,cn as w,co as C,T as k}from"./vendor-mui-core-D7t4vMS5.js";import{i as E,L as F}from"./vendor-react-DX7tU9aY.js";import{u as L,aF as R,c}from"./index-Ca33rdd_.js";import{i as v,b as l,j as P}from"./vendor-hooks-DAZ1H6Va.js";import{W as S,Q as t,b4 as d}from"./vendor-ux-Dl3wVbv_.js";import{z as u}from"./vendor-utils-BzQg432x.js";import"./vendor-arcblock-ivFYo5vP.js";function U(){const{api:f}=L(),m=E(),{t:n}=S(),o=new URLSearchParams(m.search).get("token"),i=v({error:"",finished:!1,loading:!1}),b=l(()=>{window.close(),window.location.replace("/")}),h=l(async()=>{try{i.loading=!0;const{data:s}=await f.post("/api/user/notification/unsubscribe",{token:o});s.success===!0?(i.finished=!0,t.success(n("notification.unsubscribeSucceed"))):(i.finished=!1,t.error(n("notification.unsubscribeFailed")))}catch(s){i.finished=!1,t.error(s.message||n("notification.unsubscribeFailed"))}finally{i.loading=!1}});P(()=>{if(!o)i.error=n("notification.unsubscribeTokenRequired");else{const s=R(o);if(!s)i.error=n("notification.unsubscribeTokenInvalid");else{const{exp:g}=s;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(F,{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:b,children:n("common.close")}),i.error||i.finished?null:e.jsx(d,{size:"small",color:"primary",variant:"contained",onClick:h,loading:i.loading,children:n("notification.unsubscribe")})]})]}),e.jsxs(k,{variant:"body2",color:"gray",children:["Copyright © ",x," ",p]})]})})}export{U as default};
