import{j as e,al as r,bX as y,cj as j,ck as w,cl as k,T as C}from"./vendor-mui-core-CDEc-eG6.js";import{i as v,L as F}from"./vendor-react-DX7tU9aY.js";import{u as L,b0 as R,W as c}from"./index-DGZk149v.js";import{i as E,b as l,j as P}from"./vendor-hooks-BrgYeCrj.js";import{W as S,O as t,b5 as d}from"./vendor-ux-bFYdDLNG.js";import{y as u}from"./vendor-utils-_C9URqjS.js";import"./vendor-arcblock-DY2miJjh.js";function O(){const{api:f}=L(),m=v(),{t:s}=S(),o=new URLSearchParams(m.search).get("token"),i=E({error:"",finished:!1,loading:!1}),b=l(()=>{window.close(),window.location.replace("/")}),h=l(async()=>{try{i.loading=!0;const{data:n}=await f.post("/api/user/notification/unsubscribe",{token:o});n.success===!0?(i.finished=!0,t.success(s("notification.unsubscribeSucceed"))):(i.finished=!1,t.error(s("notification.unsubscribeFailed")))}catch(n){i.finished=!1,t.error(n.message||s("notification.unsubscribeFailed"))}finally{i.loading=!1}});P(()=>{if(!o)i.error=s("notification.unsubscribeTokenRequired");else{const n=R(o);if(!n)i.error=s("notification.unsubscribeTokenInvalid");else{const{exp:g}=n;g*1e3<=Date.now()&&(i.error=s("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,"/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?s("notification.unsubscribeSucceed"):s("notification.email.unsubscribe")}),e.jsxs(w,{sx:{minHeight:"10em"},children:[i.error?i.error:null,!i.error&&!i.finished?s("notification.email.unsubscribeDescription"):null,!i.error&&i.finished?e.jsxs(e.Fragment,{children:[s("notification.email.subscribeDescription")," ",e.jsx(F,{to:u(c,"/user/settings"),color:"primary",children:s("notification.email.subscribe")})]}):null]}),e.jsxs(k,{sx:{justifyContent:"end!important"},children:[e.jsx(d,{size:"small",color:i.error?"error":"primary",variant:"outlined",onClick:b,children:s("common.close")}),i.error||i.finished?null:e.jsx(d,{size:"small",color:"primary",variant:"contained",onClick:h,loading:i.loading,children:s("notification.unsubscribe")})]})]}),e.jsxs(C,{variant:"body2",color:"gray",children:["Copyright © ",x," ",p]})]})})}export{O as default};
