var e=`zfile-guest-login-redirect`,t=600*1e3,n=[`/login`,`/admin`,`/guest`,`/install`,`/401`,`/403`,`/404`,`/500`],r=e=>{let t=Array.isArray(e)?e[0]:e;if(typeof t!=`string`)return``;let n=t.trim().replace(/[\t\n\r]/g,``);return!n||!n.startsWith(`/`)||n.startsWith(`//`)||n.startsWith(`/\\`)||/^[a-zA-Z][a-zA-Z\d+.-]*:/.test(n)?``:n},i=e=>{let t=Array.isArray(e)?e[0]:e;if(typeof t!=`string`)return``;let n=t.replace(/[\t\n\r]/g,``);if(!n.startsWith(`/`)||n.startsWith(`//`)||n.startsWith(`/\\`))return``;try{return new URL(n,window.location.origin).origin===window.location.origin?n:``}catch{return``}},a=(e,t)=>{let n=r(t);if(!n)return!1;try{let t=e.resolve(n).matched;if(!t.length)return!1;let r=t[t.length-1].path;return!(/\(\.\*\)\*$/.test(r)&&r.startsWith(`/admin`))}catch{return!1}},o=(e,t)=>{let n=r(t);if(!n)return!1;try{let t=e.resolve(n);if(t.path!==`/admin`&&!t.path.startsWith(`/admin/`))return!1;let r=t.matched;if(!r.length)return!1;let i=r[r.length-1].path;return!/\(\.\*\)\*$/.test(i)}catch{return!1}},s=(e,t)=>{let n=r(t);return o(e,n)?n:`/admin/dashboard`},c=e=>{let t=r(e);return t?!n.some(e=>t===e||t.startsWith(`${e}/`)):!1},l=t=>{let n=r(t);if(!c(n))return u(),``;let i={target:n,createdAt:Date.now()};try{window.sessionStorage.setItem(e,JSON.stringify(i))}catch(e){console.warn(`[auth] remember guest login redirect failed`,e)}return n},u=()=>{try{window.sessionStorage.removeItem(e)}catch(e){console.warn(`[auth] clear guest login redirect failed`,e)}},d=()=>{try{let n=window.sessionStorage.getItem(e);if(!n)return``;let i=JSON.parse(n),a=r(i.target),o=typeof i.createdAt==`number`?i.createdAt:0;return!c(a)||o<=0||Date.now()-o>t?(u(),``):a}catch{return u(),``}},f=()=>{let e=d();return u(),e};export{r as a,i as c,a as i,f as n,l as o,c as r,s,u as t};