dns-worker 1.1.5 → 1.1.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. package/LICENSE +154 -155
  2. package/README.md +1 -3
  3. package/dist/serverfull.mjs +49 -49
  4. package/dist/serverfull.mjs.map +4 -4
  5. package/package.json +7 -3
  6. package/static/assets/AccountView-DIeqrGlp.js +4 -0
  7. package/static/assets/AnalyticsView-BzZ61m0y.js +2 -0
  8. package/static/assets/{DestinationMap-Bwv9zW4k.js → DestinationMap-DAk0zqdP.js} +1 -1
  9. package/static/assets/{FilteringView-hYm_mlJ0.js → FilteringView-CkcgGa7_.js} +1 -1
  10. package/static/assets/LogsView-Bb2JGWSY.js +5 -0
  11. package/static/assets/{RulesView-DLhxdWLq.js → RulesView-BKZXclmK.js} +1 -1
  12. package/static/assets/{SettingsView-VR3JolCU.js → SettingsView-BIUiIVIC.js} +1 -1
  13. package/static/assets/SetupView-MjSOUYm0.js +1 -0
  14. package/static/assets/{TrendChart-wcrIRt7R.js → TrendChart-CDyqUTCQ.js} +1 -1
  15. package/static/assets/date-D8IlsmbP.js +1 -0
  16. package/static/assets/de-DE-BXtoHcnB.js +12 -0
  17. package/static/assets/es-ES-HzsKZWQV.js +12 -0
  18. package/static/assets/fr-FR-cS1x6c9J.js +12 -0
  19. package/static/assets/index-BJJdTKLc.css +2 -0
  20. package/static/assets/index-C5rHE6WK.js +17 -0
  21. package/static/assets/ja-JP-Dxk2el-P.js +12 -0
  22. package/static/assets/ko-KR-Bj56Fs_D.js +12 -0
  23. package/static/assets/ru-RU-D1z3XQQZ.js +12 -0
  24. package/static/assets/{services-BYhiWUn8.js → services-B-OKDv75.js} +1 -1
  25. package/static/assets/useLogsE2ee-Crd_rHKZ.js +1 -0
  26. package/static/assets/vi-VN-YQQX1woE.js +12 -0
  27. package/static/assets/zh-CN-B0jDBZPP.js +12 -0
  28. package/static/assets/zh-TW-DOnIGWL3.js +12 -0
  29. package/static/index.html +2 -2
  30. package/static/sw.js +1 -1
  31. package/static/assets/AccountView-t2HnohwK.js +0 -4
  32. package/static/assets/AnalyticsView-DDNyezYl.js +0 -2
  33. package/static/assets/LogsView-BSRCO63V.js +0 -5
  34. package/static/assets/SetupView-BEaDE8T8.js +0 -1
  35. package/static/assets/date-DG8jTrEB.js +0 -1
  36. package/static/assets/de-DE-BiPVfS40.js +0 -12
  37. package/static/assets/es-ES-CM9mOh6j.js +0 -12
  38. package/static/assets/fr-FR-_-PAIgSj.js +0 -12
  39. package/static/assets/index-CrB_HdIL.js +0 -17
  40. package/static/assets/index-DZNm9qiP.css +0 -2
  41. package/static/assets/ja-JP-CYATQiqp.js +0 -12
  42. package/static/assets/ko-KR-DCPI1Twu.js +0 -12
  43. package/static/assets/ru-RU-D5bj5X0j.js +0 -12
  44. package/static/assets/vi-VN-D1YSdAMz.js +0 -12
  45. package/static/assets/zh-CN-Dhtte9ac.js +0 -12
  46. package/static/assets/zh-TW-CiUsmXXj.js +0 -12
  47. /package/static/assets/{SwipeableDrawer-DkPacJ1O.js → SwipeableDrawer-BrlOF_Xg.js} +0 -0
@@ -1,4 +0,0 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/date-DG8jTrEB.js","assets/index-CrB_HdIL.js","assets/vendor-icons-other-BTYC6Wvz.js","assets/vendor-icons-16-BgwRBCeU.js","assets/rolldown-runtime-C4Xdq4VV.js","assets/vendor-icons-20-X5NPN60g.js","assets/vendor-react-De1zEwOV.js","assets/vendor-i18next-CevVzhh3.js","assets/vendor-ui-core-ClwQiwMI.js","assets/vendor-utils-rmW6cqPl.js","assets/index-DZNm9qiP.css"])))=>i.map(i=>d[i]);
2
- import{i as e}from"./rolldown-runtime-C4Xdq4VV.js";import{$ as t,A as n,B as r,C as i,D as a,E as o,Et as s,J as c,N as l,Q as u,Qt as d,R as f,S as p,W as m,X as h,Y as g,b as _,ft as v,gt as y,ht as b,it as x,j as S,k as C,lt as w,rt as T,x as E,y as D,z as O}from"./vendor-react-De1zEwOV.js";import{S as k,b as A,x as j}from"./vendor-icons-other-BTYC6Wvz.js";import{i as ee}from"./vendor-i18next-CevVzhh3.js";import{B as M,C as N,D as P,F as te,H as F,L as I,M as ne,N as L,O as R,P as z,R as B,S as V,T as re,V as H,_ as U,d as ie,f as W,h as ae,j as G,p as K,r as q,t as oe,u as se,v as ce,x as J,z as Y}from"./vendor-ui-core-ClwQiwMI.js";import{_t as le}from"./vendor-utils-rmW6cqPl.js";import{$t as ue,At as de,Bt as fe,C as pe,Ct as me,Dt as he,E as ge,Et as _e,Ft as ve,It as ye,Kt as be,Lt as xe,Mt as Se,Nt as Ce,Ot as we,Pt as Te,Rt as Ee,S as De,St as Oe,T as ke,Vt as Ae,_t as je,bt as Me,d as Ne,f as Pe,gt as Fe,h as X,ht as Ie,i as Le,jt as Re,kt as ze,l as Be,m as Ve,mt as He,o as Ue,p as We,pt as Ge,r as Ke,s as qe,u as Je,vt as Ye,w as Xe,wt as Ze,x as Z,xt as Qe,yt as $e,zt as et}from"./index-CrB_HdIL.js";var Q=e(k(),1),$=e(A(),1);const tt=({recoveryKeys:e,copied:t,onCopy:r,onDone:i})=>{let{t:a}=d();return(0,$.jsxs)(`div`,{className:`p-4 bg-gray-50 dark:bg-gray-900/50 rounded-lg border border-gray-200 dark:border-gray-800`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2 mb-4`,children:[(0,$.jsx)(n,{size:20,className:`text-green-500`}),(0,$.jsx)(G,{style:{margin:0},children:a(`account.totp.recoveryKeysTitle`,`Save Your Recovery Keys`)})]}),(0,$.jsx)(V,{intent:H.WARNING,className:`mb-4`,children:a(`account.totp.recoveryKeysWarning`,`Store these keys safely. Each key can only be used once.`)}),(0,$.jsx)(`div`,{className:e.length===1?`space-y-2 mb-4`:`grid grid-cols-2 gap-2 mb-4`,children:e.map((e,t)=>(0,$.jsx)(`code`,{className:`block font-mono text-sm sm:text-base font-semibold bg-gray-100 dark:bg-gray-800 text-blue-600 dark:text-blue-400 px-4 py-3 rounded-xl text-center tracking-widest break-all select-all border border-gray-200 dark:border-gray-700`,children:e},t))}),(0,$.jsxs)(`div`,{className:`flex gap-2`,children:[(0,$.jsx)(L,{fill:!0,icon:(0,$.jsx)(w,{size:14}),text:t?a(`account.totp.copied`,`Copied!`):a(`account.totp.copyKeys`,`Copy All Keys`),intent:t?H.SUCCESS:H.NONE,onClick:r}),(0,$.jsx)(L,{fill:!0,intent:H.PRIMARY,text:a(`account.totp.done`,`Done, I've saved them`),onClick:i})]})]})},nt=({onRefresh:e,toasterRef:t})=>{let{t:n}=d(),[r,i]=(0,Q.useState)([]),[a,o]=(0,Q.useState)(!0),[s,c]=(0,Q.useState)(!0),[l,u]=(0,Q.useState)(null),[f,p]=(0,Q.useState)(!1),[m,h]=(0,Q.useState)(null),[g,_]=(0,Q.useState)(!1),[v,y]=(0,Q.useState)(``),[b,x]=(0,Q.useState)(!1),[S,C]=(0,Q.useState)(!1),[w,T]=(0,Q.useState)(``),[E,D]=(0,Q.useState)(null),[O,k]=(0,Q.useState)(``),[A,j]=(0,Q.useState)(!1),[ee,M]=(0,Q.useState)(!1),[N,P]=(0,Q.useState)(``),[te,F]=(0,Q.useState)(null),[I,ne]=(0,Q.useState)(!1),[L,R]=(0,Q.useState)(null),z=(0,Q.useCallback)(async()=>{o(!0);try{i(await me()||[])}catch{}finally{o(!1)}},[]);return(0,Q.useEffect)(()=>{c(et()),z()},[z]),{passkeys:r,loading:a,supported:s,recoveryKeys:l,setRecoveryKeys:u,copiedKeys:f,handleCopyRecoveryKeys:()=>{l&&navigator.clipboard.writeText(l.join(`
3
- `)).then(()=>{p(!0),setTimeout(()=>p(!1),2e3)})},isAddOpen:g,setIsAddOpen:_,passkeyName:v,setPasskeyName:y,nameFocused:b,setNameFocused:x,registering:S,addError:w,setAddError:T,handleOpenAdd:()=>{y(``),T(``),x(!1),_(!0)},handleRegister:async t=>{t.preventDefault();let r=v.trim();if(!Ve(r)){T(n(`account.passkey.formatTip`,`1-30 characters, letters, numbers, hyphens and underscores allowed`));return}C(!0),T(``);try{let t=await Ee({name:r,credential:await Ae(await Oe())}),n=t?.passkey?.id||t?.id;if(n&&Z.isUnlocked())try{await Z.wrapCurrentKeyForPasskey(n)}catch(e){console.warn(`[Passkeys] Failed to wrap existing E2EE key for new passkey:`,e)}_(!1),y(``),await z(),e?.(),t?.recovery_keys&&t.recovery_keys.length>0&&u(t.recovery_keys)}catch(e){console.error(`Passkey registration failed:`,e),T(e instanceof Error?e.message:n(`account.passkey.regFailed`,`Registration failed`))}finally{C(!1)}},editingPasskey:E,setEditingPasskey:D,editName:O,setEditName:k,renameFocused:A,setRenameFocused:j,renaming:ee,renameError:N,setRenameError:P,handleOpenRename:e=>{D(e),k(e.name),P(``),j(!1)},handleRenameSubmit:async e=>{e.preventDefault();let t=O.trim();if(!(!E||!t)){if(!Ve(t)){P(n(`account.passkey.formatTip`,`1-30 characters, letters, numbers, hyphens and underscores allowed`));return}M(!0),P(``);try{await _e(E.id,t),D(null),await z()}catch(e){P(e instanceof Error?e.message:n(`common.errorNetwork`))}finally{M(!1)}}},deletingId:te,deleteConfirmOpen:I,setDeleteConfirmOpen:ne,targetToDelete:L,handleOpenDelete:e=>{R(e),ne(!0)},handleDeleteSubmit:async()=>{if(L){F(L.id);try{await je(L.id),ne(!1),R(null),await z(),e?.()}catch(e){let t=e instanceof Error?e.message:n(`common.errorNetwork`);alert(t)}finally{F(null)}}},testingId:m,handleTestPasskey:async e=>{h(e?e.id:`all`);try{let r=await Se(e?.id);r.success&&(t?.current?.show({message:n(`account.passkey.testSuccess`,{name:r.passkey?.name||e?.name||``,defaultValue:`Passkey verified successfully: ${r.passkey?.name||e?.name||``}`}),intent:H.SUCCESS,icon:`tick-circle`}),await z())}catch(e){let r=e instanceof Error?e.message:String(e);r.includes(`cancelled`)||r.includes(`NotAllowedError`)||r.includes(`timed out`)||r.includes(`abort`)?t?.current?.show({message:n(`account.passkey.testCancelled`,`Passkey verification cancelled`),intent:H.WARNING,icon:`warning-sign`}):t?.current?.show({message:r||n(`account.passkey.testFailed`,`Passkey verification failed`),intent:H.DANGER,icon:`error`})}finally{h(null)}},fetchPasskeys:z}},rt=({passkeys:e,loading:a,deletingId:o,testingId:s,onTestPasskey:c,onOpenRename:l,onOpenDelete:u})=>{let{t:f}=d();return a?(0,$.jsx)(`div`,{className:`py-6 text-center`,children:(0,$.jsx)(z,{size:24})}):e.length===0?(0,$.jsxs)(`div`,{className:`py-6 text-center text-sm text-gray-500 dark:text-gray-400 border border-dashed border-gray-200 dark:border-gray-800 rounded-lg`,children:[(0,$.jsx)(t,{size:28,className:`mx-auto mb-2 opacity-40`}),(0,$.jsx)(`p`,{children:f(`account.passkey.empty`,`No passkeys added yet.`)})]}):(0,$.jsx)(`div`,{className:`divide-y divide-gray-100 dark:divide-gray-800 border border-gray-200 dark:border-gray-800 rounded-lg overflow-hidden`,children:e.map(e=>(0,$.jsxs)(`div`,{className:`p-3 sm:p-4 flex items-center justify-between gap-3 hover:bg-gray-50 dark:hover:bg-gray-900/40 transition-colors`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-3 min-w-0`,children:[(0,$.jsx)(`div`,{className:`p-2 bg-purple-50 dark:bg-purple-950/40 text-purple-600 dark:text-purple-400 rounded-lg shrink-0`,children:(0,$.jsx)(t,{size:18})}),(0,$.jsxs)(`div`,{className:`min-w-0`,children:[(0,$.jsx)(`div`,{className:`font-semibold text-sm truncate text-gray-900 dark:text-gray-100`,children:e.name}),(0,$.jsxs)(`div`,{className:`text-xs text-gray-500 dark:text-gray-400 flex flex-wrap gap-x-3 gap-y-1 mt-0.5`,children:[(0,$.jsxs)(`span`,{children:[f(`account.passkey.created`,`Added`),`:`,` `,X(new Date(e.created_at*1e3))]}),e.last_used_at?(0,$.jsxs)(`span`,{children:[f(`account.passkey.lastUsed`,`Last used`),`:`,` `,X(new Date(e.last_used_at*1e3))]}):(0,$.jsx)(`span`,{children:f(`account.passkey.neverUsed`,`Never used`)})]})]})]}),(0,$.jsxs)(`div`,{className:`flex items-center gap-1 shrink-0`,children:[(0,$.jsx)(L,{minimal:!0,small:!0,intent:H.PRIMARY,icon:(0,$.jsx)(n,{size:14}),title:f(`account.passkey.testThis`,`Test this passkey`),loading:s===e.id,onClick:()=>c?.(e)}),(0,$.jsx)(L,{minimal:!0,small:!0,icon:(0,$.jsx)(r,{size:14}),title:f(`common.rename`,`Rename`),onClick:()=>l(e)}),(0,$.jsx)(L,{minimal:!0,small:!0,intent:H.DANGER,icon:(0,$.jsx)(i,{size:14}),title:f(`common.delete`,`Delete`),loading:o===e.id,onClick:()=>u(e)})]})]},e.id))})},it=({isOpen:e,onClose:t,passkeyName:n,setPasskeyName:r,nameFocused:i,setNameFocused:a,registering:o,addError:s,setAddError:c,onSubmit:l})=>{let{t:u}=d();return(0,$.jsx)(R,{isOpen:e,onClose:()=>!o&&t(),title:u(`account.passkey.addTitle`,`Add New Passkey`),className:`max-w-md`,children:(0,$.jsxs)(`form`,{onSubmit:l,children:[(0,$.jsxs)(`div`,{className:I,children:[s&&(0,$.jsx)(V,{intent:H.DANGER,className:`mb-4`,children:s}),(0,$.jsx)(K,{label:u(`account.passkey.nameLabel`,`Passkey Name`),labelFor:`passkey-name-input`,helperText:u(`account.passkey.formatTip`,`1-30 characters, letters, numbers, hyphens and underscores allowed`),children:(0,$.jsx)(ce,{content:u(`account.passkey.formatTip`,`1-30 characters, letters, numbers, hyphens and underscores allowed`),isOpen:i,position:M.TOP,intent:H.PRIMARY,className:`w-full`,children:(0,$.jsx)(`div`,{className:`w-full block`,children:(0,$.jsx)(W,{id:`passkey-name-input`,autoFocus:!0,placeholder:u(`account.passkey.namePlaceholder`,`e.g. my_passkey`),value:n,onChange:e=>{r(e.target.value),s&&c(``)},onFocus:()=>a(!0),onBlur:()=>a(!1),disabled:o})})})}),(0,$.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-gray-400`,children:u(`account.passkey.promptNotice`,`After clicking continue, your browser will prompt you to authenticate via Key, face scan, PIN, or hardware key.`)})]}),(0,$.jsx)(`div`,{className:B,children:(0,$.jsxs)(`div`,{className:Y,children:[(0,$.jsx)(L,{text:u(`common.cancel`,`Cancel`),onClick:t,disabled:o}),(0,$.jsx)(L,{intent:H.PRIMARY,type:`submit`,text:u(`account.passkey.continue`,`Continue`),loading:o,disabled:!Ve(n.trim())||o})]})})]})})},at=({isOpen:e,onClose:t,editName:n,setEditName:r,renameFocused:i,setRenameFocused:a,renaming:o,renameError:s,setRenameError:c,onSubmit:l})=>{let{t:u}=d();return(0,$.jsx)(R,{isOpen:e,onClose:()=>!o&&t(),title:u(`account.passkey.renameTitle`,`Rename Passkey`),className:`max-w-md`,children:(0,$.jsxs)(`form`,{onSubmit:l,children:[(0,$.jsxs)(`div`,{className:I,children:[s&&(0,$.jsx)(V,{intent:H.DANGER,className:`mb-4`,children:s}),(0,$.jsx)(K,{label:u(`account.passkey.appNameLabel`,`Application (Domain)`),children:(0,$.jsx)(W,{readOnly:!0,disabled:!0,leftIcon:`globe`,value:window.location.hostname})}),(0,$.jsx)(K,{label:u(`account.passkey.nameLabel`,`Passkey Name`),helperText:u(`account.passkey.formatTip`,`1-30 characters, letters, numbers, hyphens and underscores allowed`),children:(0,$.jsx)(ce,{content:u(`account.passkey.formatTip`,`1-30 characters, letters, numbers, hyphens and underscores allowed`),isOpen:i,position:M.TOP,intent:H.PRIMARY,className:`w-full`,children:(0,$.jsx)(`div`,{className:`w-full block`,children:(0,$.jsx)(W,{autoFocus:!0,placeholder:u(`account.passkey.namePlaceholder`,`e.g. my_passkey`),value:n,onChange:e=>{r(e.target.value),s&&c(``)},onFocus:()=>a(!0),onBlur:()=>a(!1),disabled:o})})})})]}),(0,$.jsx)(`div`,{className:B,children:(0,$.jsxs)(`div`,{className:Y,children:[(0,$.jsx)(L,{text:u(`common.cancel`,`Cancel`),onClick:t,disabled:o}),(0,$.jsx)(L,{intent:H.PRIMARY,type:`submit`,text:u(`common.save`,`Save`),loading:o,disabled:!Ve(n.trim())||o})]})})]})})},ot=({isOpen:e,onClose:t,targetToDelete:n,deleting:r,onConfirm:i})=>{let{t:a}=d();return(0,$.jsxs)(R,{isOpen:e,onClose:()=>!r&&t(),title:a(`account.passkey.deleteTitle`,`Delete Passkey`),className:`max-w-md`,children:[(0,$.jsx)(`div`,{className:I,children:(0,$.jsx)(`p`,{children:a(`account.passkey.deleteConfirm`,`Are you sure you want to delete passkey "{{name}}"? You will no longer be able to use this passkey for MFA.`,{name:n?.name})})}),(0,$.jsx)(`div`,{className:B,children:(0,$.jsxs)(`div`,{className:Y,children:[(0,$.jsx)(L,{text:a(`common.cancel`,`Cancel`),onClick:t,disabled:r}),(0,$.jsx)(L,{intent:H.DANGER,text:a(`common.delete`,`Delete`),onClick:i,loading:r})]})})]})},st=({onRefresh:e})=>{let{t}=d(),r=(0,Q.useRef)(null),{passkeys:i,loading:a,supported:o,recoveryKeys:s,setRecoveryKeys:c,copiedKeys:l,handleCopyRecoveryKeys:f,isAddOpen:p,setIsAddOpen:m,passkeyName:h,setPasskeyName:g,nameFocused:_,setNameFocused:v,registering:y,addError:b,setAddError:x,handleOpenAdd:C,handleRegister:w,editingPasskey:T,setEditingPasskey:E,editName:D,setEditName:k,renameFocused:A,setRenameFocused:j,renaming:ee,renameError:M,setRenameError:N,handleOpenRename:P,handleRenameSubmit:te,deletingId:F,deleteConfirmOpen:I,setDeleteConfirmOpen:ne,targetToDelete:R,handleOpenDelete:z,handleDeleteSubmit:B,testingId:re,handleTestPasskey:U}=nt({onRefresh:e,toasterRef:r});return s?(0,$.jsx)(tt,{recoveryKeys:s,copied:l,onCopy:f,onDone:()=>c(null)}):(0,$.jsxs)(`div`,{className:`space-y-4`,children:[(0,$.jsx)(oe,{ref:r}),(0,$.jsxs)(`div`,{className:`flex items-center justify-between mb-4`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(u,{size:20,className:`text-purple-500`}),(0,$.jsx)(G,{style:{margin:0},children:t(`account.passkey.title`,`Passkeys`)}),(0,$.jsx)(q,{intent:i.length>0?H.SUCCESS:H.NONE,minimal:!0,round:!0,children:i.length>0?t(`account.passkey.count`,{count:i.length,defaultValue:`${i.length} configured`}):t(`account.passkey.none`,`None configured`)})]}),(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[o&&i.length>0&&(0,$.jsx)(L,{intent:H.NONE,outlined:!0,icon:(0,$.jsx)(n,{size:16}),text:t(`account.passkey.testBtn`,`Test Passkey`),onClick:()=>U(),loading:re===`all`}),o&&(0,$.jsx)(L,{intent:H.PRIMARY,icon:(0,$.jsx)(O,{size:16}),text:t(`account.passkey.addBtn`,`Add Passkey`),onClick:C})]})]}),(0,$.jsx)(`p`,{className:`text-sm text-gray-600 dark:text-gray-400 mb-4`,children:t(`account.passkey.desc`,`Authenticate securely with biometrics (Touch ID, Face ID, Windows Hello) or a hardware security key (YubiKey) as an MFA factor.`)}),!o&&(0,$.jsx)(V,{intent:H.WARNING,icon:(0,$.jsx)(S,{size:16}),className:`mb-4`,children:t(`account.passkey.notSupported`,`Your browser or device does not support Passkeys (WebAuthn).`)}),(0,$.jsx)(rt,{passkeys:i,loading:a,deletingId:F,testingId:re,onTestPasskey:U,onOpenRename:P,onOpenDelete:z}),(0,$.jsx)(it,{isOpen:p,onClose:()=>m(!1),passkeyName:h,setPasskeyName:g,nameFocused:_,setNameFocused:v,registering:y,addError:b,setAddError:x,onSubmit:w}),(0,$.jsx)(at,{isOpen:!!T,onClose:()=>E(null),editName:D,setEditName:k,renameFocused:A,setRenameFocused:j,renaming:ee,renameError:M,setRenameError:N,onSubmit:te}),(0,$.jsx)(ot,{isOpen:I,onClose:()=>ne(!1),targetToDelete:R,deleting:!!F,onConfirm:B})]})},ct=({isOpen:e,onClose:n})=>{let{t:r}=d(),[i,a]=(0,Q.useState)(``),[o,s]=(0,Q.useState)(!1),[c,l]=(0,Q.useState)(``),[u,f]=(0,Q.useState)(!1);(0,Q.useEffect)(()=>{e&&(a(``),l(``),f(!1),s(!1))},[e]);let p=async e=>{let t=(e??i).trim().replace(/\s/g,``);if(t.length!==6){l(r(`account.totp.invalidCode`,`Please enter a 6-digit code`));return}s(!0),l(``),f(!1);try{await Ce(t),f(!0)}catch(e){l((e instanceof Error?e.message:String(e))||r(`account.totp.testFailed`,`Invalid verification code`))}finally{s(!1)}};return(0,$.jsx)(R,{isOpen:e,onClose:n,title:r(`account.totp.testTitle`,`Test Authenticator App (TOTP)`),icon:(0,$.jsx)(t,{size:18}),children:(0,$.jsxs)(`div`,{className:`p-6 space-y-4`,children:[(0,$.jsx)(`p`,{className:`text-sm text-gray-600 dark:text-gray-400`,children:r(`account.totp.testDesc`,`Enter the 6-digit verification code from your authenticator app to verify that it is generating valid codes.`)}),u&&(0,$.jsx)(V,{intent:H.SUCCESS,icon:(0,$.jsx)(v,{size:16}),children:r(`account.totp.testSuccess`,`Verification successful! Your authenticator app is configured properly.`)}),c&&(0,$.jsx)(V,{intent:H.DANGER,children:c}),(0,$.jsxs)(`form`,{onSubmit:e=>{e.preventDefault(),p()},className:`space-y-4`,children:[(0,$.jsx)(K,{label:r(`account.totp.verificationCode`,`6-Digit Verification Code`),labelFor:`test-totp-input`,children:(0,$.jsx)(W,{id:`test-totp-input`,value:i,onChange:e=>{let t=e.target.value.replace(/\D/g,``).slice(0,6);a(t),l(``),f(!1),t.length===6&&p(t)},placeholder:`123456`,maxLength:6,autoFocus:!0,inputMode:`numeric`,autoComplete:`one-time-code`,className:`font-mono text-lg tracking-widest`,disabled:o})}),(0,$.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,$.jsx)(L,{text:u?r(`common.close`,`Close`):r(`common.cancel`,`Cancel`),onClick:n}),!u&&(0,$.jsx)(L,{intent:H.PRIMARY,text:r(`account.totp.verifyBtn`,`Verify`),type:`submit`,loading:o,disabled:i.length!==6})]})]})]})})},lt=({user:e,disableDialogOpen:n,setDisableDialogOpen:r,disablePassword:i,setDisablePassword:a,disableError:s,setDisableError:c,disableLoading:l,onDisable:u})=>{let{t:f}=d(),[p,m]=Q.useState(!1),[h,g]=Q.useState(!1);return(0,$.jsxs)(`div`,{className:`space-y-4`,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-2 mb-4`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(o,{size:20,className:`text-blue-500`}),(0,$.jsx)(G,{style:{margin:0},children:f(`account.totp.title`,`Authenticator App (TOTP)`)}),(0,$.jsx)(q,{intent:H.SUCCESS,minimal:!0,round:!0,children:f(`account.totp.enabled`,`Enabled`)})]}),(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(L,{outlined:!0,icon:(0,$.jsx)(t,{size:14}),text:f(`account.totp.testBtn`,`Test Code`),onClick:()=>g(!0)}),(0,$.jsx)(L,{intent:H.DANGER,outlined:!0,icon:(0,$.jsx)(C,{size:14}),text:f(`account.totp.disable`,`Disable Authenticator App (TOTP)`),onClick:()=>r(!0)})]})]}),(0,$.jsx)(`div`,{className:`space-y-4`,children:(0,$.jsx)(`p`,{className:`text-sm text-gray-600 dark:text-gray-400`,children:f(`account.totp.activeDesc`,`Authenticator app (TOTP) is active and generating 6-digit verification codes for your account.`)})}),(0,$.jsx)(R,{isOpen:n,onClose:()=>{r(!1),a(``),c(``),m(!1)},title:f(`account.totp.disableTitle`,`Disable Authenticator App (TOTP)`),icon:`shield`,children:(0,$.jsxs)(`div`,{className:`p-6 space-y-4`,children:[(0,$.jsx)(V,{intent:H.WARNING,children:f(`account.totp.disableWarning`,`After disabling TOTP, if no Passkeys are configured, your account will only be protected by password.`)}),s&&(0,$.jsx)(V,{intent:H.DANGER,children:s}),!e.totp_skip_password&&(0,$.jsxs)(`form`,{onSubmit:u,className:`space-y-4`,children:[(0,$.jsx)(K,{label:f(`account.currentPassword`),children:(0,$.jsx)(W,{type:p?`text`:`password`,leftIcon:`lock`,value:i,onChange:e=>a(e.target.value),rightElement:(0,$.jsx)(L,{minimal:!0,icon:p?`eye-open`:`eye-off`,onClick:()=>m(!p),title:p?f(`auth.hidePassword`,`Hide password`):f(`auth.showPassword`,`Show password`)}),required:!0})}),(0,$.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,$.jsx)(L,{text:f(`account.cancel`),onClick:()=>r(!1)}),(0,$.jsx)(L,{intent:H.DANGER,text:f(`account.totp.confirmDisable`,`Disable TOTP`),type:`submit`,loading:l})]})]}),e.totp_skip_password&&(0,$.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,$.jsx)(L,{text:f(`account.cancel`),onClick:()=>r(!1)}),(0,$.jsx)(L,{intent:H.DANGER,text:f(`account.totp.confirmDisable`,`Disable TOTP`),loading:l,onClick:u})]})]})}),(0,$.jsx)(ct,{isOpen:h,onClose:()=>g(!1)})]})},ut=({setupData:e,setupToken:t,setSetupToken:n,setupError:r,setupLoading:i,onStartSetup:s,onConfirmSetup:c,onCancel:l})=>{let{t:u}=d();return(0,$.jsxs)(`div`,{className:`space-y-4`,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-2 mb-4`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(o,{size:20,className:`text-blue-500`}),(0,$.jsx)(G,{style:{margin:0},children:u(`account.totp.title`,`Authenticator App (TOTP)`)}),(0,$.jsx)(q,{minimal:!0,round:!0,intent:H.NONE,children:u(`account.totp.disabled`,`Disabled`)})]}),!e&&(0,$.jsx)(L,{intent:H.PRIMARY,icon:(0,$.jsx)(a,{size:14}),text:u(`account.totp.setupBtn`,`Set Up Authenticator App (TOTP)`),loading:i,onClick:s})]}),e?(0,$.jsxs)(`div`,{className:`space-y-4`,children:[(0,$.jsx)(`p`,{className:`text-sm font-medium`,children:u(`account.totp.scanQR`,`Scan this QR code with your authenticator app:`)}),(0,$.jsxs)(`div`,{className:`flex flex-col items-center gap-3`,children:[(0,$.jsx)(Ke,{uri:e.uri}),(0,$.jsxs)(`div`,{className:`text-center`,children:[(0,$.jsx)(`p`,{className:`text-xs text-gray-500 mb-1`,children:u(`account.totp.orEnterManually`,`Or enter the key manually:`)}),(0,$.jsx)(`code`,{className:`text-xs font-mono bg-gray-100 dark:bg-gray-800 px-2 py-1 rounded select-all`,children:e.secret})]})]}),(0,$.jsx)(U,{}),r&&(0,$.jsx)(V,{intent:H.DANGER,children:r}),(0,$.jsxs)(`form`,{onSubmit:c,className:`space-y-3`,children:[(0,$.jsx)(K,{label:u(`account.totp.enterCode`,`Enter the 6-digit code to confirm:`),helperText:u(`account.totp.enterCodeHint`,`This verifies the key was scanned correctly.`),children:(0,$.jsx)(Le,{length:6,value:t,onChange:n,disabled:i})}),(0,$.jsxs)(`div`,{className:`flex gap-2`,children:[(0,$.jsx)(L,{text:u(`account.cancel`),onClick:l}),(0,$.jsx)(L,{intent:H.SUCCESS,type:`submit`,loading:i,text:u(`account.totp.activate`,`Activate`),disabled:t.length<6})]})]})]}):(0,$.jsxs)(`div`,{className:`space-y-3`,children:[(0,$.jsx)(`p`,{className:`text-sm text-gray-600 dark:text-gray-400`,children:u(`account.totp.setupDesc`,`Add an extra layer of security. Use Google Authenticator, Authy, or any TOTP app.`)}),r&&(0,$.jsx)(V,{intent:H.DANGER,children:r})]})]})},dt=({user:e,onRefresh:t})=>{let{t:n}=d(),[r,i]=(0,Q.useState)(null),[a,o]=(0,Q.useState)(``),[s,c]=(0,Q.useState)(null),[l,u]=(0,Q.useState)(!1),[f,p]=(0,Q.useState)(``),[m,h]=(0,Q.useState)(!1),[g,_]=(0,Q.useState)(!1),[v,y]=(0,Q.useState)(``),[b,x]=(0,Q.useState)(!1),[S,C]=(0,Q.useState)(``),[w,T]=(0,Q.useState)(!1);return s?(0,$.jsx)(tt,{recoveryKeys:s,copied:m,onCopy:()=>{s&&navigator.clipboard.writeText(s.join(`
4
- `)).then(()=>{h(!0),setTimeout(()=>h(!1),2e3)})},onDone:()=>c(null)}):e.totp_enabled?(0,$.jsx)(lt,{user:e,settingsLoading:w,onToggleSkipPassword:async e=>{T(!0);try{await xe(e),t()}catch{}finally{T(!1)}},disableDialogOpen:g,setDisableDialogOpen:_,disablePassword:v,setDisablePassword:y,disableError:S,setDisableError:C,disableLoading:b,onDisable:async r=>{r.preventDefault(),x(!0),C(``);try{let n=v;e.password_version===2&&(n=await Ne(v,e.username)),await Ye(n),_(!1),y(``),t()}catch(e){C(e.message||n(`common.errorNetwork`))}finally{x(!1)}}}):(0,$.jsx)(ut,{setupData:r,setupToken:a,setSetupToken:o,setupError:f,setupLoading:l,onStartSetup:async()=>{u(!0),p(``);try{i(await Re())}catch(e){p(e.message||n(`common.errorNetwork`))}finally{u(!1)}},onConfirmSetup:async e=>{if(e.preventDefault(),r){u(!0),p(``);try{let e=a.replace(/\s/g,``),n=crypto.randomUUID(),s=new TextEncoder().encode(e+n),l=await crypto.subtle.digest(`SHA-256`,s),u=Array.from(new Uint8Array(l)).map(e=>e.toString(16).padStart(2,`0`)).join(``);c((await Ie({secret:r.secret,totpTokenHash:u,salt:n})).recovery_keys),i(null),o(``),t()}catch(e){p(e.message||n(`common.errorNetwork`))}finally{u(!1)}}},onCancel:()=>{i(null),o(``),p(``)}})},ft=({method:e,onSelectMethod:t,hasPasskey:r,hasRecoveryKey:i,hasTotp:a,hasPassword:o})=>{let{t:s}=d();return(0,$.jsx)(`div`,{className:`flex justify-center mb-5 isolate`,style:{isolation:`isolate`},children:(0,$.jsx)(`div`,{className:`w-full bg-gray-100/70 dark:bg-gray-800/70 p-1 rounded-lg`,children:(0,$.jsxs)(N,{fill:!0,variant:`minimal`,style:{isolation:`isolate`},children:[r&&(0,$.jsx)(L,{small:!0,active:e===`passkey`,intent:e===`passkey`?H.PRIMARY:H.NONE,icon:(0,$.jsx)(u,{size:14}),text:s(`account.mfa.passkey`,`Passkey`),onClick:()=>t(`passkey`)}),i&&(0,$.jsx)(L,{small:!0,active:e===`recovery_key`,intent:e===`recovery_key`?H.PRIMARY:H.NONE,icon:(0,$.jsx)(u,{size:14}),text:s(`account.recoveryKey.verifyBtn`,`Recovery Key`),onClick:()=>t(`recovery_key`)}),a&&(0,$.jsx)(L,{small:!0,active:e===`totp`,intent:e===`totp`?H.PRIMARY:H.NONE,icon:(0,$.jsx)(n,{size:14}),text:s(`account.mfa.totp`,`TOTP`),onClick:()=>t(`totp`)}),o&&(0,$.jsx)(L,{small:!0,active:e===`password`,intent:e===`password`?H.PRIMARY:H.NONE,icon:(0,$.jsx)(h,{size:14}),text:s(`account.mfa.password`,`Password`),onClick:()=>t(`password`)})]})})})},pt=({loading:e,onVerify:t})=>{let{t:n}=d();return(0,$.jsxs)(`div`,{className:`text-center py-4 space-y-4`,children:[(0,$.jsx)(`div`,{className:`flex justify-center`,children:(0,$.jsx)(`div`,{className:`p-4 rounded-full bg-blue-50 dark:bg-blue-900/30 text-blue-500`,children:(0,$.jsx)(u,{size:48})})}),(0,$.jsx)(`p`,{className:`text-sm text-gray-600 dark:text-gray-300`,children:n(`account.passkey.verifyPrompt`,`Authenticate using your device's biometric sensor (Face ID, Touch ID, Windows Hello) or security key.`)}),(0,$.jsx)(L,{fill:!0,large:!0,intent:H.PRIMARY,loading:e,onClick:t,icon:(0,$.jsx)(u,{size:16}),text:n(`account.usePasskeyInstead`,`Authenticate with Passkey`)})]})},mt=({totpCode:e,setTotpCode:t,loading:n,onVerify:r})=>{let{t:i}=d();return(0,$.jsxs)(`div`,{className:`py-2 space-y-4`,children:[(0,$.jsx)(K,{label:i(`account.totpCode`,`Authenticator Code`),children:(0,$.jsx)(Le,{length:6,value:e,onChange:e=>{t(e),e.length===6&&r(e)},disabled:n})}),(0,$.jsx)(L,{fill:!0,intent:H.PRIMARY,loading:n,disabled:e.length!==6,onClick:()=>r(),text:i(`common.confirm`,`Confirm`)})]})},ht=({password:e,setPassword:t,showPassword:n,setShowPassword:r,loading:i,onSubmit:a})=>{let{t:o}=d();return(0,$.jsxs)(`form`,{onSubmit:a,className:`py-2 space-y-4`,children:[(0,$.jsx)(K,{label:o(`account.currentPassword`,`Current Password`),children:(0,$.jsx)(W,{leftIcon:`lock`,type:n?`text`:`password`,value:e,onChange:e=>t(e.target.value),autoFocus:!0,rightElement:(0,$.jsx)(L,{minimal:!0,icon:n?`eye-open`:`eye-off`,onClick:()=>r(!n)})})}),(0,$.jsx)(L,{fill:!0,intent:H.PRIMARY,type:`submit`,loading:i,text:o(`common.confirm`,`Confirm`)})]})},gt=({recoveryKey:e,setRecoveryKey:t,loading:n,onSubmit:r})=>{let{t:i}=d();return(0,$.jsxs)(`form`,{onSubmit:r,autoComplete:`off`,className:`py-2 space-y-4`,children:[(0,$.jsx)(K,{label:i(`account.recoveryKey.verifyPromptLabel`,`原恢复密钥 (Original Recovery Key)`),children:(0,$.jsx)(W,{leftIcon:`key`,type:`text`,id:`verify-recovery-key-input`,name:`verify_recovery_key_input`,autoComplete:`off`,autoCorrect:`off`,autoCapitalize:`off`,spellCheck:!1,"data-1p-ignore":`true`,"data-lpignore":`true`,"data-bwignore":`true`,placeholder:`123456-789012-345678-901234-567890`,value:e,onChange:e=>t(e.target.value),autoFocus:!0,className:`font-mono text-xs`})}),(0,$.jsx)(L,{fill:!0,intent:H.PRIMARY,type:`submit`,loading:n,disabled:!e.trim(),text:i(`common.confirm`,`Confirm`)})]})};var _t=(e,t)=>{let n=t||[`passkey`,`totp`,`password`];return n.includes(`passkey`)&&e?.passkeys_count&&e.passkeys_count>0?`passkey`:n.includes(`recovery_key`)?`recovery_key`:n.includes(`totp`)&&e?.totp_enabled?`totp`:n.includes(`password`)?`password`:n[0]||`password`};const vt=({isOpen:e,onClose:t,user:n,title:r,onVerify:i,allowedMethods:a})=>{let{t:o}=d(),s=a||[`passkey`,`totp`,`password`],c=!!(n?.passkeys_count&&n.passkeys_count>0)&&s.includes(`passkey`),l=!!n?.totp_enabled&&s.includes(`totp`),u=s.includes(`password`),f=s.includes(`recovery_key`),p=_t(n,a),[m,h]=(0,Q.useState)(p),[g,_]=(0,Q.useState)(``),[v,y]=(0,Q.useState)(!1),[b,x]=(0,Q.useState)(``),[S,C]=(0,Q.useState)(``),[w,T]=(0,Q.useState)(!1),[E,D]=(0,Q.useState)(``),[O,k]=(0,Q.useState)(e);!O&&e?(k(!0),h(p),_(``),y(!1),x(``),C(``),D(``)):O&&!e&&k(!1),(0,Q.useEffect)(()=>{m===`passkey`&&!c?h(f?`recovery_key`:l?`totp`:`password`):m===`totp`&&!l?h(c?`passkey`:f?`recovery_key`:`password`):m===`recovery_key`&&!f&&h(c?`passkey`:l?`totp`:`password`)},[c,l,f,m]);let A=async e=>{if(e&&e.preventDefault(),!g){D(o(`auth.passwordRequired`,`Password is required`));return}T(!0),D(``);try{let e=g;n?.password_version===2&&n?.username&&(e=await Ne(g,n.username)),await i({password:e}),t()}catch(e){D(Je(e,o))}finally{T(!1)}},j=async()=>{T(!0),D(``);try{await i({passkeyAssertion:await fe(await Qe())}),t()}catch(e){D(Je(e,o))}finally{T(!1)}},ee=async e=>{let n=e||b;if(n.length!==6){D(o(`account.totp.invalidCode`,`Please enter a 6-digit code`));return}T(!0),D(``);try{let e=crypto.randomUUID(),r=new TextEncoder().encode(n+e),a=await crypto.subtle.digest(`SHA-256`,r);await i({totpTokenHash:Array.from(new Uint8Array(a)).map(e=>e.toString(16).padStart(2,`0`)).join(``),totpSalt:e}),t()}catch(e){D(Je(e,o))}finally{T(!1)}},M=async e=>{e&&e.preventDefault();let n=S.trim();if(!n){D(o(`account.recoveryKey.keyRequired`,`Recovery key is required`));return}T(!0),D(``);try{await i({recoveryKey:n}),t()}catch(e){D(Je(e,o))}finally{T(!1)}},N=(c?1:0)+(f?1:0)+(l?1:0)+(u?1:0);return(0,$.jsx)(R,{isOpen:e,onClose:t,title:r||o(`account.verifyIdentity`,`Security Verification`),icon:`shield`,className:`max-w-md w-full`,children:(0,$.jsxs)(`div`,{className:I,children:[(0,$.jsx)(`p`,{className:`text-sm text-gray-600 dark:text-gray-400 mb-4`,children:o(`account.verifyIdentityDesc`,`To protect your account security, please verify your identity before proceeding.`)}),N>1&&(0,$.jsx)(ft,{method:m,onSelectMethod:e=>{h(e),D(``)},hasPasskey:c,hasRecoveryKey:f,hasTotp:l,hasPassword:u}),E&&(0,$.jsx)(V,{intent:H.DANGER,className:`mb-4`,children:E}),m===`recovery_key`&&(0,$.jsx)(gt,{recoveryKey:S,setRecoveryKey:C,loading:w,onSubmit:M}),m===`passkey`&&(0,$.jsx)(pt,{loading:w,onVerify:j}),m===`totp`&&(0,$.jsx)(mt,{totpCode:b,setTotpCode:x,loading:w,onVerify:ee}),m===`password`&&(0,$.jsx)(ht,{password:g,setPassword:_,showPassword:v,setShowPassword:y,loading:w,onSubmit:A})]})})},yt=({user:e,onRefresh:t})=>{let{t:r}=d(),[i,a]=(0,Q.useState)(!1),[o,s]=(0,Q.useState)(!1),[c,l]=(0,Q.useState)(null),[p,m]=(0,Q.useState)(!1),[g,_]=(0,Q.useState)(!1),[v,b]=(0,Q.useState)(null),C=!!(e.has_recovery_keys||e.recovery_keys_encrypted),E=()=>{b(null),s(!0)},D=()=>{s(!1),a(!0)},O=async e=>{let n=await ze(e);l(n.recovery_key),m(!1);let i=!1;if(Z.isUnlocked())try{await Z.wrapCurrentKeyForRecovery(n.recovery_key),i=!0}catch(e){console.warn(`[RecoveryKey] Failed to wrap E2EE key with new recovery key:`,e)}else if(e.recoveryKey)try{await Z.unlockWithRecoveryKey(e.recoveryKey),await Z.wrapCurrentKeyForRecovery(n.recovery_key),i=!0}catch(e){console.warn(`[RecoveryKey] Failed to unlock and re-wrap with new recovery key:`,e)}else if(e.passkeyAssertion)try{await Z.unlockUser(),await Z.wrapCurrentKeyForRecovery(n.recovery_key),i=!0}catch(e){console.warn(`[RecoveryKey] Failed to unlock via Passkey and re-wrap:`,e)}try{if((await Z.getUserStatus()).hasKeys&&!i){b({text:r(`account.recoveryKey.rotateSuccessE2eeWarning`,`恢复密钥已成功轮换!注意:由于端到端加密此前处于锁定状态且未能解密,旧 E2EE 密文仍需使用轮换前的旧恢复密钥解锁,或可在下方端到端加密卡片中点击「重置密钥对」。`),intent:H.WARNING}),t();return}}catch{}b({text:r(`account.recoveryKey.rotateSuccess`,`恢复密钥已成功轮换!请立即妥善离线保存新密钥,旧密钥已失效。`),intent:H.SUCCESS}),t()},k=e=>{navigator.clipboard.writeText(e),_(!0),setTimeout(()=>_(!1),2e3)};return(0,$.jsxs)(`div`,{className:`space-y-4`,children:[(0,$.jsxs)(`div`,{className:`flex flex-col sm:flex-row sm:items-center justify-between gap-3`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[(0,$.jsx)(u,{size:18,className:`text-amber-500`}),(0,$.jsx)(G,{style:{margin:0},children:r(`account.recoveryKey.title`,`紧急恢复密钥`)}),(0,$.jsx)(q,{intent:C?H.SUCCESS:H.NONE,minimal:!0,round:!0,children:C?r(`account.recoveryKey.configured`,`已配置`):r(`account.recoveryKey.notConfigured`,`未配置`)}),(0,$.jsx)(ce,{content:r(`account.recoveryKey.oneWayTooltip`,`采用 SHA-256 单向密码学散列保护,服务端不存储明文且不可解密,仅支持身份轮换验证。`),position:M.TOP,children:(0,$.jsx)(q,{intent:H.PRIMARY,minimal:!0,round:!0,icon:(0,$.jsx)(n,{size:12,style:{display:`inline-flex`,alignItems:`center`,marginRight:`4px`}}),children:r(`account.recoveryKey.oneWayHash`,`单向不可逆散列`)})})]}),(0,$.jsx)(`div`,{className:`flex items-center gap-2`,children:(0,$.jsx)(L,{small:!0,intent:H.WARNING,icon:(0,$.jsx)(f,{size:14}),text:r(`account.recoveryKey.rotateBtn`,`轮换恢复密钥`),onClick:E})})]}),(0,$.jsx)(`p`,{className:`text-sm text-gray-600 dark:text-gray-400`,children:r(`account.recoveryKey.descOneWay`,`紧急恢复密钥是在您丢失所有通行密钥 (Passkey) 或身份验证器时,恢复账号访问及端到端解密数据的唯一凭据。为确保零知识安全,恢复密钥采用单向不可逆散列存储,无法在网页端查看明文,仅支持通过原恢复密钥或现有 Passkey 进行轮换。密钥一旦被使用将立即自动轮换。`)}),v&&(0,$.jsx)(V,{intent:v.intent,className:`my-2`,children:v.text}),c&&(0,$.jsxs)(J,{elevation:F.ZERO,className:`bg-amber-50/50 dark:bg-amber-950/20 border border-amber-300 dark:border-amber-800 p-4 space-y-3`,children:[(0,$.jsxs)(`div`,{className:`flex flex-col sm:flex-row sm:items-center justify-between gap-2`,children:[(0,$.jsxs)(`span`,{className:`text-xs font-semibold text-amber-800 dark:text-amber-300 uppercase tracking-wider flex items-center gap-1.5`,children:[(0,$.jsx)(S,{size:14}),r(`account.recoveryKey.newKeyGenerated`,`已生成全新 30 位恢复密钥(请立即保存)`)]}),(0,$.jsxs)(`div`,{className:`flex items-center gap-1.5 flex-wrap`,children:[(0,$.jsx)(L,{minimal:!0,small:!0,icon:p?(0,$.jsx)(T,{size:14}):(0,$.jsx)(x,{size:14}),onClick:()=>m(!p),title:p?r(`auth.showPassword`,`显示`):r(`auth.hidePassword`,`隐藏`)}),(0,$.jsx)(L,{minimal:!0,small:!0,icon:g?(0,$.jsx)(y,{size:14,className:`text-green-500`}):(0,$.jsx)(w,{size:14}),onClick:()=>k(c),title:r(`common.copy`,`复制`),text:g?r(`common.copied`,`已复制`):r(`common.copy`,`复制`)}),(0,$.jsx)(L,{minimal:!0,small:!0,icon:`cross`,onClick:()=>l(null),title:r(`common.close`,`关闭`)})]})]}),(0,$.jsx)(`div`,{className:`p-3 bg-white dark:bg-gray-900 rounded border border-amber-200 dark:border-amber-800/80 font-mono text-center text-lg sm:text-xl font-bold tracking-widest select-all text-gray-900 dark:text-gray-100`,children:p?`••••••-••••••-••••••-••••••-••••••`:c}),(0,$.jsxs)(`p`,{className:`text-xs text-amber-700 dark:text-amber-400 flex items-center gap-1`,children:[(0,$.jsx)(h,{size:14,className:`shrink-0`}),r(`account.recoveryKey.oneWayWarning`,`注意:此密钥仅在此显示一次,关闭后将无法再次查看!服务端仅保存不可逆散列,请务必将其妥善复制并离线安全保存。`)]})]}),(0,$.jsx)(P,{isOpen:o,onConfirm:D,onCancel:()=>s(!1),cancelButtonText:r(`common.cancel`,`取消`),confirmButtonText:r(`account.recoveryKey.confirmRotateBtn`,`确认进入轮换验证`),intent:H.DANGER,icon:`warning-sign`,children:(0,$.jsx)(`p`,{children:r(`account.recoveryKey.rotateConfirm`,`轮换恢复密钥将立即使原恢复密钥失效,并重新派生信封加密密钥。仅允许通过现有通行密钥 (Passkey) 或原恢复密钥完成轮换验证。是否继续?`)})}),(0,$.jsx)(vt,{isOpen:i,onClose:()=>a(!1),user:e,allowedMethods:[`passkey`,`recovery_key`],title:r(`account.recoveryKey.rotateVerifyTitle`,`验证身份以轮换恢复密钥`),onVerify:O})]})},bt=({user:e,onRefresh:r})=>{let{t:i}=d(),[a,o]=(0,Q.useState)(!1),s=!!(e.mfa_enabled??(e.totp_enabled||e.passkeys_count&&e.passkeys_count>0)),c=async e=>{o(!0);try{await ve(e),r()}catch(e){alert(e.message||i(`common.errorNetwork`,`Network error`))}finally{o(!1)}};return(0,$.jsxs)(J,{elevation:F.ONE,className:`space-y-6`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`div`,{className:`flex items-center justify-between mb-3`,children:(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(n,{size:20,className:s?`text-green-500`:`text-gray-400`}),(0,$.jsx)(G,{style:{margin:0},children:i(`account.mfa.title`,`Multi-Factor Authentication (MFA)`)}),(0,$.jsx)(q,{intent:s?H.SUCCESS:H.NONE,minimal:!0,round:!0,children:s?i(`account.mfa.enabled`,`Configured`):i(`account.mfa.notConfigured`,`Not Configured`)})]})}),(0,$.jsx)(`p`,{className:`text-sm text-gray-600 dark:text-gray-400 mb-4`,children:i(`account.mfa.desc`,`Passkeys and Authenticator Apps (TOTP) both serve as MFA authentication methods. Configuring at least one factor protects your account and enables passwordless login and self-service password recovery.`)}),s?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(U,{className:`my-3`}),(0,$.jsxs)(`div`,{className:`flex flex-col sm:flex-row sm:items-center justify-between gap-2 py-1`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`div`,{className:`font-medium text-sm text-gray-900 dark:text-gray-100`,children:i(`account.mfa.passwordlessTitle`,`Passwordless Login`)}),(0,$.jsx)(`div`,{className:`text-xs text-gray-500 dark:text-gray-400`,children:i(`account.mfa.passwordlessDesc`,`When enabled, logging in will skip the password requirement and verify your identity directly via Passkey or TOTP.`)})]}),(0,$.jsx)(ae,{checked:!!e.totp_skip_password,onChange:e=>c(e.currentTarget.checked),disabled:a,className:`mb-0 shrink-0`})]})]}):(0,$.jsx)(V,{intent:H.PRIMARY,icon:(0,$.jsx)(t,{size:16,style:{display:`inline-flex`,alignItems:`center`,marginRight:`8px`}}),children:i(`account.mfa.unconfiguredHint`,`No MFA method configured yet. Set up either a Passkey or Authenticator App below to safeguard your account and unlock passwordless login and account recovery.`)})]}),(0,$.jsx)(U,{}),(0,$.jsx)(st,{onRefresh:r}),(0,$.jsx)(U,{}),(0,$.jsx)(dt,{user:e,onRefresh:r}),(0,$.jsx)(U,{}),(0,$.jsx)(yt,{user:e,onRefresh:r})]})},xt={signup:{label:`account.activity.signup`,icon:(0,$.jsx)(E,{size:14}),intent:H.SUCCESS},login_success:{label:`account.activity.loginSuccess`,icon:(0,$.jsx)(g,{size:14}),intent:H.SUCCESS},login_fail:{label:`account.activity.loginFail`,icon:(0,$.jsx)(p,{size:14}),intent:H.DANGER},logout:{label:`account.activity.logout`,icon:(0,$.jsx)(c,{size:14}),intent:H.NONE},password_change_success:{label:`account.activity.pwChangeSuccess`,icon:(0,$.jsx)(u,{size:14}),intent:H.SUCCESS},password_change_fail:{label:`account.activity.pwChangeFail`,icon:(0,$.jsx)(p,{size:14}),intent:H.DANGER},totp_verify_success:{label:`account.activity.totpVerifySuccess`,icon:(0,$.jsx)(n,{size:14}),intent:H.SUCCESS},totp_verify_fail:{label:`account.activity.totpVerifyFail`,icon:(0,$.jsx)(p,{size:14}),intent:H.DANGER},totp_setup:{label:`account.activity.totpSetup`,icon:(0,$.jsx)(a,{size:14}),intent:H.PRIMARY},totp_removed:{label:`account.activity.totpRemoved`,icon:(0,$.jsx)(C,{size:14}),intent:H.WARNING},recovery_key_used:{label:`account.activity.recoveryKeyUsed`,icon:(0,$.jsx)(u,{size:14}),intent:H.WARNING},recovery_key_rotated:{label:`account.activity.recoveryKeyRotated`,icon:(0,$.jsx)(u,{size:14}),intent:H.WARNING},session_revoked:{label:`account.activity.sessionRevoked`,icon:(0,$.jsx)(c,{size:14}),intent:H.WARNING},passkey_registered:{label:`account.activity.passkeyRegistered`,icon:(0,$.jsx)(u,{size:14}),intent:H.PRIMARY},passkey_deleted:{label:`account.activity.passkeyDeleted`,icon:(0,$.jsx)(C,{size:14}),intent:H.WARNING},passkey_verify_success:{label:`account.activity.passkeyVerifySuccess`,icon:(0,$.jsx)(n,{size:14}),intent:H.SUCCESS},passkey_verify_fail:{label:`account.activity.passkeyVerifyFail`,icon:(0,$.jsx)(p,{size:14}),intent:H.DANGER}},St=e=>{if(!e)return`desktop`;let t=e.toLowerCase();return t.includes(`mobile`)||t.includes(`android`)||t.includes(`iphone`)||t.includes(`tablet`)||t.includes(`ipad`)?`mobile-phone`:`desktop`},Ct=(e,t)=>{if(!e)return t;let n=e;return n.includes(`Edg/`)?`Edge`:n.includes(`Chrome/`)&&!n.includes(`Edg/`)?`Chrome`:n.includes(`Firefox/`)?`Firefox`:n.includes(`Safari/`)&&!n.includes(`Chrome/`)?`Safari`:t},wt=({userAgent:e})=>{let{t}=d();if(!e)return(0,$.jsx)(`span`,{className:`text-gray-500`,children:`—`});let n=Ct(e,t(`account.sessions.unknownDevice`,`Unknown Device`));return(0,$.jsxs)(`div`,{children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(te,{icon:St(e),className:`text-gray-400`}),(0,$.jsx)(`span`,{children:n})]}),(0,$.jsx)(`div`,{className:`text-xs text-gray-400 mt-1 max-w-xs truncate`,title:e,children:e})]})},Tt=({hoveredSessionId:e,setHoveredSessionId:t})=>{let{t:n}=d(),[r,i]=(0,Q.useState)([]),[a,o]=(0,Q.useState)(!0),[c,l]=(0,Q.useState)(!0),[u,p]=(0,Q.useState)(!1),m=(0,Q.useCallback)(async e=>{o(!0);try{let t=new URLSearchParams({limit:`20`});e&&t.set(`before`,String(e));let n=await $e(t.toString());i(e?e=>[...e,...n]:n),l(n.length===20)}catch{}finally{o(!1)}},[]);(0,Q.useEffect)(()=>{m()},[m]);let h=()=>{let e=r[r.length-1];e&&m(e.timestamp)},g=e=>xt[e]??{label:e,icon:(0,$.jsx)(s,{size:14}),intent:H.NONE};return(0,$.jsxs)(J,{elevation:F.ONE,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between cursor-pointer`,onClick:()=>p(!u),children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(s,{size:20,className:`text-purple-500`}),(0,$.jsx)(G,{style:{margin:0},children:n(`account.activity.title`,`Account Activity`)}),r.length>0&&(0,$.jsxs)(q,{minimal:!0,round:!0,intent:H.NONE,children:[r.length,c?`+`:``]})]}),(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(L,{minimal:!0,icon:(0,$.jsx)(f,{size:14}),onClick:e=>{e.stopPropagation(),m()}}),(0,$.jsx)(b,{size:16,className:`text-gray-400 transition-transform ${u?`rotate-180`:``}`})]})]}),u&&(0,$.jsx)(`div`,{className:`mt-4`,children:a&&r.length===0?(0,$.jsx)(`div`,{className:`flex justify-center py-8`,children:(0,$.jsx)(z,{size:24})}):r.length===0?(0,$.jsx)(`p`,{className:`text-sm text-gray-500 text-center py-6`,children:n(`account.activity.empty`,`No activity recorded yet.`)}):(0,$.jsxs)(`div`,{className:`overflow-x-auto`,children:[(0,$.jsxs)(se,{interactive:!0,striped:!0,className:`w-full text-sm`,children:[(0,$.jsx)(`thead`,{children:(0,$.jsxs)(`tr`,{children:[(0,$.jsx)(`th`,{children:n(`account.activity.action`,`Action`)}),(0,$.jsx)(`th`,{children:n(`account.activity.time`,`Time`)}),(0,$.jsx)(`th`,{children:n(`account.activity.session`,`Session`)}),(0,$.jsx)(`th`,{children:n(`account.activity.ip`,`IP Address`)}),(0,$.jsx)(`th`,{children:n(`account.activity.device`,`Device`)})]})}),(0,$.jsx)(`tbody`,{children:r.map(r=>{let i=g(r.action),a=``,o=r.session_id_hash||``;if(r.extra)try{let e=JSON.parse(r.extra);if(e.reason){let t=`account.activity.reasons.${e.reason}`,r=n(t);a=r&&r!==t?r:e.reason.replace(/[_-]+/g,` `).replace(/\b\w/g,e=>e.toUpperCase())}}catch{}return(0,$.jsxs)(`tr`,{onMouseEnter:()=>{o&&t?.(o)},onMouseLeave:()=>{o&&t?.(null)},className:e&&e===o?`bg-gray-100/80 dark:bg-slate-800/80`:``,children:[(0,$.jsx)(`td`,{className:`align-middle`,children:(0,$.jsxs)(`div`,{className:`flex flex-col items-start gap-1`,children:[(0,$.jsx)(q,{minimal:!0,intent:i.intent,icon:i.icon,children:n(i.label,r.action)}),a&&(0,$.jsx)(`span`,{className:`text-xs text-gray-500 italic ml-1`,children:a})]})}),(0,$.jsx)(`td`,{className:`text-xs text-gray-500 whitespace-nowrap align-middle`,children:X(new Date(r.timestamp*1e3))}),(0,$.jsx)(`td`,{className:`font-mono text-xs text-gray-500 align-middle`,children:o?o.slice(0,8):`—`}),(0,$.jsx)(`td`,{className:`font-mono text-xs text-gray-500 align-middle`,children:r.ip_address||`—`}),(0,$.jsx)(`td`,{className:`align-middle`,children:(0,$.jsx)(wt,{userAgent:r.user_agent||null})})]},r.id)})})]}),c&&(0,$.jsx)(`div`,{className:`flex justify-center mt-3`,children:(0,$.jsx)(L,{minimal:!0,loading:a,text:n(`account.activity.loadMore`,`Load More`),onClick:h})})]})})]})},Et=({hoveredSessionId:e,setHoveredSessionId:t})=>{let{t:n}=d(),[r,i]=(0,Q.useState)([]),[a,o]=(0,Q.useState)(!0),[s,l]=(0,Q.useState)(null),[u,p]=(0,Q.useState)(!1),[h,g]=(0,Q.useState)(!1),_=r.filter(e=>!e.is_current).length,v=(0,Q.useCallback)(async()=>{o(!0);try{let e=await Ze(),t=Date.now();i((e||[]).filter(e=>e.expires_at*1e3>t))}catch{}finally{o(!1)}},[]);(0,Q.useEffect)(()=>{v()},[v]);let y=async e=>{l(e);try{(await we(e)).is_current?window.location.reload():i(t=>t.filter(t=>t.id!==e))}catch(e){alert(e.message||n(`account.sessions.revokeFailed`,`Failed to revoke session.`))}finally{l(null)}};return(0,$.jsxs)(J,{elevation:F.ONE,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between mb-4`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(m,{size:20,className:`text-green-500`}),(0,$.jsx)(G,{style:{margin:0},children:n(`account.sessions.title`,`Active Sessions`)})]}),(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[_>0&&(0,$.jsx)(L,{small:!0,minimal:!0,intent:H.DANGER,icon:(0,$.jsx)(c,{size:14}),text:n(`account.sessions.revokeOthers`,`Revoke Other Sessions`),loading:u,onClick:()=>g(!0)}),(0,$.jsx)(L,{minimal:!0,icon:(0,$.jsx)(f,{size:14}),onClick:()=>v()})]})]}),a?(0,$.jsx)(`div`,{className:`flex justify-center py-4`,children:(0,$.jsx)(z,{size:24})}):r.length===0?(0,$.jsx)(`p`,{className:`text-sm text-gray-500 text-center py-4`,children:n(`account.sessions.empty`,`No active sessions found.`)}):(0,$.jsx)(`div`,{className:`overflow-x-auto`,children:(0,$.jsxs)(se,{interactive:!0,striped:!0,className:`w-full text-sm`,children:[(0,$.jsx)(`thead`,{children:(0,$.jsxs)(`tr`,{children:[(0,$.jsx)(`th`,{children:n(`account.sessions.device`,`Device`)}),(0,$.jsx)(`th`,{children:n(`account.sessions.session`,`Session`)}),(0,$.jsx)(`th`,{children:n(`account.sessions.ip`,`IP Address`)}),(0,$.jsx)(`th`,{children:n(`account.sessions.loginTime`,`Login Time`)}),(0,$.jsx)(`th`,{children:n(`account.sessions.expires`,`Expires`)}),(0,$.jsx)(`th`,{children:n(`account.sessions.action`,`Action`)})]})}),(0,$.jsx)(`tbody`,{children:r.map(r=>(0,$.jsxs)(`tr`,{onMouseEnter:()=>t?.(r.id),onMouseLeave:()=>t?.(null),className:e===r.id?`bg-gray-100/80 dark:bg-slate-800/80`:``,children:[(0,$.jsx)(`td`,{children:(0,$.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,$.jsx)(wt,{userAgent:r.user_agent}),r.is_current&&(0,$.jsx)(q,{minimal:!0,intent:H.SUCCESS,className:`mt-0.5`,children:n(`account.sessions.current`,`Current`)})]})}),(0,$.jsx)(`td`,{className:`font-mono text-xs text-gray-500 align-middle`,children:r.id?r.id.slice(0,8):`—`}),(0,$.jsx)(`td`,{className:`font-mono text-xs text-gray-500 align-middle`,children:r.ip_address||`—`}),(0,$.jsx)(`td`,{className:`text-xs text-gray-500 align-middle`,children:r.created_at?X(new Date(r.created_at*1e3)):`—`}),(0,$.jsx)(`td`,{className:`text-xs text-gray-500 align-middle`,children:X(new Date(r.expires_at*1e3))}),(0,$.jsx)(`td`,{className:`align-middle`,children:(0,$.jsx)(L,{small:!0,minimal:!0,intent:H.DANGER,disabled:r.is_current,icon:(0,$.jsx)(c,{size:14}),text:n(`account.sessions.revoke`,`Revoke`),loading:s===r.id,onClick:()=>y(r.id)})})]},r.id))})]})}),(0,$.jsx)(P,{isOpen:h,cancelButtonText:n(`common.cancel`,`Cancel`),confirmButtonText:n(`account.sessions.confirmRevokeOthers`,`Revoke Other Sessions`),intent:H.DANGER,icon:`log-out`,onCancel:()=>g(!1),onConfirm:async()=>{p(!0);try{await he(),i(e=>e.filter(e=>e.is_current)),g(!1)}catch(e){alert(e.message||n(`account.sessions.revokeFailed`,`Failed to revoke session.`))}finally{p(!1)}},loading:u,children:(0,$.jsx)(`p`,{children:n(`account.sessions.revokeOthersConfirmText`,`Are you sure you want to revoke all other active sessions? All other logged-in devices will be signed out immediately.`)})})]})},Dt=({users:e,currentUserId:t,onRefresh:r,registrationEnabled:a=!0,onRefreshSettings:o})=>{let{t:s}=d(),[c,l]=(0,Q.useState)(!1),[u,f]=(0,Q.useState)(``),[p,m]=(0,Q.useState)(``),[h,g]=(0,Q.useState)(`user`),[_,v]=(0,Q.useState)(!1),[y,b]=(0,Q.useState)(!1),[x,S]=(0,Q.useState)(a),[C,w]=(0,Q.useState)(!1);(0,Q.useEffect)(()=>{S(a)},[a]);let T=async e=>{S(e),w(!0);try{await ge({registration_enabled:String(e)}),o?.()}catch(t){console.error(t),S(!e),alert(t.message||s(`common.errorNetwork`,`Network error`))}finally{w(!1)}},D=async()=>{if(!Be.test(u)){alert(s(`account.formatTipUsername`));return}if(!Ue.test(p)){alert(s(`account.formatTipPassword`));return}v(!0);try{await De({username:u,password:await Ne(p,u),role:h}),l(!1),f(``),m(``),b(!1),r()}catch(e){console.error(e),alert(e.message||s(`common.errorNetwork`))}finally{v(!1)}},O=async e=>{if(confirm(s(`account.confirmDeleteUser`)))try{await pe(e),r()}catch(e){console.error(e)}};return(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`div`,{className:`flex flex-col sm:flex-row sm:items-center justify-between gap-3`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(n,{size:20,className:`text-red-500`}),(0,$.jsx)(G,{style:{margin:0},children:s(`account.userManagement`)})]}),(0,$.jsxs)(`div`,{className:`flex items-center gap-4 flex-wrap`,children:[(0,$.jsx)(ae,{label:s(`account.enableRegistration`,`开放新用户注册`),checked:x,disabled:C,onChange:e=>T(e.currentTarget.checked),className:`mb-0`}),(0,$.jsx)(L,{className:`whitespace-nowrap`,icon:(0,$.jsx)(E,{size:16}),intent:H.SUCCESS,text:s(`account.createUser`),onClick:()=>l(!0)})]})]}),(0,$.jsx)(J,{elevation:F.ONE,className:`p-0 overflow-hidden overflow-x-auto`,children:(0,$.jsxs)(se,{interactive:!0,striped:!0,className:`w-full`,children:[(0,$.jsx)(`thead`,{children:(0,$.jsxs)(`tr`,{children:[(0,$.jsx)(`th`,{children:s(`account.username`)}),(0,$.jsx)(`th`,{children:s(`account.role`)}),(0,$.jsx)(`th`,{children:`MFA`}),(0,$.jsx)(`th`,{children:`ID`}),(0,$.jsx)(`th`,{children:s(`account.createdAt`)}),(0,$.jsx)(`th`,{children:s(`account.lastActive`)}),(0,$.jsx)(`th`,{children:s(`account.lastResolve`)}),(0,$.jsx)(`th`,{className:`text-right`,children:s(`account.actions`)})]})}),(0,$.jsx)(`tbody`,{children:e.map(e=>(0,$.jsxs)(`tr`,{children:[(0,$.jsx)(`td`,{className:`font-bold`,children:e.username}),(0,$.jsx)(`td`,{children:(0,$.jsx)(q,{minimal:!0,intent:e.role===`admin`?H.DANGER:H.NONE,children:e.role===`admin`?s(`account.roleAdmin`):s(`account.roleUser`)})}),(0,$.jsx)(`td`,{children:(0,$.jsxs)(`div`,{className:`flex flex-wrap gap-1`,children:[!!e.totp_enabled&&(0,$.jsx)(q,{minimal:!0,intent:H.SUCCESS,children:`TOTP`}),!!(e.passkeys_count&&e.passkeys_count>0)&&(0,$.jsx)(q,{minimal:!0,intent:H.PRIMARY,children:`Passkey`}),!e.totp_enabled&&!(e.passkeys_count&&e.passkeys_count>0)&&(0,$.jsx)(q,{minimal:!0,intent:H.NONE,style:{color:`#8a9ba8`},children:s(`account.mfaNone`,`无`)})]})}),(0,$.jsx)(`td`,{children:(0,$.jsx)(`code`,{className:`text-xs`,children:e.id})}),(0,$.jsx)(`td`,{className:`text-xs text-gray-500`,children:e.created_at?X(new Date(e.created_at*1e3)):`-`}),(0,$.jsx)(`td`,{className:`text-xs text-gray-500`,children:e.last_active_at?X(new Date(e.last_active_at*1e3)):`-`}),(0,$.jsx)(`td`,{className:`text-xs text-gray-500`,children:e.last_resolve_at?X(new Date(e.last_resolve_at*1e3)):`-`}),(0,$.jsx)(`td`,{className:`text-right`,children:(0,$.jsx)(`div`,{className:`inline-flex items-center gap-1`,children:(0,$.jsx)(L,{minimal:!0,intent:H.DANGER,icon:(0,$.jsx)(i,{size:14}),disabled:e.id===t,onClick:()=>O(e.id)})})})]},e.id))})]})}),(0,$.jsx)(R,{isOpen:c,onClose:()=>{l(!1),b(!1)},title:s(`account.createNewUser`),icon:`user`,children:(0,$.jsxs)(`div`,{className:`p-6 space-y-4`,children:[(0,$.jsx)(K,{label:s(`account.username`),children:(0,$.jsx)(W,{value:u,onChange:e=>f(e.target.value),placeholder:s(`auth.usernamePlaceholder`)})}),(0,$.jsx)(K,{label:s(`account.initialPassword`),children:(0,$.jsx)(W,{type:y?`text`:`password`,value:p,onChange:e=>m(e.target.value),placeholder:s(`auth.passwordPlaceholder`),rightElement:(0,$.jsx)(L,{minimal:!0,icon:y?`eye-open`:`eye-off`,onClick:()=>b(!y),title:y?s(`auth.hidePassword`,`Hide password`):s(`auth.showPassword`,`Show password`)})})}),(0,$.jsx)(K,{label:s(`account.userRole`),children:(0,$.jsx)(ie,{fill:!0,value:h,onChange:e=>g(e.target.value),options:[{label:s(`account.roleUser`),value:`user`},{label:s(`account.roleAdmin`),value:`admin`}]})}),(0,$.jsxs)(`div`,{className:`flex justify-end gap-2 mt-6`,children:[(0,$.jsx)(L,{text:s(`account.cancel`),onClick:()=>l(!1)}),(0,$.jsx)(L,{intent:H.PRIMARY,text:s(`account.createNow`),loading:_,onClick:D})]})]})})]})},Ot=({initialSettings:e,onRefresh:t})=>{let{t:n}=d(),[r,i]=(0,Q.useState)(e),[a,o]=(0,Q.useState)(!1),[s,c]=(0,Q.useState)(!1);return(0,Q.useEffect)(()=>{i(e)},[e]),(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(l,{size:20,className:`text-gray-500`}),(0,$.jsx)(G,{style:{margin:0},children:n(`account.systemSettings`,`System Settings`)})]}),(0,$.jsxs)(J,{elevation:F.ONE,children:[(0,$.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-x-8 gap-y-4`,children:[(0,$.jsxs)(`div`,{className:`space-y-4`,children:[(0,$.jsx)(G,{className:`text-sm font-bold opacity-70 text-blue-500`,children:`Cloudflare Turnstile`}),(0,$.jsx)(K,{label:`Site Key`,children:(0,$.jsx)(W,{value:r.turnstile_site_key||``,onChange:e=>i({...r,turnstile_site_key:e.target.value}),placeholder:`0x000...`})}),(0,$.jsx)(K,{label:`Secret Key`,children:(0,$.jsx)(W,{type:s?`text`:`password`,value:r.turnstile_secret_key||``,onChange:e=>i({...r,turnstile_secret_key:e.target.value}),placeholder:`0x000...`,rightElement:(0,$.jsx)(L,{minimal:!0,icon:s?`eye-open`:`eye-off`,onClick:()=>c(!s),title:s?n(`auth.hidePassword`,`Hide password`):n(`auth.showPassword`,`Show password`)})})})]}),(0,$.jsxs)(`div`,{className:`space-y-4`,children:[(0,$.jsx)(G,{className:`text-sm font-bold opacity-70 text-green-500`,children:n(`account.featureToggle`,`Feature Toggle`)}),(0,$.jsx)(ae,{label:n(`account.enableTurnstileSignup`,`Enable verification on Signup`),checked:r.turnstile_enabled_signup===`true`,onChange:e=>i({...r,turnstile_enabled_signup:String(e.currentTarget.checked)})}),(0,$.jsx)(ae,{label:n(`account.enableTurnstileLogin`,`Enable verification on Login`),checked:r.turnstile_enabled_login===`true`,onChange:e=>i({...r,turnstile_enabled_login:String(e.currentTarget.checked)})})]})]}),(0,$.jsx)(U,{className:`my-4`}),(0,$.jsx)(`div`,{className:`flex justify-end`,children:(0,$.jsx)(L,{intent:H.PRIMARY,icon:`floppy-disk`,text:n(`common.save`,`Save`),loading:a,onClick:async()=>{o(!0);try{await ge({turnstile_site_key:r.turnstile_site_key||``,turnstile_secret_key:r.turnstile_secret_key||``,turnstile_enabled_signup:r.turnstile_enabled_signup||`false`,turnstile_enabled_login:r.turnstile_enabled_login||`false`}),alert(n(`common.saveSuccess`,`Settings saved`)),t()}catch(e){console.error(e)}finally{o(!1)}}})})]})]})},kt=({isAdmin:e,onLogsCleared:t})=>{let{t:n}=d(),[r,a]=(0,Q.useState)(!1);return(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(G,{className:`text-red-500 flex items-center gap-2`,children:[(0,$.jsx)(i,{size:20}),` `,n(`account.dangerZone`)]}),(0,$.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-6`,children:[(0,$.jsxs)(J,{elevation:F.ONE,className:`flex flex-col justify-between`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(G,{children:n(`account.clearLogs`)}),(0,$.jsx)(`p`,{className:`text-xs opacity-60 mb-3`,children:n(`account.clearLogsDesc`)})]}),(0,$.jsx)(L,{fill:!0,intent:H.DANGER,text:n(`account.clearLogsBtn`),icon:`trash`,loading:r,onClick:async()=>{if(confirm(n(`account.confirmClearLogs`))){a(!0);try{await Ge(),alert(n(`account.clearLogsSuccess`)),t?.()}catch(e){console.error(e)}finally{a(!1)}}}})]}),!e&&(0,$.jsxs)(J,{elevation:F.ONE,className:`flex flex-col justify-between`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(G,{children:n(`account.deleteAccount`)}),(0,$.jsx)(`p`,{className:`text-xs opacity-60 mb-4`,children:n(`account.deleteAccountDesc`)})]}),(0,$.jsx)(L,{fill:!0,intent:H.DANGER,text:n(`account.deleteAccountBtn`),icon:`delete`,onClick:async()=>{if(confirm(n(`account.confirmDeleteAccount`)))try{await Fe(),window.location.href=`/`}catch(e){console.error(e),alert(e.message||n(`common.errorNetwork`))}}})]})]}),(0,$.jsx)(V,{intent:H.WARNING,icon:`info-sign`,title:n(`account.inactivityPolicy`),children:(0,$.jsx)(`p`,{className:`text-sm`,children:n(`account.inactivityDesc`)})})]})},At=[{label:ee(`account.timezoneAuto`,`Auto (Browser Default)`),value:``},{label:`Pacific/Midway (Midway Island) (Standard: UTC-11)`,value:`Pacific/Midway`},{label:`Pacific/Honolulu (Honolulu, Hawaii) (Standard: UTC-10)`,value:`Pacific/Honolulu`},{label:`America/Anchorage (Anchorage, Alaska) (Standard: UTC-9 / DST: UTC-8)`,value:`America/Anchorage`},{label:`America/Los_Angeles (Pacific Time) (Standard: UTC-8 / DST: UTC-7)`,value:`America/Los_Angeles`},{label:`America/Denver (Mountain Time) (Standard: UTC-7 / DST: UTC-6)`,value:`America/Denver`},{label:`America/Chicago (Central Time) (Standard: UTC-6 / DST: UTC-5)`,value:`America/Chicago`},{label:`America/New_York (Eastern Time) (Standard: UTC-5 / DST: UTC-4)`,value:`America/New_York`},{label:`America/Halifax (Atlantic Time) (Standard: UTC-4 / DST: UTC-3)`,value:`America/Halifax`},{label:`America/Argentina/Buenos_Aires (Buenos Aires) (Standard: UTC-3)`,value:`America/Argentina/Buenos_Aires`},{label:`America/Noronha (Fernando de Noronha) (Standard: UTC-2)`,value:`America/Noronha`},{label:`Atlantic/Azores (Azores) (Standard: UTC-1 / DST: UTC+0)`,value:`Atlantic/Azores`},{label:`UTC (Coordinated Universal Time) (Standard: UTC+0)`,value:`UTC`},{label:`Europe/London (London) (Standard: UTC+0 / DST: UTC+1)`,value:`Europe/London`},{label:`Europe/Paris (Paris, Berlin, Rome) (Standard: UTC+1 / DST: UTC+2)`,value:`Europe/Paris`},{label:`Europe/Kyiv (Kyiv, Helsinki, Cairo) (Standard: UTC+2 / DST: UTC+3)`,value:`Europe/Kyiv`},{label:`Europe/Moscow (Moscow) (Standard: UTC+3)`,value:`Europe/Moscow`},{label:`Asia/Dubai (Dubai, Baku) (Standard: UTC+4)`,value:`Asia/Dubai`},{label:`Asia/Karachi (Karachi, Tashkent) (Standard: UTC+5)`,value:`Asia/Karachi`},{label:`Asia/Dhaka (Dhaka, Almaty) (Standard: UTC+6)`,value:`Asia/Dhaka`},{label:`Asia/Bangkok (Bangkok, Jakarta) (Standard: UTC+7)`,value:`Asia/Bangkok`},{label:`Asia/Singapore (Beijing, Shanghai, Singapore, Taipei) (Standard: UTC+8)`,value:`Asia/Singapore`},{label:`Asia/Tokyo (Tokyo, Seoul) (Standard: UTC+9)`,value:`Asia/Tokyo`},{label:`Australia/Sydney (Sydney, Melbourne) (Standard: UTC+10 / DST: UTC+11)`,value:`Australia/Sydney`},{label:`Pacific/Noumea (Nouméa) (Standard: UTC+11)`,value:`Pacific/Noumea`},{label:`Pacific/Auckland (Auckland, Suva) (Standard: UTC+12 / DST: UTC+13)`,value:`Pacific/Auckland`}],jt=({me:e,isEditingUsername:t,setIsEditingUsername:n,editUsername:i,setEditUsername:a,usernameLoading:o,usernameFocused:s,setUsernameFocused:c,onUpdateUsername:l,onUpdateTimezone:u})=>{let{t:f}=d();return(0,$.jsxs)(J,{elevation:F.ONE,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2 mb-4`,children:[(0,$.jsx)(_,{size:20,className:`text-blue-500`}),(0,$.jsx)(G,{style:{margin:0},children:f(`account.personalInfo`)})]}),(0,$.jsxs)(`div`,{className:`space-y-4`,children:[(0,$.jsx)(K,{label:f(`account.username`),children:(0,$.jsx)(`div`,{className:`flex gap-2`,children:t?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(ce,{content:f(`account.formatTipUsername`),isOpen:s,position:M.TOP,intent:H.PRIMARY,className:`w-full`,children:(0,$.jsx)(`div`,{className:`w-full block`,children:(0,$.jsx)(W,{fill:!0,value:i,onChange:e=>a(e.target.value),onFocus:()=>c(!0),onBlur:()=>c(!1),autoFocus:!0})})}),(0,$.jsxs)(N,{children:[(0,$.jsx)(L,{icon:(0,$.jsx)(y,{size:16}),intent:H.SUCCESS,loading:o,onClick:l}),(0,$.jsx)(L,{icon:(0,$.jsx)(D,{size:16}),onClick:()=>{n(!1),a(e?.username||``)}})]})]}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(W,{fill:!0,value:e?.username,readOnly:!0}),(0,$.jsx)(L,{icon:(0,$.jsx)(r,{size:16}),onClick:()=>n(!0)})]})})}),(0,$.jsx)(K,{label:f(`account.userId`),children:(0,$.jsx)(W,{leftIcon:`id-number`,value:e?.id,disabled:!0})}),(0,$.jsx)(K,{label:f(`account.timezone`,`Timezone`),children:(0,$.jsx)(ie,{fill:!0,value:e?.timezone||``,onChange:e=>u?.(e.target.value||null),options:At})})]})]})},Mt=({me:e,onRefresh:t})=>{let{t:r}=d(),i=!!(e?.passkeys_count&&e.passkeys_count>0),a=!!e?.totp_enabled,[o,s]=(0,Q.useState)(`password`),[c,l]=(0,Q.useState)(``),[f,p]=(0,Q.useState)(!1),[m,g]=(0,Q.useState)(``),[_,v]=(0,Q.useState)(``),[y,b]=(0,Q.useState)(!1),[x,S]=(0,Q.useState)(!1),[C,w]=(0,Q.useState)(!1),[T,E]=(0,Q.useState)(null);return(0,Q.useEffect)(()=>{o===`passkey`&&!i?s(a?`totp`:`password`):o===`totp`&&!a&&s(i?`passkey`:`password`)},[i,a,o]),(0,$.jsxs)(J,{elevation:F.ONE,className:`isolate`,style:{isolation:`isolate`},children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2 mb-4`,children:[(0,$.jsx)(u,{size:20,className:`text-orange-500`}),(0,$.jsx)(G,{style:{margin:0},children:r(`account.changePassword`,`Change Password`)})]}),(i||a)&&(0,$.jsx)(`div`,{className:`mb-4 isolate`,style:{isolation:`isolate`},children:(0,$.jsx)(`div`,{className:`w-full bg-gray-100/70 dark:bg-gray-800/70 p-1 rounded-lg`,children:(0,$.jsxs)(N,{fill:!0,variant:`minimal`,style:{isolation:`isolate`},children:[(0,$.jsx)(L,{small:!0,active:o===`password`,intent:o===`password`?H.PRIMARY:H.NONE,icon:(0,$.jsx)(h,{size:14}),text:r(`account.mfa.password`,`Password`),onClick:()=>{s(`password`),E(null)}}),i&&(0,$.jsx)(L,{small:!0,active:o===`passkey`,intent:o===`passkey`?H.PRIMARY:H.NONE,icon:(0,$.jsx)(u,{size:14}),text:r(`account.mfa.passkey`,`Passkey`),onClick:()=>{s(`passkey`),E(null)}}),a&&(0,$.jsx)(L,{small:!0,active:o===`totp`,intent:o===`totp`?H.PRIMARY:H.NONE,icon:(0,$.jsx)(n,{size:14}),text:r(`account.mfa.totp`,`TOTP`),onClick:()=>{s(`totp`),E(null)}})]})})}),T&&(0,$.jsx)(V,{intent:T.intent,className:`mb-4`,children:T.text}),(0,$.jsxs)(`form`,{onSubmit:async n=>{if(n.preventDefault(),!Ue.test(_)){E({text:r(`account.formatTipPassword`,`Password must be 12-100 characters and contain letters, numbers, and symbols.`),intent:H.DANGER});return}if(!e?.username){E({text:r(`auth.sessionExpired`,`Session expired. Please log in again.`),intent:H.DANGER});return}w(!0),E(null);try{let n=await Ne(_,e.username);if(o===`passkey`)await ye({passkeyAssertion:await fe(await Qe()),newPassword:n});else if(o===`totp`){if(m.length!==6){E({text:r(`account.totp.invalidCode`,`Please enter a 6-digit code`),intent:H.DANGER}),w(!1);return}let e=crypto.randomUUID(),t=new TextEncoder().encode(m+e),i=await crypto.subtle.digest(`SHA-256`,t);await ye({totpTokenHash:Array.from(new Uint8Array(i)).map(e=>e.toString(16).padStart(2,`0`)).join(``),totpSalt:e,newPassword:n})}else{if(!c){E({text:r(`auth.passwordRequired`,`Current password is required`),intent:H.DANGER}),w(!1);return}let t=c;(e.password_version??1)===2&&(t=await Ne(c,e.username)),await ye({oldPassword:t,newPassword:n})}E({text:r(`account.passwordSuccess`,`Password updated successfully!`),intent:H.SUCCESS}),l(``),g(``),v(``),t&&t()}catch(e){E({text:Je(e,r),intent:H.DANGER})}finally{w(!1)}},className:`space-y-4`,children:[o===`password`&&(0,$.jsx)(K,{label:r(`account.currentPassword`,`Current Password`),children:(0,$.jsx)(W,{leftIcon:`lock`,type:f?`text`:`password`,value:c,onChange:e=>l(e.target.value),rightElement:(0,$.jsx)(L,{minimal:!0,icon:f?`eye-open`:`eye-off`,onClick:()=>p(!f),title:r(f?`auth.hidePassword`:`auth.showPassword`)}),required:!0})}),o===`totp`&&(0,$.jsx)(K,{label:r(`account.totpCode`,`Authenticator Code`),children:(0,$.jsx)(Le,{length:6,value:m,onChange:g,disabled:C})}),o===`passkey`&&(0,$.jsx)(V,{intent:H.PRIMARY,children:(0,$.jsx)(`span`,{className:`text-xs`,children:r(`account.passkey.changePwNotice`,`You will be prompted to verify via biometric authentication or your security key when submitting.`)})}),(0,$.jsx)(K,{label:r(`account.newPassword`,`New Password`),children:(0,$.jsx)(ce,{content:r(`account.formatTipPassword`,`Password must be 12-100 characters and contain letters, numbers, and symbols.`),isOpen:x,position:M.TOP,intent:H.PRIMARY,className:`w-full`,children:(0,$.jsx)(`div`,{className:`w-full block`,children:(0,$.jsx)(W,{leftIcon:`lock`,type:y?`text`:`password`,value:_,onChange:e=>v(e.target.value),onFocus:()=>S(!0),onBlur:()=>S(!1),rightElement:(0,$.jsx)(L,{minimal:!0,icon:y?`eye-open`:`eye-off`,onClick:()=>b(!y),title:r(y?`auth.hidePassword`:`auth.showPassword`)}),required:!0})})})}),(0,$.jsx)(L,{fill:!0,intent:o===`passkey`?H.PRIMARY:H.WARNING,type:`submit`,loading:C,icon:o===`passkey`?(0,$.jsx)(u,{size:16}):void 0,text:o===`passkey`?r(`account.changePasswordWithPasskey`,`Verify with Passkey & Update`):r(`account.updatePassword`,`Update Password`)})]})]})},Nt=({isOpen:e,onClose:t,user:r,onSuccess:i})=>{let{t:a}=d(),o=!!(r?.passkeys_count&&r.passkeys_count>0),s=!!r?.totp_enabled,[c,l]=(0,Q.useState)(`password`),[f,p]=(0,Q.useState)(``),[m,g]=(0,Q.useState)(``),[_,v]=(0,Q.useState)(``),[y,b]=(0,Q.useState)(!1),[x,S]=(0,Q.useState)(``),[C,w]=(0,Q.useState)(!1),[T,E]=(0,Q.useState)(``),D=(0,Q.useRef)(null),O=(0,Q.useRef)(null);(0,Q.useEffect)(()=>{c===`passkey`&&!o?l(s?`totp`:`password`):c===`totp`&&!s&&l(o?`passkey`:`password`)},[o,s,c]);let k=async(e,t)=>{if(e&&e.preventDefault(),f.length!==4||!qe.test(f)){E(a(`auth.pinFormatTip`,`PIN must be exactly 4 digits`));return}if(f!==m){E(a(`auth.pinMatchTip`,`PINs do not match`));return}w(!0),E(``);try{let e=r?.id||sessionStorage.getItem(`dns_worker_user_id`);if(!e){E(a(`auth.sessionExpired`,`Session expired. Logging out...`)),setTimeout(()=>{A()},1500);return}let n=await Pe(f,e),o={};if(c===`passkey`)o.passkeyAssertion=await fe(await Qe());else if(c===`totp`){let e=(t||x).replace(/\s/g,``);if(e.length!==6){E(a(`account.totp.invalidCode`,`Please enter a 6-digit code`)),w(!1);return}let n=crypto.randomUUID();o.totpTokenHash=await We(e,n),o.totpSalt=n}else{if(!_){E(a(`auth.passwordRequired`,`Password is required for verification`)),w(!1);return}let e=_;r?.password_version===2&&r?.username&&(e=await Ne(_,r.username)),o.password=e}await de(n,o),p(``),g(``),v(``),S(``),i()}catch(e){E(Je(e,a))}finally{w(!1)}},A=()=>{E(``),p(``),g(``),v(``),b(!1),S(``),l(`password`),t()};return(0,$.jsx)(R,{isOpen:e,onClose:A,title:r?.pin_enabled?a(`auth.changePin`,`Change PIN`):a(`auth.configurePin`,`Configure PIN`),icon:`key`,className:`pb-0`,style:{width:`420px`},children:(0,$.jsxs)(`form`,{onSubmit:k,children:[(0,$.jsxs)(`div`,{className:I,children:[T&&(0,$.jsx)(V,{intent:H.DANGER,className:`mb-4`,children:T}),(0,$.jsx)(K,{label:a(`auth.newPin`,`New 4-Digit PIN`),labelFor:`new-pin-input`,helperText:a(`auth.pinHelper`,`Digits only, e.g., 1234`),children:(0,$.jsx)(Le,{length:4,value:f,onChange:p,type:`password`,disabled:C,autoFocus:!0,onComplete:()=>D.current?.focus()})}),(0,$.jsx)(K,{label:a(`auth.confirmPin`,`Confirm New PIN`),labelFor:`confirm-pin-input`,children:(0,$.jsx)(Le,{ref:D,length:4,value:m,onChange:g,type:`password`,disabled:C,onComplete:()=>{c===`totp`?O.current?.focus():c===`password`&&document.getElementById(`verify-pw-input`)?.focus()}})}),(0,$.jsx)(U,{className:`my-4`}),(0,$.jsxs)(`div`,{className:`mb-3 space-y-2`,children:[(0,$.jsx)(`span`,{className:`font-semibold text-sm block`,children:a(`auth.verifyIdentity`,`Verify Identity`)}),(o||s)&&(0,$.jsx)(`div`,{className:`w-full bg-gray-100/70 dark:bg-gray-800/70 p-1 rounded-lg isolate`,style:{isolation:`isolate`},children:(0,$.jsxs)(N,{fill:!0,variant:`minimal`,style:{isolation:`isolate`},children:[(0,$.jsx)(L,{small:!0,active:c===`password`,intent:c===`password`?H.PRIMARY:H.NONE,icon:(0,$.jsx)(h,{size:14}),text:a(`account.mfa.password`,`Password`),onClick:()=>{l(`password`),E(``)}}),o&&(0,$.jsx)(L,{small:!0,active:c===`passkey`,intent:c===`passkey`?H.PRIMARY:H.NONE,icon:(0,$.jsx)(u,{size:14}),text:a(`account.mfa.passkey`,`Passkey`),onClick:()=>{l(`passkey`),E(``)}}),s&&(0,$.jsx)(L,{small:!0,active:c===`totp`,intent:c===`totp`?H.PRIMARY:H.NONE,icon:(0,$.jsx)(n,{size:14}),text:a(`account.mfa.totp`,`TOTP`),onClick:()=>{l(`totp`),E(``)}})]})})]}),c===`password`&&(0,$.jsx)(K,{label:a(`auth.currentPassword`,`Current Password`),labelFor:`verify-pw-input`,children:(0,$.jsx)(W,{id:`verify-pw-input`,type:y?`text`:`password`,placeholder:a(`auth.passwordPlaceholder`,`Enter current password`),value:_,onChange:e=>v(e.target.value),leftIcon:`lock`,rightElement:(0,$.jsx)(L,{minimal:!0,icon:y?`eye-open`:`eye-off`,onClick:()=>b(!y),title:y?a(`auth.hidePassword`,`Hide password`):a(`auth.showPassword`,`Show password`)}),required:!0})}),c===`totp`&&(0,$.jsx)(K,{label:a(`auth.totpCode`,`TOTP Code`),labelFor:`verify-totp-input`,children:(0,$.jsx)(Le,{ref:O,length:6,value:x,onChange:S,disabled:C,onComplete:e=>k(void 0,e),autoFocus:!0})}),c===`passkey`&&(0,$.jsx)(V,{intent:H.PRIMARY,icon:(0,$.jsx)(u,{size:16}),children:(0,$.jsx)(`span`,{className:`text-xs`,children:a(`account.passkey.submitNotice`,a(`account.passkey.changePwNotice`,`You will be prompted to verify via biometric authentication or your security key when submitting.`))})})]}),(0,$.jsx)(`div`,{className:B,children:(0,$.jsxs)(`div`,{className:Y,children:[(0,$.jsx)(L,{onClick:A,children:a(`common.cancel`,`Cancel`)}),(0,$.jsx)(L,{type:`submit`,intent:H.PRIMARY,loading:C,children:a(`common.save`,`Save`)})]})})]})})},Pt=({isOpen:e,onClose:t,user:r,onSuccess:i})=>{let{t:a}=d(),o=!!(r?.passkeys_count&&r.passkeys_count>0),s=!!r?.totp_enabled,[c,l]=(0,Q.useState)(`password`),[f,p]=(0,Q.useState)(``),[m,g]=(0,Q.useState)(!1),[_,v]=(0,Q.useState)(``),[y,b]=(0,Q.useState)(!1),[x,C]=(0,Q.useState)(``);(0,Q.useEffect)(()=>{c===`passkey`&&!o?l(s?`totp`:`password`):c===`totp`&&!s&&l(o?`passkey`:`password`)},[o,s,c]);let w=async(e,t)=>{e&&e.preventDefault(),b(!0),C(``);try{let e={};if(c===`passkey`)e.passkeyAssertion=await fe(await Qe());else if(c===`totp`){let n=(t||_).replace(/\s/g,``);if(n.length!==6){C(a(`account.totp.invalidCode`,`Please enter a 6-digit code`)),b(!1);return}let r=crypto.randomUUID();e.totpTokenHash=await We(n,r),e.totpSalt=r}else{if(!f){C(a(`auth.passwordRequired`,`Password is required for verification`)),b(!1);return}let t=f;r?.password_version===2&&r?.username&&(t=await Ne(f,r.username)),e.password=t}await He(e),p(``),v(``),i()}catch(e){C(Je(e,a))}finally{b(!1)}},T=()=>{C(``),p(``),g(!1),v(``),l(`password`),t()};return(0,$.jsx)(R,{isOpen:e,onClose:T,title:a(`auth.disablePin`,`Disable Session Lock`),icon:`trash`,className:`pb-0`,style:{width:`420px`},children:(0,$.jsxs)(`form`,{onSubmit:w,children:[(0,$.jsxs)(`div`,{className:I,children:[x&&(0,$.jsx)(V,{intent:H.DANGER,className:`mb-4`,children:x}),(0,$.jsx)(V,{intent:H.WARNING,className:`mb-4`,icon:(0,$.jsx)(S,{size:20}),children:a(`auth.disablePinWarning`,`Disabling the PIN will disable the inactivity session locking feature completely.`)}),(0,$.jsxs)(`div`,{className:`mb-3 space-y-2`,children:[(0,$.jsx)(`span`,{className:`font-semibold text-sm block`,children:a(`auth.verifyIdentity`,`Verify Identity`)}),(o||s)&&(0,$.jsx)(`div`,{className:`w-full bg-gray-100/70 dark:bg-gray-800/70 p-1 rounded-lg isolate`,style:{isolation:`isolate`},children:(0,$.jsxs)(N,{fill:!0,variant:`minimal`,style:{isolation:`isolate`},children:[(0,$.jsx)(L,{small:!0,active:c===`password`,intent:c===`password`?H.PRIMARY:H.NONE,icon:(0,$.jsx)(h,{size:14}),text:a(`account.mfa.password`,`Password`),onClick:()=>{l(`password`),C(``)}}),o&&(0,$.jsx)(L,{small:!0,active:c===`passkey`,intent:c===`passkey`?H.PRIMARY:H.NONE,icon:(0,$.jsx)(u,{size:14}),text:a(`account.mfa.passkey`,`Passkey`),onClick:()=>{l(`passkey`),C(``)}}),s&&(0,$.jsx)(L,{small:!0,active:c===`totp`,intent:c===`totp`?H.PRIMARY:H.NONE,icon:(0,$.jsx)(n,{size:14}),text:a(`account.mfa.totp`,`TOTP`),onClick:()=>{l(`totp`),C(``)}})]})})]}),c===`password`&&(0,$.jsx)(K,{label:a(`auth.currentPassword`,`Current Password`),labelFor:`disable-pw-input`,children:(0,$.jsx)(W,{id:`disable-pw-input`,type:m?`text`:`password`,placeholder:a(`auth.passwordPlaceholder`,`Enter current password`),value:f,onChange:e=>p(e.target.value),leftIcon:`lock`,rightElement:(0,$.jsx)(L,{minimal:!0,icon:m?`eye-open`:`eye-off`,onClick:()=>g(!m),title:m?a(`auth.hidePassword`,`Hide password`):a(`auth.showPassword`,`Show password`)}),required:!0})}),c===`totp`&&(0,$.jsx)(K,{label:a(`auth.totpCode`,`TOTP Code`),labelFor:`disable-totp-input`,children:(0,$.jsx)(Le,{length:6,value:_,onChange:v,disabled:y,onComplete:e=>w(void 0,e),autoFocus:!0})}),c===`passkey`&&(0,$.jsx)(V,{intent:H.PRIMARY,icon:(0,$.jsx)(u,{size:16}),children:(0,$.jsx)(`span`,{className:`text-xs`,children:a(`account.passkey.submitNotice`,a(`account.passkey.changePwNotice`,`You will be prompted to verify via biometric authentication or your security key when submitting.`))})})]}),(0,$.jsx)(`div`,{className:B,children:(0,$.jsxs)(`div`,{className:Y,children:[(0,$.jsx)(L,{onClick:T,children:a(`common.cancel`,`Cancel`)}),(0,$.jsx)(L,{type:`submit`,intent:H.DANGER,loading:y,children:a(`common.disable`,`Disable`)})]})})]})})},Ft=({user:e,onRefresh:t})=>{let{t:r}=d(),[i,a]=(0,Q.useState)(!1),[o,s]=(0,Q.useState)(!1),[c,l]=(0,Q.useState)(!1),u=!!e?.pin_enabled,f=e?.session_lock_timeout||15,p=async e=>{let n=Number(e.currentTarget.value);a(!0);try{await Te({session_lock_timeout:n}),t()}catch(e){console.error(`Failed to change session lock timeout`,e)}finally{a(!1)}},m=()=>{s(!0)};return(0,$.jsxs)(J,{elevation:F.ONE,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between mb-4`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(n,{size:20,className:`text-indigo-600`}),(0,$.jsx)(G,{className:`m-0!`,children:r(`auth.sessionLockTitle`,`Idle Session Lock`)})]}),!u&&(0,$.jsx)(L,{icon:`key`,intent:H.PRIMARY,onClick:m,disabled:i,children:r(`auth.configurePin`,`Configure 4-Digit PIN`)})]}),(0,$.jsx)(`p`,{className:`text-gray-500 text-sm mb-4`,children:r(`auth.sessionLockDesc`,`Lock the interface with a 4-digit PIN when the application is idle to protect active sessions from unauthorized physical access.`)}),(0,$.jsx)(`div`,{className:`flex flex-col gap-4 mb-4`,children:(0,$.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,$.jsx)(`span`,{children:r(`auth.inactivityTimeout`,`Inactivity Timeout`)}),(0,$.jsx)(ie,{value:f,onChange:p,disabled:!u||i,options:[{label:r(`auth.timeout1m`,`1 Minute`),value:1},{label:r(`auth.timeout2m`,`2 Minutes`),value:2},{label:r(`auth.timeout5m`,`5 Minutes`),value:5},{label:r(`auth.timeout15m`,`15 Minutes`),value:15},{label:r(`auth.timeout30m`,`30 Minutes`),value:30},{label:r(`auth.timeout60m`,`60 Minutes`),value:60}]})]})}),u&&(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3`,children:[(0,$.jsx)(L,{icon:`edit`,onClick:m,disabled:i,children:r(`auth.changePin`,`Change PIN`)}),(0,$.jsx)(L,{icon:`trash`,intent:H.DANGER,onClick:()=>{l(!0)},disabled:i,children:r(`auth.disablePin`,`Disable PIN & Lock`)}),(0,$.jsx)(L,{icon:`lock`,intent:H.WARNING,onClick:async()=>{a(!0);try{await be(),window.dispatchEvent(new Event(`session_paused`))}catch(e){console.error(`Failed to lock session immediately`,e)}finally{a(!1)}},disabled:i,children:r(`auth.lockNow`,`Lock Now`)})]}),(0,$.jsx)(Nt,{isOpen:o,onClose:()=>s(!1),user:e,onSuccess:()=>{s(!1),t()}}),(0,$.jsx)(Pt,{isOpen:c,onClose:()=>l(!1),user:e,onSuccess:()=>{l(!1),t()}})]})};function It({user:e,onRefresh:t,toasterRef:n,setProcessing:r}){let{t:i}=d(),[a,o]=(0,Q.useState)(null),[s,c]=(0,Q.useState)(!0),[l,u]=(0,Q.useState)(!1),[f,p]=(0,Q.useState)(!1),m=(0,Q.useCallback)(async()=>{c(!0);try{o(await Z.getUserStatus()),u(Z.isUnlocked())}catch(e){console.error(`[useE2eeStatus] Failed to fetch E2EE status:`,e)}finally{c(!1)}},[]);(0,Q.useEffect)(()=>{m()},[m]);let h=e.passkeys_count&&e.passkeys_count>0||(a?.userPasskeyCount||0)>0,g=!!a?.enabled;return{status:a,loading:s,isUnlocked:l,setIsUnlocked:u,isPqc:(0,Q.useMemo)(()=>{if(!a?.publicKey)return!1;try{let e=JSON.parse(a.publicKey);return e.alg===`P256-MLKEM768`||!!e.pqc_pk}catch{return!1}},[a?.publicKey]),isLogsE2eeEnabled:g,hasPasskey:h,loadStatus:m,isDisableAlertOpen:f,setIsDisableAlertOpen:p,handleToggleLogs:async e=>{if(e){r(!0);try{await Z.enableUserE2ee(),n.current?.show({message:i(`account.e2ee.enableSuccess`),intent:H.SUCCESS,icon:`lock`}),await m(),t?.()}catch(e){console.error(`[useE2eeStatus] Failed to enable E2EE:`,e),n.current?.show({message:e.message||i(`account.e2ee.enableError`),intent:H.DANGER,icon:`error`})}finally{r(!1)}}else p(!0)},handleConfirmDisable:async()=>{r(!0);try{await Z.disableUserE2ee(),n.current?.show({message:i(`account.e2ee.disableSuccess`),intent:H.WARNING,icon:`unlock`}),await m(),t?.()}catch(e){console.error(`[useE2eeStatus] Failed to disable E2EE:`,e),n.current?.show({message:e.message||i(`account.e2ee.disableError`),intent:H.DANGER,icon:`error`})}finally{r(!1),p(!1)}},handleLockDevice:()=>{Z.clearStorage(),u(!1),n.current?.show({message:i(`account.e2ee.lockSuccess`,`已锁定,私钥已从本地清除`),intent:H.NONE})}}}function Lt({onRefresh:e,loadStatus:t,setIsUnlocked:n,toasterRef:r,setProcessing:i}){let{t:a}=d(),[o,s]=(0,Q.useState)(!1),[c,l]=(0,Q.useState)(``),[u,f]=(0,Q.useState)(``),[p,m]=(0,Q.useState)(!1),[h,g]=(0,Q.useState)(``),[_,v]=(0,Q.useState)(``),[y,b]=(0,Q.useState)(null),[x,S]=(0,Q.useState)(!1);return{isRecoveryDialogOpen:o,setIsRecoveryDialogOpen:s,recoveryKeyInput:c,setRecoveryKeyInput:l,recoveryUnlockError:u,setRecoveryUnlockError:f,initRecoveryDialogOpen:p,setInitRecoveryDialogOpen:m,initRecoveryKeyInput:h,setInitRecoveryKeyInput:g,initRecoveryError:_,setInitRecoveryError:v,rotatedKey:y,setRotatedKey:b,copiedKey:x,handleUnlockWithRecoveryKey:async o=>{o.preventDefault();let u=c.trim();if(u){i(!0),f(``);try{await Z.unlockWithRecoveryKey(u);try{let e=await ze({recoveryKey:u});await Z.wrapCurrentKeyForRecovery(e.recovery_key),b(e.recovery_key)}catch(e){console.warn(`[useE2eeRecoveryDialogs] Recovery key auto-rotation failed:`,e)}n(!0),s(!1),l(``),r.current?.show({message:a(`account.e2ee.unlockSuccess`),intent:H.SUCCESS,icon:`tick`}),await t(),e?.()}catch(e){console.error(`[useE2eeRecoveryDialogs] Recovery unlock failed:`,e),f(e.message||a(`account.e2ee.recoveryUnlockFailed`))}finally{i(!1)}}},handleInitWithRecoveryKey:async o=>{o.preventDefault();let s=h.trim();if(s){i(!0),v(``);try{await Z.initUserE2eeWithRecoveryKey(s);try{let e=await ze({recoveryKey:s});await Z.wrapCurrentKeyForRecovery(e.recovery_key),b(e.recovery_key)}catch(e){console.warn(`[useE2eeRecoveryDialogs] Recovery key auto-rotation failed:`,e)}m(!1),g(``),n(!0),r.current?.show({message:a(`account.e2ee.keypairGenSuccess`),intent:H.SUCCESS,icon:`tick`}),await t(),e?.()}catch(e){console.error(`[useE2eeRecoveryDialogs] Init keypair with recovery key failed:`,e),v(e.message||a(`account.e2ee.initFailed`))}finally{i(!1)}}},handleCopyRotatedKey:e=>{navigator.clipboard.writeText(e),S(!0),setTimeout(()=>S(!1),2e3)}}}function Rt({hasPasskey:e,onRefresh:t,loadStatus:n,setIsUnlocked:r,setInitRecoveryDialogOpen:i,toasterRef:a,setProcessing:o}){let{t:s}=d(),[c,l]=(0,Q.useState)(!1);return{handleUnlock:async()=>{o(!0);try{await Z.unlockUser()&&(r(!0),a.current?.show({message:s(`account.e2ee.unlockSuccess`),intent:H.SUCCESS,icon:`tick`}))}catch(e){console.error(`[useE2eeActions] Failed to unlock private key:`,e),a.current?.show({message:e.message||s(`account.e2ee.unlockError`),intent:H.DANGER,icon:`error`})}finally{o(!1)}},handleGenerateKeyWithPasskey:async()=>{o(!0);try{await Z.enableUserE2ee(),a.current?.show({message:s(`account.e2ee.keypairGenSuccess`),intent:H.SUCCESS,icon:`tick`}),await n(),t?.()}catch(e){console.error(`[useE2eeActions] Generate key with Passkey failed:`,e),a.current?.show({message:e.message||s(`account.e2ee.keypairGenError`),intent:H.DANGER,icon:`error`})}finally{o(!1)}},handleUpgradeToPqc:async()=>{o(!0);try{await Z.rotateUserE2eeKey(),a.current?.show({message:s(`account.e2ee.upgradePqcSuccess`,`已成功升级到后量子混合加密 (P256-MLKEM768)`),intent:H.SUCCESS,icon:`tick`}),await n(),t?.()}catch(e){console.error(`[useE2eeActions] Upgrade to PQC failed:`,e),a.current?.show({message:e.message||s(`account.e2ee.upgradePqcError`,`升级到后量子加密失败`),intent:H.DANGER,icon:`error`})}finally{o(!1)}},handleEnrollPasskey:async()=>{o(!0);try{let e=await me(),r=e.length>0?e[0].id:`primary`;if(await Z.wrapCurrentKeyForPasskey(r))a.current?.show({message:s(`account.e2ee.enrollPasskeySuccess`,`已成功将通行密钥关联至端到端加密!`),intent:H.SUCCESS,icon:`tick`}),await n(),t?.();else throw Error(s(`account.e2ee.enrollPasskeyFailed`,`关联通行密钥失败`))}catch(e){console.error(`[useE2eeActions] Enroll passkey failed:`,e),a.current?.show({message:e.message||s(`account.e2ee.enrollPasskeyFailed`,`关联通行密钥失败`),intent:H.DANGER,icon:`error`})}finally{o(!1)}},isResetAlertOpen:c,setIsResetAlertOpen:l,handleResetAndReinit:async()=>{o(!0);try{await fetch(`/api/account/e2ee?purge=true`,{method:`DELETE`}),Z.clearStorage(),e?(await Z.enableUserE2ee(),a.current?.show({message:s(`account.e2ee.resetAndInitPasskeySuccess`,`密钥对已成功重置并使用通行密钥重新加密!`),intent:H.SUCCESS,icon:`tick`})):(a.current?.show({message:s(`account.e2ee.resetSuccessEnterRecovery`,`旧密钥已清除,请使用恢复密钥初始化新密钥对。`),intent:H.WARNING,icon:`refresh`}),i(!0)),await n(),t?.()}catch(e){console.error(`[useE2eeActions] Reset keypair failed:`,e),a.current?.show({message:e.message||s(`account.e2ee.resetFailed`,`重置密钥对失败`),intent:H.DANGER,icon:`error`})}finally{o(!1),l(!1)}}}}function zt({user:e,onRefresh:t,toasterRef:n}){let[r,i]=(0,Q.useState)(!1),a=It({user:e,onRefresh:t,toasterRef:n,setProcessing:i}),o=Lt({onRefresh:t,loadStatus:a.loadStatus,setIsUnlocked:a.setIsUnlocked,toasterRef:n,setProcessing:i}),s=Rt({hasPasskey:a.hasPasskey,onRefresh:t,loadStatus:a.loadStatus,setIsUnlocked:a.setIsUnlocked,setInitRecoveryDialogOpen:o.setInitRecoveryDialogOpen,toasterRef:n,setProcessing:i});return{status:a.status,loading:a.loading,processing:r,isUnlocked:a.isUnlocked,isPqc:a.isPqc,isLogsE2eeEnabled:a.isLogsE2eeEnabled,hasPasskey:a.hasPasskey,isDisableAlertOpen:a.isDisableAlertOpen,setIsDisableAlertOpen:a.setIsDisableAlertOpen,isRecoveryDialogOpen:o.isRecoveryDialogOpen,setIsRecoveryDialogOpen:o.setIsRecoveryDialogOpen,recoveryKeyInput:o.recoveryKeyInput,setRecoveryKeyInput:o.setRecoveryKeyInput,recoveryUnlockError:o.recoveryUnlockError,setRecoveryUnlockError:o.setRecoveryUnlockError,initRecoveryDialogOpen:o.initRecoveryDialogOpen,setInitRecoveryDialogOpen:o.setInitRecoveryDialogOpen,initRecoveryKeyInput:o.initRecoveryKeyInput,setInitRecoveryKeyInput:o.setInitRecoveryKeyInput,initRecoveryError:o.initRecoveryError,setInitRecoveryError:o.setInitRecoveryError,rotatedKey:o.rotatedKey,setRotatedKey:o.setRotatedKey,copiedKey:o.copiedKey,handleToggleLogs:a.handleToggleLogs,handleConfirmDisable:a.handleConfirmDisable,handleUnlock:s.handleUnlock,handleUnlockWithRecoveryKey:o.handleUnlockWithRecoveryKey,handleGenerateKeyWithPasskey:s.handleGenerateKeyWithPasskey,handleUpgradeToPqc:s.handleUpgradeToPqc,handleInitWithRecoveryKey:o.handleInitWithRecoveryKey,handleLockDevice:a.handleLockDevice,handleCopyRotatedKey:o.handleCopyRotatedKey,isResetAlertOpen:s.isResetAlertOpen,setIsResetAlertOpen:s.setIsResetAlertOpen,handleResetAndReinit:s.handleResetAndReinit,handleEnrollPasskey:s.handleEnrollPasskey}}const Bt=({isLogsE2eeEnabled:e})=>{let{t}=d();return(0,$.jsxs)(`div`,{className:`flex items-center justify-between mb-3`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(h,{size:20,className:e?`text-emerald-500`:`text-gray-400`}),(0,$.jsx)(G,{style:{margin:0},children:t(`account.e2ee.title`,`E2EE`)}),(0,$.jsx)(q,{intent:e?H.SUCCESS:H.NONE,minimal:!0,round:!0,children:t(e?`account.e2ee.enabled`:`account.e2ee.disabled`)})]}),(0,$.jsx)(re,{placement:`bottom-end`,usePortal:!0,content:(0,$.jsxs)(`div`,{className:`p-4 max-w-sm`,children:[(0,$.jsx)(ne,{children:t(`account.e2ee.trustBoundaryTitle`)}),(0,$.jsx)(`p`,{className:`text-sm text-gray-700 dark:text-gray-300 m-0`,children:t(`account.e2ee.trustBoundaryDesc`,`All DNS query traffic inevitably passes through the hosting server (Cloudflare Workers edge nodes or self-hosted server runtime) during resolution, where queries are processed in memory before being encrypted and saved. This feature strictly protects data at rest in the cloud database (D1 / persistent storage) from data leaks or offline analysis; it does not conceal active network traffic from the hosting server processing the request.`)})]}),children:(0,$.jsx)(L,{icon:`help`,variant:`minimal`,intent:H.NONE})})]})},Vt=({hasPasskey:e,processing:n,onGenerateKeyWithPasskey:r,onOpenInitRecoveryDialog:i})=>{let{t:a}=d();return(0,$.jsx)(V,{intent:H.PRIMARY,icon:`shield`,className:`my-3 text-xs`,children:(0,$.jsxs)(`div`,{className:`space-y-3`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`h5`,{className:`font-semibold text-sm mb-1 text-blue-900 dark:text-blue-100`,children:a(`account.e2ee.noKeypairTitle`)}),(0,$.jsx)(`p`,{className:`text-xs text-blue-800 dark:text-blue-200 m-0`,children:a(`account.e2ee.noKeypairDesc`)})]}),(0,$.jsxs)(`div`,{className:`flex items-center gap-2 flex-wrap pt-1`,children:[e?(0,$.jsx)(L,{intent:H.PRIMARY,small:!0,icon:(0,$.jsx)(t,{size:14}),text:a(`account.e2ee.initPasskeyBtn`),loading:n,onClick:r}):(0,$.jsx)(L,{intent:H.PRIMARY,small:!0,icon:(0,$.jsx)(u,{size:14}),text:a(`account.e2ee.addPasskeyBtn`),onClick:()=>{document.getElementById(`passkeys-section`)?.scrollIntoView({behavior:`smooth`})}}),(0,$.jsx)(L,{intent:H.NONE,small:!0,icon:(0,$.jsx)(u,{size:14}),text:a(`account.e2ee.initRecoveryBtn`),onClick:i})]})]})})},Ht=({status:e,isLogsE2eeEnabled:r,isUnlocked:i,isPqc:a,hasPasskey:o,processing:s,loading:c,onToggleLogs:l,onUpgradeToPqc:u,onLockDevice:p,onUnlockPasskey:m,onOpenRecoveryUnlockDialog:h,onEnrollPasskey:g,onOpenResetAlert:_})=>{let{t:v}=d();return(0,$.jsxs)(`div`,{className:`space-y-4`,children:[(0,$.jsx)(U,{className:`my-2`}),(0,$.jsxs)(`div`,{className:`flex flex-col sm:flex-row sm:items-center justify-between gap-4 p-4 rounded-lg border border-gray-200 dark:border-gray-800 bg-gray-50/70 dark:bg-gray-900/50`,children:[(0,$.jsxs)(`div`,{className:`space-y-1`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(`span`,{className:`font-semibold text-sm text-gray-900 dark:text-gray-100`,children:v(`account.e2ee.enableSwitch`)}),(0,$.jsx)(q,{intent:r?H.SUCCESS:H.NONE,minimal:!0,round:!0,children:v(r?`account.e2ee.enabled`:`account.e2ee.disabled`)})]}),(0,$.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-gray-400 m-0`,children:v(`account.e2ee.enableSwitchDesc`)})]}),(0,$.jsx)(`div`,{className:`shrink-0 flex items-center`,children:(0,$.jsx)(ae,{checked:r,disabled:s||c,onChange:e=>l(e.currentTarget.checked),large:!0,className:`mb-0`})})]}),(0,$.jsxs)(`div`,{className:`pt-2 border-t border-gray-100 dark:border-gray-800/80 space-y-2 text-xs`,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,$.jsxs)(`span`,{className:`opacity-70 flex items-center gap-1.5`,children:[(0,$.jsx)(t,{size:13}),v(`account.e2ee.keyType`),`:`]}),(0,$.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,$.jsx)(`span`,{className:`font-mono`,children:a?`P256-MLKEM768 + AES-256-GCM`:`ECDH P-256 + AES-256-GCM`}),a?(0,$.jsx)(q,{minimal:!0,intent:H.PRIMARY,className:`text-[10px]`,children:v(`account.e2ee.pqcTag`,`PQC / NIST FIPS 203`)}):(0,$.jsx)(L,{small:!0,intent:H.PRIMARY,minimal:!0,icon:(0,$.jsx)(f,{size:12}),text:v(`account.e2ee.upgradePqcBtn`,`升级到后量子 (PQC)`),loading:s,onClick:u})]})]}),(0,$.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,$.jsxs)(`span`,{className:`opacity-70 flex items-center gap-1.5`,children:[(0,$.jsx)(n,{size:13}),v(`account.e2ee.deviceState`),`:`]}),i?(0,$.jsxs)(`div`,{className:`flex items-center gap-2 flex-wrap justify-end`,children:[(0,$.jsx)(q,{minimal:!0,intent:H.SUCCESS,className:`text-[10px]`,children:v(`account.e2ee.unlocked`)}),o&&(e?.wrappedPasskeys?.length||0)===0&&g&&(0,$.jsx)(L,{small:!0,intent:H.PRIMARY,icon:(0,$.jsx)(t,{size:12}),text:v(`account.e2ee.enrollPasskeyBtn`,`关联当前通行密钥`),loading:s,onClick:g}),(0,$.jsx)(L,{small:!0,minimal:!0,intent:H.NONE,icon:`lock`,text:v(`account.e2ee.lockDevice`,`锁定此设备`),onClick:p})]}):(0,$.jsxs)(`div`,{className:`flex items-center gap-2 flex-wrap justify-end`,children:[o&&(e?.wrappedPasskeys?.length||0)>0&&(0,$.jsx)(L,{small:!0,minimal:!0,intent:H.PRIMARY,icon:(0,$.jsx)(f,{size:12}),text:v(`account.e2ee.unlockButton`),loading:s,onClick:m}),(0,$.jsx)(L,{small:!0,minimal:!0,intent:H.NONE,icon:(0,$.jsx)(t,{size:12}),text:v(`account.e2ee.unlockRecoveryButton`),onClick:h}),_&&(0,$.jsx)(L,{small:!0,minimal:!0,intent:H.DANGER,icon:`reset`,text:v(`account.e2ee.resetKeypairBtn`,`重置密钥对`),onClick:_})]})]}),(0,$.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,$.jsxs)(`span`,{className:`opacity-70`,children:[v(`account.e2ee.protectedPasskeys`),`:`]}),(0,$.jsxs)(`span`,{className:`font-mono`,children:[e?.wrappedPasskeys?.length||0,` `,v(`account.e2ee.devicesUnit`)]})]})]})]})},Ut=({isOpen:e,processing:t,onConfirm:n,onCancel:r})=>{let{t:i}=d();return(0,$.jsx)(P,{isOpen:e,confirmButtonText:i(`common.confirmDisable`),cancelButtonText:i(`common.cancel`),intent:H.DANGER,icon:`unlock`,onConfirm:n,onCancel:r,loading:t,children:(0,$.jsx)(`p`,{children:i(`account.e2ee.disableConfirm`)})})},Wt=({isOpen:e,onClose:t,recoveryKeyInput:n,setRecoveryKeyInput:r,recoveryUnlockError:i,processing:a,onSubmit:o})=>{let{t:s}=d();return(0,$.jsx)(R,{isOpen:e,onClose:t,title:s(`account.e2ee.unlockWithRecoveryTitle`),icon:`key`,className:`dark:bg-gray-900`,children:(0,$.jsxs)(`form`,{onSubmit:o,autoComplete:`off`,children:[(0,$.jsxs)(`div`,{className:I,children:[(0,$.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-gray-400 mb-3`,children:s(`account.e2ee.unlockWithRecoveryDesc`)}),i&&(0,$.jsx)(V,{intent:H.DANGER,className:`mb-3 text-xs`,children:i}),(0,$.jsx)(K,{label:s(`account.e2ee.recoveryKeyInputLabel`),labelFor:`recovery-key-input`,children:(0,$.jsx)(W,{id:`recovery-key-input`,name:`recovery_key_input`,autoComplete:`off`,autoCorrect:`off`,autoCapitalize:`off`,spellCheck:!1,"data-1p-ignore":`true`,"data-lpignore":`true`,"data-bwignore":`true`,placeholder:`123456-789012-345678-901234-567890`,value:n,onChange:e=>r(e.target.value),leftIcon:`key`,className:`font-mono text-xs`,autoFocus:!0})})]}),(0,$.jsx)(`div`,{className:B,children:(0,$.jsxs)(`div`,{className:Y,children:[(0,$.jsx)(L,{onClick:t,text:s(`common.cancel`)}),(0,$.jsx)(L,{type:`submit`,intent:H.PRIMARY,loading:a,disabled:!n.trim(),text:s(`account.e2ee.unlockConfirm`)})]})})]})})},Gt=({isOpen:e,onClose:t,initRecoveryKeyInput:n,setInitRecoveryKeyInput:r,initRecoveryError:i,processing:a,onSubmit:o})=>{let{t:s}=d();return(0,$.jsx)(R,{isOpen:e,onClose:t,title:s(`account.e2ee.initWithRecoveryTitle`),icon:`key`,className:`dark:bg-gray-900`,children:(0,$.jsxs)(`form`,{onSubmit:o,autoComplete:`off`,children:[(0,$.jsxs)(`div`,{className:I,children:[(0,$.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-gray-400 mb-3`,children:s(`account.e2ee.initWithRecoveryDesc`)}),i&&(0,$.jsx)(V,{intent:H.DANGER,className:`mb-3 text-xs`,children:i}),(0,$.jsx)(K,{label:s(`account.e2ee.recoveryKeyInputLabel`),labelFor:`init-recovery-key-input`,children:(0,$.jsx)(W,{id:`init-recovery-key-input`,name:`init_recovery_key_input`,autoComplete:`off`,autoCorrect:`off`,autoCapitalize:`off`,spellCheck:!1,"data-1p-ignore":`true`,"data-lpignore":`true`,"data-bwignore":`true`,placeholder:`123456-789012-345678-901234-567890`,value:n,onChange:e=>r(e.target.value),leftIcon:`key`,className:`font-mono text-xs`,autoFocus:!0})})]}),(0,$.jsx)(`div`,{className:B,children:(0,$.jsxs)(`div`,{className:Y,children:[(0,$.jsx)(L,{onClick:t,text:s(`common.cancel`)}),(0,$.jsx)(L,{type:`submit`,intent:H.PRIMARY,loading:a,disabled:!n.trim(),text:s(`account.e2ee.generateKeypairBtn`)})]})})]})})},Kt=({rotatedKey:e,onClose:t,copiedKey:n,onCopyKey:r})=>{let{t:i}=d();return(0,$.jsxs)(R,{isOpen:!!e,onClose:t,title:i(`account.recoveryKey.autoRotatedTitle`),icon:`warning-sign`,isCloseButtonShown:!1,canOutsideClickClose:!1,className:`dark:bg-gray-900`,children:[(0,$.jsxs)(`div`,{className:I,children:[(0,$.jsx)(V,{intent:H.WARNING,icon:(0,$.jsx)(S,{size:16}),className:`mb-4 text-xs`,children:i(`account.recoveryKey.autoRotatedNotice`)}),e&&(0,$.jsxs)(`div`,{className:`space-y-3`,children:[(0,$.jsx)(`div`,{className:`p-3 bg-gray-100 dark:bg-gray-800 rounded border border-gray-200 dark:border-gray-700 font-mono text-center text-lg font-bold tracking-widest select-all text-gray-900 dark:text-gray-100`,children:e}),(0,$.jsx)(`div`,{className:`flex justify-center`,children:(0,$.jsx)(L,{intent:H.PRIMARY,icon:n?(0,$.jsx)(y,{size:14,className:`text-green-400`}):(0,$.jsx)(w,{size:14}),text:i(n?`common.copied`:`common.copyKey`),onClick:()=>r(e)})})]})]}),(0,$.jsx)(`div`,{className:B,children:(0,$.jsx)(`div`,{className:Y,children:(0,$.jsx)(L,{intent:H.SUCCESS,onClick:t,text:i(`account.recoveryKey.savedAndClose`)})})})]})},qt=({isOpen:e,processing:t,hasPasskey:n,onConfirm:r,onCancel:i})=>{let{t:a}=d();return(0,$.jsx)(P,{isOpen:e,confirmButtonText:a(`account.e2ee.confirmResetBtn`,`确认重置并重新生成`),cancelButtonText:a(`common.cancel`,`取消`),intent:H.DANGER,icon:`reset`,onConfirm:r,onCancel:i,loading:t,children:(0,$.jsxs)(`div`,{className:`space-y-2 text-xs`,children:[(0,$.jsx)(`p`,{className:`font-semibold text-gray-900 dark:text-gray-100`,children:a(`account.e2ee.resetKeypairTitle`,`重置端到端加密密钥对`)}),(0,$.jsx)(`p`,{children:a(`account.e2ee.resetKeypairDesc`,`如果您的恢复密钥不匹配或无法解密,且未关联通行密钥,重置密钥对将从服务端清除旧密钥,并为您重新生成全新的后量子 (P256-MLKEM768) 密钥对。`)}),(0,$.jsx)(`p`,{className:`text-gray-500 dark:text-gray-400`,children:n?a(`account.e2ee.resetKeypairPasskeyNotice`,`确认后将立即调用您当前已配置的通行密钥 (Passkey) 完成新密钥对的加密与授权。`):a(`account.e2ee.resetKeypairRecoveryNotice`,`确认后将引导您输入当前恢复密钥以完成新密钥对的生成与加密。`)})]})})},Jt=({user:e,onRefresh:t})=>{let{t:n}=d(),r=(0,Q.useRef)(null),{status:i,loading:a,processing:o,isUnlocked:s,isPqc:c,isLogsE2eeEnabled:l,hasPasskey:u,isDisableAlertOpen:f,setIsDisableAlertOpen:p,isRecoveryDialogOpen:m,setIsRecoveryDialogOpen:h,recoveryKeyInput:g,setRecoveryKeyInput:_,recoveryUnlockError:v,initRecoveryDialogOpen:y,setInitRecoveryDialogOpen:b,initRecoveryKeyInput:x,setInitRecoveryKeyInput:S,initRecoveryError:C,setInitRecoveryError:w,rotatedKey:T,setRotatedKey:E,copiedKey:D,handleToggleLogs:O,handleConfirmDisable:k,handleUnlock:A,handleUnlockWithRecoveryKey:j,handleGenerateKeyWithPasskey:ee,handleUpgradeToPqc:M,handleInitWithRecoveryKey:N,handleLockDevice:P,handleCopyRotatedKey:te,isResetAlertOpen:I,setIsResetAlertOpen:ne,handleResetAndReinit:L,handleEnrollPasskey:R}=zt({user:e,onRefresh:t,toasterRef:r});return(0,$.jsxs)(J,{elevation:F.ONE,className:`space-y-6`,children:[(0,$.jsx)(oe,{ref:r}),(0,$.jsxs)(`div`,{children:[(0,$.jsx)(Bt,{isLogsE2eeEnabled:l}),(0,$.jsx)(`p`,{className:`text-sm text-gray-600 dark:text-gray-400 mb-3`,children:n(`account.e2ee.desc`)}),a?(0,$.jsx)(`div`,{className:`flex items-center justify-center p-6`,children:(0,$.jsx)(z,{size:20})}):i?.hasKeys?(0,$.jsx)(Ht,{status:i,isLogsE2eeEnabled:l,isUnlocked:s,isPqc:c,hasPasskey:u,processing:o,loading:a,onToggleLogs:O,onUpgradeToPqc:M,onLockDevice:P,onUnlockPasskey:A,onOpenRecoveryUnlockDialog:()=>{_(``),h(!0)},onEnrollPasskey:R,onOpenResetAlert:()=>ne(!0)}):(0,$.jsx)(Vt,{hasPasskey:u,processing:o,onGenerateKeyWithPasskey:ee,onOpenInitRecoveryDialog:()=>{w(``),S(``),b(!0)}})]}),(0,$.jsx)(Ut,{isOpen:f,processing:o,onConfirm:k,onCancel:()=>p(!1)}),(0,$.jsx)(qt,{isOpen:I,processing:o,hasPasskey:u,onConfirm:L,onCancel:()=>ne(!1)}),(0,$.jsx)(Wt,{isOpen:m,onClose:()=>h(!1),recoveryKeyInput:g,setRecoveryKeyInput:_,recoveryUnlockError:v,processing:o,onSubmit:j}),(0,$.jsx)(Gt,{isOpen:y,onClose:()=>b(!1),initRecoveryKeyInput:x,setInitRecoveryKeyInput:S,initRecoveryError:C,processing:o,onSubmit:N}),(0,$.jsx)(Kt,{rotatedKey:T,onClose:()=>E(null),copiedKey:D,onCopyKey:te})]})},Yt=()=>{let[e,t]=(0,Q.useState)(null),[r,i]=(0,Q.useState)([]),[a,o]=(0,Q.useState)(!0),[s,c]=(0,Q.useState)(null),{t:l,i18n:u}=d(),f=ue(),[m,h]=(0,Q.useState)(!1),[g,_]=(0,Q.useState)(``),[v,y]=(0,Q.useState)(!1),[b,x]=(0,Q.useState)(!1),[S,C]=(0,Q.useState)({}),w=async()=>{try{i(await ke())}catch(e){console.error(e)}},T=async()=>{try{C(await Xe())}catch(e){console.error(e)}},E=(0,Q.useCallback)(async()=>{try{let e=await Me();if(t(e),_(e.username),window.dispatchEvent(new Event(`user_updated`)),e.timezone){let{setSystemTimeZone:t}=await j(async()=>{let{setSystemTimeZone:e}=await import(`./date-DG8jTrEB.js`);return{setSystemTimeZone:e}},__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10]));t(e.timezone)}if(e.locale){let{setSystemLocale:t}=await j(async()=>{let{setSystemLocale:e}=await import(`./date-DG8jTrEB.js`);return{setSystemLocale:e}},__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10]));t(e.locale),u.changeLanguage(e.locale)}e.role===`admin`&&(w(),T())}catch(e){console.error(e)}finally{o(!1)}},[]);return(0,Q.useEffect)(()=>{E()},[E]),a?(0,$.jsx)(`div`,{className:`p-8 text-center`,children:l(`common.loading`)}):(0,$.jsxs)(`div`,{className:le(`max-w-5xl mx-auto space-y-8`,f?`p-0`:`px-8`),children:[(0,$.jsxs)(`div`,{className:`flex justify-between items-end`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`h2`,{className:`bp6-heading`,children:l(`account.title`)}),(0,$.jsx)(`p`,{className:`bp6-text-muted`,children:l(`account.subtitle`)})]}),e&&(0,$.jsx)(q,{large:!0,round:!0,intent:e.role===`admin`?H.DANGER:H.PRIMARY,icon:(0,$.jsx)(n,{size:16}),children:e.role===`admin`?l(`account.roleAdmin`):l(`account.roleUser`)})]}),e?.role===`admin`&&e?.jwt_secret_warning&&(0,$.jsx)(V,{intent:H.WARNING,icon:(0,$.jsx)(p,{size:18}),title:l(`account.jwtSecretWarningTitle`),children:(0,$.jsx)(`div`,{className:`text-sm leading-relaxed mt-1`,children:l(`account.jwtSecretWarningDesc`)})}),(0,$.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-6`,children:[(0,$.jsx)(jt,{me:e,isEditingUsername:m,setIsEditingUsername:h,editUsername:g,setEditUsername:_,usernameLoading:v,usernameFocused:b,setUsernameFocused:x,onUpdateUsername:async()=>{if(g===e?.username){h(!1);return}if(!Be.test(g)){alert(l(`account.formatTipUsername`));return}y(!0);try{await Te({username:g}),t(e=>e?{...e,username:g}:null),h(!1)}catch(e){console.error(e),alert(e.message||l(`common.errorNetwork`))}finally{y(!1)}},onUpdateTimezone:async e=>{try{await Te({timezone:e||``}),t(t=>t?{...t,timezone:e}:null);let{setSystemTimeZone:n}=await j(async()=>{let{setSystemTimeZone:e}=await import(`./date-DG8jTrEB.js`);return{setSystemTimeZone:e}},__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10]));n(e||``)}catch(e){console.error(e),alert(e.message||l(`common.errorNetwork`))}}}),(0,$.jsx)(Mt,{me:e,onRefresh:E})]}),e&&(0,$.jsx)(bt,{user:e,onRefresh:E}),e&&(0,$.jsx)(Jt,{user:e,onRefresh:E}),e&&(0,$.jsx)(Ft,{user:e,onRefresh:E}),e&&(0,$.jsx)(Et,{hoveredSessionId:s,setHoveredSessionId:c}),e&&(0,$.jsx)(Tt,{hoveredSessionId:s,setHoveredSessionId:c}),e?.role===`admin`&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(U,{}),(0,$.jsx)(`div`,{className:`space-y-4`,children:(0,$.jsx)(Dt,{users:r,currentUserId:e.id,onRefresh:w,registrationEnabled:S.registration_enabled!==`false`,onRefreshSettings:T})}),(0,$.jsx)(U,{}),(0,$.jsx)(`div`,{className:`space-y-4`,children:(0,$.jsx)(Ot,{initialSettings:S,onRefresh:T})})]}),(0,$.jsx)(U,{}),(0,$.jsx)(`div`,{className:`space-y-4`,children:(0,$.jsx)(kt,{isAdmin:e?.role===`admin`})})]})};export{Yt as AccountView};
@@ -1,2 +0,0 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/TrendChart-wcrIRt7R.js","assets/index-CrB_HdIL.js","assets/vendor-icons-other-BTYC6Wvz.js","assets/vendor-icons-16-BgwRBCeU.js","assets/rolldown-runtime-C4Xdq4VV.js","assets/vendor-icons-20-X5NPN60g.js","assets/vendor-react-De1zEwOV.js","assets/vendor-i18next-CevVzhh3.js","assets/vendor-ui-core-ClwQiwMI.js","assets/vendor-utils-rmW6cqPl.js","assets/index-DZNm9qiP.css","assets/DestinationMap-Bwv9zW4k.js","assets/formatCountryName-JTcoEopY.js","assets/getFlagEmoji-DiZiGyWX.js"])))=>i.map(i=>d[i]);
2
- import{i as e}from"./rolldown-runtime-C4Xdq4VV.js";import{D as t,L as n,Qt as r,j as i,q as a,tt as o,v as s,vt as c}from"./vendor-react-De1zEwOV.js";import{S as l,b as u,x as d}from"./vendor-icons-other-BTYC6Wvz.js";import"./vendor-i18next-CevVzhh3.js";import{C as f,H as p,M as m,N as h,P as g,T as _,V as v,d as y,f as b,o as x,p as S,r as C,u as w,x as T}from"./vendor-ui-core-ClwQiwMI.js";import{_t as E}from"./vendor-utils-rmW6cqPl.js";import{$t as D,Q as O,X as k,Z as A,x as j,y as M}from"./index-CrB_HdIL.js";import{t as N}from"./getFlagEmoji-DiZiGyWX.js";var P=e(l(),1);function F(e,t,n){if(!e)return[];let r={},i=Math.floor(Date.now()/1e3),a,o;switch(t){case`10m`:o=60,a=i-600;break;case`1h`:o=60,a=i-3600;break;case`24h`:o=3600,a=i-24*3600;break;case`7d`:o=86400,a=i-7*86400;break;case`30d`:o=86400,a=i-30*86400;break;case`custom`:if(o=3600,n.start&&n.end)a=Math.floor(new Date(n.start).getTime()/1e3),i=Math.floor(new Date(n.end).getTime()/1e3);else{let t=e.trend.map(e=>e.timestamp);a=t.length?Math.min(...t):i-86400,i=t.length?Math.max(...t):i}break;default:o=3600,a=i-24*3600}a=Math.floor(a/o)*o,i=Math.floor(i/o)*o;for(let e=a;e<=i;e+=o)r[e]={timestamp:e,allowed:0,blocked:0,redirected:0};return e.trend.forEach(e=>{let t=Math.floor(e.timestamp/o)*o;r[t]||(r[t]={timestamp:t,allowed:0,blocked:0,redirected:0}),e.action===`PASS`?r[t].allowed+=e.count:e.action===`BLOCK`?r[t].blocked+=e.count:e.action===`REDIRECT`&&(r[t].redirected+=e.count)}),Object.keys(r).sort((e,t)=>Number(e)-Number(t)).map(e=>r[Number(e)])}var I=e(u(),1);const L=({title:e,data:t,intent:n})=>{let{t:i}=r(),a=[{key:`rank`,cellClassName:`w-8 opacity-30 font-mono text-xs`,render:(e,t)=>t+1},{key:`domain`,cellClassName:`font-medium text-sm truncate max-w-50`,render:e=>e.domain},{key:`count`,cellClassName:`text-right`,render:e=>(0,I.jsx)(C,{minimal:!0,intent:n,className:`font-bold`,children:e.count})}];return(0,I.jsxs)(T,{elevation:p.ZERO,className:`dark:bg-gray-900 dark:border-gray-800 border border-gray-100 shadow-sm`,children:[(0,I.jsx)(m,{className:`mb-4 font-bold`,children:e}),(0,I.jsx)(w,{striped:!0,className:`w-full`,children:(0,I.jsxs)(`tbody`,{children:[t.map((e,t)=>(0,I.jsx)(`tr`,{children:a.map(n=>(0,I.jsx)(`td`,{className:n.cellClassName,children:n.render(e,t)},n.key))},t)),t.length===0&&(0,I.jsx)(`tr`,{children:(0,I.jsx)(`td`,{colSpan:a.length,className:`text-center py-8 opacity-50`,children:i(`analytics.noData`)})})]})})]})};function R(e){let[t,n]=(0,P.useState)(null),[r,i]=(0,P.useState)(!0),[a,o]=(0,P.useState)(`24h`),[s,c]=(0,P.useState)({start:``,end:``}),[l,u]=(0,P.useState)(null),[d,f]=(0,P.useState)([]),[p,m]=(0,P.useState)(30);(0,P.useEffect)(()=>{k(e).then(e=>f(e)).catch(e=>console.error(`[useAnalyticsData] Failed to load access points:`,e))},[e]),(0,P.useEffect)(()=>{O(e).then(e=>{try{let t=JSON.parse(e.settings||`{}`);m(t.log_retention_days===void 0?30:Number(t.log_retention_days))}catch(e){console.error(`[useAnalyticsData] Failed to parse settings:`,e)}}).catch(e=>console.error(`[useAnalyticsData] Failed to fetch profile settings:`,e))},[e]);let h=(0,P.useCallback)(async(t,r,a,o)=>{i(!0);let s=Math.floor(Date.now()/1e3),c,l=s,u;if(t===`custom`&&r&&a){c=Math.floor(new Date(r).getTime()/1e3),l=Math.floor(new Date(a).getTime()/1e3);let e=l-c;u=e<=7200?60:e<=172800?3600:86400}else switch(t){case`10m`:c=s-600,u=60;break;case`1h`:c=s-3600,u=60;break;case`24h`:c=s-86400,u=3600;break;case`7d`:c=s-604800,u=86400;break;case`30d`:c=s-2592e3,u=86400;break;default:c=s-86400,u=3600;break}try{j.isUnlocked()&&await M.reDecryptLocalLogs(e)}catch{}try{if(await M.init()){let t=await M.queryAnalytics({profileId:e,since:c,until:l,bucketSec:u,accessPointId:o||void 0});t.summary.some(e=>e.count>0)&&(n(t),i(!1))}}catch(e){console.warn(`[useAnalyticsData] Local SQLite preview failed:`,e)}try{let i=`?range=${t}`;t===`custom`&&r&&a&&(i+=`&start=${c}&end=${l}`),o&&(i+=`&access_point_id=${o}`);let s=null;try{s=await A(e,``,i)}catch{let[t,n,r,a,o,c]=await Promise.all([A(e,`summary`,i),A(e,`trend`,i),A(e,`top_allowed`,i),A(e,`top_blocked`,i),A(e,`clients`,i),A(e,`destinations`,i)]);s={summary:t,trend:n,top_allowed:r,top_blocked:a,clients:o,destinations:c}}s&&n(e=>{let t=e&&(e.top_allowed.some(e=>e.domain&&e.domain!==`[Encrypted]`&&e.domain!==`[Decryption Failed]`)||e.destinations&&e.destinations.length>0);return{...s,trend:s.trend||[],summary:s.summary||[],top_allowed:t&&e?.top_allowed.length?e.top_allowed:s.top_allowed||[],top_blocked:t&&e?.top_blocked.length?e.top_blocked:s.top_blocked||[],clients:t&&e?.clients.length?e.clients:s.clients||[],destinations:(t||(s.destinations||[]).length===0)&&e?.destinations?.length?e.destinations:s.destinations||[]}})}catch(e){console.error(`[useAnalyticsData] Failed to fetch server analytics:`,e)}finally{i(!1)}try{M.syncProfileLogs(e,void 0,c).then(async t=>{if(t>0)try{let t=await M.queryAnalytics({profileId:e,since:c,until:l,bucketSec:u,accessPointId:o||void 0});(t.destinations?.length>0||t.top_allowed?.length>0)&&n(e=>e?{...e,destinations:t.destinations.length>0?t.destinations:e.destinations,top_allowed:t.top_allowed.length>0?t.top_allowed:e.top_allowed,top_blocked:t.top_blocked.length>0?t.top_blocked:e.top_blocked,clients:t.clients.length>0?t.clients:e.clients}:t)}catch{}}).catch(e=>{console.warn(`[useAnalyticsData] Background sync error:`,e)})}catch{}},[e]);return(0,P.useEffect)(()=>{a!==`custom`&&h(a,void 0,void 0,l)},[a,l,h]),{data:t,loading:r,range:a,setRange:o,customRange:s,setCustomRange:c,accessPointIdFilter:l,setAccessPointIdFilter:u,accessPoints:d,logRetentionDays:p,fetchData:h}}var z=[{key:`10m`,days:.007},{key:`1h`,days:.0416},{key:`24h`,days:1},{key:`7d`,days:7},{key:`30d`,days:30}];const B=({range:e,setRange:t,customRange:n,setCustomRange:i,logRetentionDays:a,accessPoints:o,accessPointIdFilter:s,setAccessPointIdFilter:l,loading:u,onApplyCustom:d})=>{let{t:p}=r(),x=new Date().toLocaleString(`sv-SE`).replace(` `,`T`).slice(0,16);return(0,I.jsxs)(`div`,{className:`flex justify-between items-center bg-white dark:bg-gray-900 p-2 rounded-lg shadow-sm border border-gray-100 dark:border-gray-800`,children:[(0,I.jsxs)(f,{variant:`minimal`,children:[z.filter(e=>e.days<=a).map(e=>e.key).map(n=>(0,I.jsx)(h,{active:e===n,onClick:()=>t(n),text:n.toUpperCase()},n)),(0,I.jsx)(_,{content:(0,I.jsxs)(`div`,{className:`p-4 space-y-4 w-64`,children:[(0,I.jsx)(m,{children:p(`analytics.customRange`)}),(0,I.jsx)(S,{label:p(`analytics.startTime`),children:(0,I.jsx)(b,{type:`datetime-local`,max:n.end||x,value:n.start,onChange:e=>i({...n,start:e.target.value})})}),(0,I.jsx)(S,{label:p(`analytics.endTime`),children:(0,I.jsx)(b,{type:`datetime-local`,min:n.start,max:x,value:n.end,onChange:e=>i({...n,end:e.target.value})})}),(0,I.jsx)(h,{fill:!0,intent:v.PRIMARY,text:p(`analytics.apply`),onClick:d})]}),children:(0,I.jsx)(h,{active:e===`custom`,icon:(0,I.jsx)(c,{size:14,className:`mr-1`}),text:p(`analytics.custom`)})})]}),(0,I.jsxs)(`div`,{className:`flex items-center gap-4`,children:[o.length>0&&(0,I.jsx)(y,{value:s||``,onChange:e=>l(e.target.value||null),options:[{label:`${p(`logs.allAccessPoint`)}`,value:``},...o.map(e=>({label:e.name,value:e.id}))],minimal:!0}),u&&(0,I.jsx)(g,{size:16})]})]})},V=({title:e,value:t,icon:n})=>(0,I.jsxs)(T,{elevation:p.ZERO,className:`flex items-center gap-4 p-4 dark:bg-gray-900 dark:border-gray-800 border border-gray-100 shadow-sm`,children:[(0,I.jsx)(`div`,{className:`p-3 bg-gray-50 dark:bg-gray-800 rounded-lg`,children:n}),(0,I.jsxs)(`div`,{children:[(0,I.jsx)(`div`,{className:`text-xs text-gray-500 font-medium uppercase tracking-wider`,children:e}),(0,I.jsx)(`div`,{className:`text-xl font-bold dark:text-white`,children:t})]})]}),H=({data:e})=>{let{t:a}=r(),c=e?.summary.reduce((e,t)=>e+t.count,0)||0,l=e?.summary.find(e=>e.action===`BLOCK`)?.count||0,u=e?.summary.find(e=>e.action===`REDIRECT`)?.count||0,d=c>0?(l/c*100).toFixed(1):`0.0`;return(0,I.jsx)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-5 gap-2 lg:gap-4`,children:[{title:a(`analytics.totalQueries`),value:c.toLocaleString(),icon:(0,I.jsx)(s,{className:`text-blue-500`,size:20})},{title:a(`analytics.blocked`),value:l.toLocaleString(),icon:(0,I.jsx)(i,{className:`text-red-500`,size:20})},{title:a(`analytics.redirected`),value:u.toLocaleString(),icon:(0,I.jsx)(n,{className:`text-amber-500`,size:20})},{title:a(`analytics.blockRate`),value:`${d}%`,icon:(0,I.jsx)(t,{className:`text-green-500`,size:20})},{title:a(`analytics.activeIPs`),value:e?.clients.length.toString()||`0`,icon:(0,I.jsx)(o,{className:`text-purple-500`,size:20})}].map((e,t)=>(0,I.jsx)(V,{title:e.title,value:e.value,icon:e.icon},t))})},U=({clients:e})=>{let{t}=r();return(0,I.jsx)(x,{title:t(`analytics.clientActivity`),icon:(0,I.jsx)(o,{size:16}),children:(0,I.jsxs)(w,{striped:!0,className:`w-full mt-2`,children:[(0,I.jsx)(`thead`,{children:(0,I.jsxs)(`tr`,{children:[(0,I.jsx)(`th`,{className:`text-xs uppercase opacity-60`,children:t(`analytics.ipAddress`)}),(0,I.jsx)(`th`,{className:`text-xs uppercase opacity-60`,children:t(`analytics.location`)}),(0,I.jsx)(`th`,{className:`text-xs uppercase opacity-60 text-right`,children:t(`analytics.queries`)})]})}),(0,I.jsxs)(`tbody`,{children:[e?.map((e,t)=>(0,I.jsxs)(`tr`,{children:[(0,I.jsx)(`td`,{className:`font-mono text-xs`,children:e.client_ip||`-`}),(0,I.jsx)(`td`,{children:(0,I.jsx)(C,{minimal:!0,children:N(e.geo_country)})}),(0,I.jsx)(`td`,{className:`text-right font-bold`,children:e.count})]},t)),(!e||e.length===0)&&(0,I.jsx)(`tr`,{children:(0,I.jsx)(`td`,{colSpan:3,className:`text-center py-8 opacity-50`,children:t(`analytics.noData`)})})]})]})})};var W=(0,P.lazy)(()=>d(()=>import(`./TrendChart-wcrIRt7R.js`),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10])).then(e=>({default:e.TrendChart}))),G=(0,P.lazy)(()=>d(()=>import(`./DestinationMap-Bwv9zW4k.js`),__vite__mapDeps([11,1,2,3,4,5,6,7,8,9,10,12,13])).then(e=>({default:e.DestinationMap}))),K=()=>(0,I.jsx)(`div`,{className:`h-64 flex items-center justify-center`,children:(0,I.jsx)(g,{size:30})});const q=({profileId:e})=>{let{t}=r(),n=D(),{data:i,loading:o,range:s,setRange:c,customRange:l,setCustomRange:u,accessPointIdFilter:d,setAccessPointIdFilter:f,accessPoints:h,logRetentionDays:_,fetchData:y}=R(e);if(o&&!i)return(0,I.jsx)(`div`,{className:`p-20 flex justify-center`,children:(0,I.jsx)(g,{size:50})});let b=F(i,s,l);return(0,I.jsxs)(`div`,{className:E(`max-w-7xl mx-auto space-y-6`,n?`p-0`:`p-6`),children:[(0,I.jsx)(B,{range:s,setRange:c,customRange:l,setCustomRange:u,logRetentionDays:_,accessPoints:h,accessPointIdFilter:d,setAccessPointIdFilter:f,loading:o,onApplyCustom:()=>{c(`custom`),y(`custom`,l.start,l.end,d)}}),(0,I.jsx)(H,{data:i}),(0,I.jsxs)(T,{elevation:p.ONE,className:`dark:bg-gray-900 dark:border-gray-800 relative`,children:[(0,I.jsxs)(m,{className:`mb-4 font-bold flex items-center gap-2`,children:[t(`analytics.queryTrend`),(0,I.jsx)(C,{minimal:!0,round:!0,children:s===`custom`?t(`analytics.custom`):s.toUpperCase()})]}),(0,I.jsx)(P.Suspense,{fallback:(0,I.jsx)(K,{}),children:(0,I.jsx)(W,{chartData:b,range:s})})]}),(0,I.jsxs)(`div`,{className:`grid grid-cols-1 lg:grid-cols-2 gap-6`,children:[(0,I.jsx)(L,{title:t(`analytics.topAllowed`),data:i?.top_allowed||[],intent:v.SUCCESS}),(0,I.jsx)(L,{title:t(`analytics.topBlocked`),data:i?.top_blocked||[],intent:v.DANGER})]}),(0,I.jsxs)(`div`,{className:`grid gap-6 grid-cols-1`,children:[(0,I.jsx)(x,{title:t(`analytics.destinationDistribution`),icon:(0,I.jsx)(a,{size:16}),children:(0,I.jsx)(P.Suspense,{fallback:(0,I.jsx)(K,{}),children:(0,I.jsx)(G,{destinations:i?.destinations||[],profileId:e||``,range:s,customRange:l,accessPointId:d||void 0})})}),(0,I.jsx)(U,{clients:i?.clients})]})]})};export{q as AnalyticsView};
@@ -1,5 +0,0 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/services-BYhiWUn8.js","assets/index-CrB_HdIL.js","assets/vendor-icons-other-BTYC6Wvz.js","assets/vendor-icons-16-BgwRBCeU.js","assets/rolldown-runtime-C4Xdq4VV.js","assets/vendor-icons-20-X5NPN60g.js","assets/vendor-react-De1zEwOV.js","assets/vendor-i18next-CevVzhh3.js","assets/vendor-ui-core-ClwQiwMI.js","assets/vendor-utils-rmW6cqPl.js","assets/index-DZNm9qiP.css"])))=>i.map(i=>d[i]);
2
- import{i as e}from"./rolldown-runtime-C4Xdq4VV.js";import{A as t,Et as n,G as r,H as i,Q as a,Qt as o,V as s,X as c,b as l,gt as u,j as d,lt as f,nt as p,q as m,tt as h,vt as g,xt as _}from"./vendor-react-De1zEwOV.js";import{S as v,b as y,x as b}from"./vendor-icons-other-BTYC6Wvz.js";import"./vendor-i18next-CevVzhh3.js";import{C as x,E as S,L as C,M as w,N as T,O as E,P as D,R as O,S as k,T as A,V as j,a as M,f as N,h as ee,l as P,o as F,p as I,r as L,u as te,w as R,x as z,z as B}from"./vendor-ui-core-ClwQiwMI.js";import{_t as V}from"./vendor-utils-rmW6cqPl.js";import{$t as ne,Q as re,X as H,Z as U,et as ie,h as ae,kt as oe,tt as se,v as W,x as G,y as K}from"./index-CrB_HdIL.js";import{n as q,t as J}from"./formatCountryName-JTcoEopY.js";import{t as Y}from"./getFlagEmoji-DiZiGyWX.js";import{t as ce}from"./SwipeableDrawer-DkPacJ1O.js";var X=e(v(),1),Z=e(y(),1);const le=({range:e,setRange:t,customRange:n,setCustomRange:r,nowStr:i,fetchLogs:a,isMobile:s,logRetentionDays:c})=>{let{t:l}=o(),u=[{key:`10m`,days:.007},{key:`1h`,days:.0416},{key:`24h`,days:1},{key:`7d`,days:7},{key:`30d`,days:30}].filter(e=>e.days<=c).map(e=>e.key);return(0,Z.jsx)(`div`,{className:`overflow-x-auto pb-1 -mx-4 px-4 md:mx-0 md:px-0`,children:(0,Z.jsxs)(x,{minimal:s,variant:s?void 0:`minimal`,children:[u.map(n=>(0,Z.jsx)(T,{active:e===n,onClick:()=>t(n),text:n.toUpperCase(),small:s},n)),(0,Z.jsx)(A,{content:(0,Z.jsxs)(`div`,{className:`p-4 space-y-2 w-64`,children:[(0,Z.jsx)(w,{children:l(`analytics.customRange`)}),(0,Z.jsx)(I,{label:l(`analytics.startTime`),children:(0,Z.jsx)(N,{type:`datetime-local`,max:n.end||i,value:n.start,onChange:e=>r({...n,start:e.target.value})})}),(0,Z.jsx)(I,{label:l(`analytics.endTime`),children:(0,Z.jsx)(N,{type:`datetime-local`,min:n.start,max:i,value:n.end,onChange:e=>r({...n,end:e.target.value})})}),(0,Z.jsx)(T,{fill:!0,intent:j.PRIMARY,text:l(`analytics.apply`),onClick:()=>{t(`custom`),a(`custom`,!0)}})]}),children:(0,Z.jsx)(T,{active:e===`custom`,icon:(0,Z.jsx)(g,{size:14}),text:s?``:l(`analytics.custom`),small:s})})]})})},ue=({statusFilter:e,setStatusFilter:t,isMobile:n})=>{let{t:r}=o(),i=(0,Z.jsxs)(S,{children:[(0,Z.jsx)(R,{icon:e===null?`tick`:void 0,text:r(`logs.allStatus`),onClick:()=>t(null)}),(0,Z.jsx)(P,{}),(0,Z.jsx)(R,{icon:e===`PASS`?`tick`:void 0,intent:j.SUCCESS,text:r(`logs.onlyPass`),onClick:()=>t(`PASS`)}),(0,Z.jsx)(R,{icon:e===`BLOCK`?`tick`:void 0,intent:j.DANGER,text:r(`logs.onlyBlock`),onClick:()=>t(`BLOCK`)}),(0,Z.jsx)(R,{icon:e===`REDIRECT`?`tick`:void 0,intent:j.WARNING,text:r(`logs.onlyRedirect`),onClick:()=>t(`REDIRECT`)})]}),a=(()=>{switch(e){case`PASS`:return{text:r(`logs.statusPass`),intent:j.SUCCESS};case`BLOCK`:return{text:r(`logs.statusBlock`),intent:j.DANGER};case`REDIRECT`:return{text:r(`logs.statusRedirect`),intent:j.WARNING};default:return{text:r(`logs.allStatus`),intent:j.NONE}}})();return(0,Z.jsx)(A,{content:i,placement:`bottom-start`,children:(0,Z.jsx)(T,{icon:(0,Z.jsx)(p,{size:14}),rightIcon:`caret-down`,intent:a.intent,text:a.text,variant:`outlined`,fill:n})})},de=({accessPointIdFilter:e,setAccessPointIdFilter:t,accessPoints:n,isMobile:i})=>{let{t:a}=o(),s=(0,Z.jsxs)(S,{children:[(0,Z.jsx)(R,{icon:e===null?`tick`:void 0,text:a(`logs.allAccessPoint`),onClick:()=>t(null)}),(0,Z.jsx)(P,{}),n.map(n=>(0,Z.jsx)(R,{icon:e===n.id?`tick`:void 0,text:n.name,onClick:()=>t(n.id)},n.id))]}),c=e&&n.find(t=>t.id===e)?.name||a(`logs.allAccessPoint`);return(0,Z.jsx)(A,{content:s,placement:`bottom-start`,children:(0,Z.jsx)(T,{icon:(0,Z.jsx)(r,{size:14}),rightIcon:`caret-down`,intent:e?j.PRIMARY:j.NONE,text:c,variant:`outlined`,fill:i})})},fe=Array.from(new Set(Object.values(q))).sort((e,t)=>e.localeCompare(t)),pe=({destCountryFilter:e,setDestCountryFilter:t,isMobile:n})=>{let{t:r,i18n:i}=o(),[a,s]=(0,X.useState)(!1),[c,l]=(0,X.useState)(``),u=(0,X.useMemo)(()=>{let e=i.language;return fe.map(t=>{let n=J(t,e),r=J(t,`en`);return{code:t,name:n||r||t,searchStr:`${t} ${n} ${r}`.toLowerCase()}})},[i.language]),d=(0,X.useMemo)(()=>{let e=c.trim().toLowerCase();return e?u.filter(t=>t.searchStr.includes(e)):u},[u,c]),f=(0,Z.jsxs)(`div`,{className:`w-72 flex flex-col p-1.5`,children:[(0,Z.jsx)(`div`,{className:`pb-1.5`,children:(0,Z.jsx)(N,{leftIcon:`search`,placeholder:r(`logs.searchCountry`,`Search country...`),value:c,onChange:e=>l(e.target.value),small:!0,autoFocus:!0,rightElement:c?(0,Z.jsx)(T,{icon:`cross`,variant:`minimal`,small:!0,onClick:()=>l(``)}):void 0})}),(0,Z.jsxs)(S,{className:`max-h-64 overflow-y-auto`,children:[!c&&(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(R,{icon:e===null?`tick`:void 0,text:r(`logs.allCountry`),onClick:()=>{t(null),s(!1)}}),(0,Z.jsx)(P,{})]}),d.length===0?(0,Z.jsx)(R,{disabled:!0,text:r(`logs.noMatchingCountries`,`No matching countries found`)}):d.map(n=>(0,Z.jsx)(R,{icon:e===n.code?`tick`:void 0,text:(0,Z.jsxs)(`span`,{className:`flex items-center justify-between gap-2 w-full`,children:[(0,Z.jsxs)(`span`,{className:`truncate`,children:[Y(n.code),` `,n.name]}),(0,Z.jsx)(`span`,{className:`text-xs text-gray-400 shrink-0 font-mono`,children:n.code})]}),onClick:()=>{t(n.code),s(!1)}},n.code))]})]}),p=e?`${Y(e)} ${J(e,i.language)||e} (${e})`:r(`logs.allCountry`);return(0,Z.jsx)(A,{content:f,placement:`bottom-start`,isOpen:a,onInteraction:e=>{s(e),e||l(``)},children:(0,Z.jsx)(T,{icon:(0,Z.jsx)(h,{size:14}),rightIcon:`caret-down`,intent:e?j.PRIMARY:j.NONE,text:p,variant:`outlined`,fill:n})})},me=({profileId:e,range:t,customRange:n,destCountryFilter:r,accessPointIdFilter:a,ispFilter:s,setIspFilter:c,isMobile:l})=>{let{t:u}=o(),[d,f]=(0,X.useState)(!1),[p,m]=(0,X.useState)([]),[h,g]=(0,X.useState)(!1),[_,v]=(0,X.useState)(``),y=(0,X.useRef)(``),b=`${e}:${t}:${n.start?Math.floor(new Date(n.start).getTime()/1e3):``}:${n.end?Math.floor(new Date(n.end).getTime()/1e3):``}:${r||``}:${a||``}`,x=async()=>{g(!0);try{let i=Math.floor(Date.now()/1e3),o,s=i,c=new URLSearchParams;if(t===`custom`&&n.start&&n.end)o=Math.floor(new Date(n.start).getTime()/1e3),s=Math.floor(new Date(n.end).getTime()/1e3),c.set(`range`,`custom`),c.set(`start`,String(o)),c.set(`end`,String(s));else{switch(t){case`10m`:o=i-600;break;case`1h`:o=i-3600;break;case`24h`:o=i-86400;break;case`7d`:o=i-604800;break;case`30d`:o=i-2592e3;break;default:o=i-86400;break}c.set(`range`,t)}r&&c.set(`country_code`,r),a&&c.set(`access_point_id`,a);try{let t=await K.queryISPs({profileId:e,countryCode:r||void 0,since:o,until:s,accessPointId:a||void 0});if(t&&t.length>0){m(t),y.current=b,g(!1);return}}catch(e){console.warn(`[IspFilter] Local SQLite query failed, falling back to server:`,e)}let l=await U(e,`isps`,c.toString());m(Array.isArray(l)?l:[]),y.current=b}catch(e){console.error(`Failed to fetch ISPs for filter`,e)}finally{g(!1)}},C=e=>{f(e),e?y.current!==b&&x():v(``)},w=(0,X.useMemo)(()=>{let e=_.trim().toLowerCase();return e?p.filter(t=>t.name.toLowerCase().includes(e)):p},[p,_]),E=(0,Z.jsxs)(`div`,{className:`w-72 flex flex-col p-1.5`,children:[(0,Z.jsx)(`div`,{className:`pb-1.5`,children:(0,Z.jsx)(N,{leftIcon:`search`,placeholder:u(`logs.searchIsp`,`Search ISP...`),value:_,onChange:e=>v(e.target.value),small:!0,autoFocus:!0,rightElement:_?(0,Z.jsx)(T,{icon:`cross`,variant:`minimal`,small:!0,onClick:()=>v(``)}):void 0})}),(0,Z.jsx)(S,{className:`max-h-64 overflow-y-auto`,children:h?(0,Z.jsxs)(`div`,{className:`flex items-center justify-center p-6 text-gray-500 gap-2`,children:[(0,Z.jsx)(D,{size:16}),(0,Z.jsx)(`span`,{className:`text-xs`,children:u(`logs.loadingIsps`,`Loading ISPs...`)})]}):(0,Z.jsxs)(Z.Fragment,{children:[!_&&(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(R,{icon:s===null?`tick`:void 0,text:u(`logs.allIsp`),onClick:()=>{c(null),f(!1)}}),(0,Z.jsx)(P,{})]}),w.length===0?(0,Z.jsx)(R,{disabled:!0,text:u(`logs.noMatchingIsps`,`No matching ISPs found`)}):w.map(e=>(0,Z.jsx)(R,{icon:s===e.name?`tick`:void 0,text:(0,Z.jsxs)(`span`,{className:`flex items-center justify-between gap-2 w-full`,children:[(0,Z.jsx)(`span`,{className:`truncate`,title:e.name,children:e.name}),(0,Z.jsx)(`span`,{className:`text-xs text-gray-400 shrink-0 font-mono`,children:e.count.toLocaleString()})]}),onClick:()=>{c(e.name),f(!1)}},e.name))]})})]}),O=s||u(`logs.allIsp`);return(0,Z.jsx)(A,{content:E,placement:`bottom-start`,isOpen:d,onInteraction:C,children:(0,Z.jsx)(T,{icon:(0,Z.jsx)(i,{size:14}),rightIcon:`caret-down`,intent:s?j.PRIMARY:j.NONE,text:O,variant:`outlined`,fill:l})})},he=({profileId:e,range:t,setRange:n,customRange:r,setCustomRange:i,nowStr:a,fetchLogs:s,isMobile:c,realtimeRefresh:l,setRealtimeRefresh:u,statusFilter:d,setStatusFilter:f,accessPointIdFilter:p,setAccessPointIdFilter:m,accessPoints:h,destCountryFilter:g,setDestCountryFilter:_,ispFilter:v,setIspFilter:y,searchQuery:b,setSearchQuery:x,stats:S,logRetentionDays:C,onExport:w,exporting:E,loading:D=!1,syncing:O=!1})=>{let{t:k}=o(),[A,M]=(0,X.useState)(!0),P=d!==null||p!==null||g!==null||v!==null;return(0,Z.jsxs)(`div`,{className:`p-4 ${c&&A?`space-y-0`:`space-y-4`} shrink-0 bg-white/50 dark:bg-gray-900/50 backdrop-blur-sm border-b border-gray-100 dark:border-gray-800`,children:[(0,Z.jsxs)(`div`,{className:`flex flex-col md:flex-row md:items-center justify-between gap-4`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center justify-between w-full md:w-auto`,children:[(0,Z.jsxs)(`div`,{children:[(0,Z.jsxs)(`h2`,{className:`bp6-heading flex flex-wrap items-center gap-2 text-xl md:text-2xl m-0`,children:[k(`logs.title`),` `,(!c||!A)&&(0,Z.jsx)(L,{minimal:!0,round:!0,children:t===`custom`?k(`analytics.custom`):t.toUpperCase()}),S&&(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(L,{minimal:!0,round:!0,children:S.total.toLocaleString()}),(0,Z.jsx)(L,{minimal:!0,round:!0,intent:j.SUCCESS,children:S.pass.toLocaleString()}),(0,Z.jsx)(L,{minimal:!0,round:!0,intent:j.DANGER,children:S.block.toLocaleString()}),(0,Z.jsx)(L,{minimal:!0,round:!0,intent:j.WARNING,children:S.redirect.toLocaleString()})]})]}),!c&&(0,Z.jsx)(`p`,{className:`bp6-text-muted mt-1`,children:k(`logs.subtitle`)})]}),c&&(0,Z.jsx)(T,{icon:A?`chevron-down`:`chevron-up`,variant:`minimal`,onClick:()=>M(!A)})]}),(!c||!A)&&(0,Z.jsxs)(`div`,{className:`flex flex-col items-stretch md:items-end gap-2`,children:[(0,Z.jsx)(le,{range:t,setRange:n,customRange:r,setCustomRange:i,nowStr:a,fetchLogs:s,isMobile:c,logRetentionDays:C}),(0,Z.jsxs)(`div`,{className:`flex items-center justify-end gap-4`,children:[(0,Z.jsx)(T,{icon:`download`,onClick:w,loading:E,title:k(`logs.export`,`Export Logs`),text:c?void 0:k(`logs.export`,`Export Logs`)}),(0,Z.jsx)(ee,{label:k(`logs.realtime`),checked:l,onChange:e=>u(e.target.checked),className:`mb-0!`}),(0,Z.jsx)(T,{icon:`refresh`,onClick:()=>s(t,!0,!1,!0),loading:D||O,variant:`minimal`,small:c})]})]})]}),(!c||!A)&&(0,Z.jsxs)(`div`,{className:`flex flex-col md:flex-row items-stretch md:items-center justify-between gap-3`,children:[(0,Z.jsxs)(`div`,{className:`grid grid-cols-2 md:flex md:items-center gap-2`,children:[P&&(0,Z.jsx)(`div`,{className:`col-span-2 md:contents`,children:(0,Z.jsx)(T,{icon:`filter-remove`,onClick:()=>{f(null),m(null),_(null),y(null)},variant:`minimal`,title:k(`logs.clearFilters`),text:c?k(`logs.clearFilters`):void 0,fill:c})}),(0,Z.jsx)(ue,{statusFilter:d,setStatusFilter:f,isMobile:c}),h.length>0&&(0,Z.jsx)(de,{accessPointIdFilter:p,setAccessPointIdFilter:m,accessPoints:h,isMobile:c}),(0,Z.jsx)(pe,{destCountryFilter:g,setDestCountryFilter:_,isMobile:c}),(0,Z.jsx)(me,{profileId:e,range:t,customRange:r,destCountryFilter:g,accessPointIdFilter:p,ispFilter:v,setIspFilter:y,isMobile:c})]}),(0,Z.jsx)(`div`,{className:`flex items-center gap-2 flex-1 md:max-w-md justify-end`,children:(0,Z.jsx)(`div`,{className:`flex-1 md:max-w-xs`,children:(0,Z.jsx)(N,{leftIcon:`search`,placeholder:k(`logs.searchPlaceholder`),value:b,onChange:e=>x(e.target.value),rightElement:b?(0,Z.jsx)(T,{icon:`cross`,minimal:!0,onClick:()=>x(``)}):void 0,fill:!0})})})]})]})},ge=({logs:e,setSelectedLog:t,setIsDrawerOpen:n,lastLogElementRef:r,prevLatestTimestamp:i,realtimeRefresh:a})=>{let{t:s}=o();return(0,Z.jsx)(`div`,{className:`space-y-3 py-4`,children:e.map((o,l)=>{let u=a&&i!==null&&o.timestamp>i,d=(o.encrypt_version??0)>0||!!(o.kem_key_id||o.encrypted_payload),f=d&&(!o.domain||o.domain===`[Encrypted]`),p=d&&!!(o.domain&&o.domain!==`[Encrypted]`);return(0,Z.jsxs)(z,{interactive:!0,onClick:()=>{t(o),n(!0)},className:V(`p-3 dark:bg-gray-900 rounded-xl border border-gray-200 dark:border-gray-800 shadow-sm overflow-hidden`,{"animate-row-glow":u}),ref:l===e.length-1?r:null,children:[(0,Z.jsxs)(`div`,{className:`flex justify-between items-start mb-2`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 min-w-0`,children:[f?(0,Z.jsx)(c,{size:14,className:`text-amber-500 shrink-0`}):(0,Z.jsx)(`img`,{src:`/api/icon/${o.domain.replace(/^\*\./,``)}.ico`,className:`w-4 h-4 rounded-sm shrink-0`,alt:``,referrerPolicy:`no-referrer`,onError:e=>e.currentTarget.style.opacity=`0`}),(0,Z.jsx)(`span`,{className:V(`font-bold text-sm truncate`,{"italic text-gray-400 dark:text-gray-500":f}),children:f?s(`logs.encryptedRecord`,`[加密记录]`):o.domain}),p&&(0,Z.jsx)(c,{size:12,className:`text-emerald-500 shrink-0 opacity-80`})]}),(0,Z.jsx)(L,{minimal:!0,round:!0,intent:o.action===`PASS`?j.SUCCESS:o.action===`BLOCK`?j.DANGER:j.WARNING,className:`text-[10px] shrink-0`,children:o.action})]}),(0,Z.jsxs)(`div`,{className:`flex justify-between items-center`,children:[(0,Z.jsxs)(`div`,{className:`flex gap-2 items-center`,children:[(0,Z.jsx)(`span`,{className:`text-[10px] font-mono opacity-50`,children:new Date(o.timestamp*1e3).toLocaleTimeString([],{hour12:!1})}),(0,Z.jsx)(`span`,{className:`text-[10px] bg-gray-100 dark:bg-gray-800 px-1 rounded opacity-60`,children:o.record_type}),o.access_point_name&&(0,Z.jsx)(`span`,{className:`text-[10px] opacity-50 truncate max-w-25`,children:o.access_point_name})]}),(0,Z.jsx)(`div`,{className:`text-[10px] opacity-40 font-mono italic`,children:o.latency?`${o.latency}ms`:``})]})]},o.id)})})},_e=({logs:e,setSelectedLog:t,setIsDrawerOpen:n,lastLogElementRef:r,prevLatestTimestamp:i,realtimeRefresh:a})=>{let{t:s}=o(),l=[{key:`time`,header:s(`logs.tableTime`),headerClassName:`w-24 rounded-tl-xl`,cellClassName:`font-mono text-[11px] opacity-60`,render:e=>new Date(e.timestamp*1e3).toLocaleTimeString([],{hour12:!1})},{key:`domain`,header:s(`logs.tableDomain`),headerClassName:`w-1/4`,render:e=>{let t=(e.encrypt_version??0)>0||!!(e.kem_key_id||e.encrypted_payload),n=t&&(!e.domain||e.domain===`[Encrypted]`),r=t&&!!(e.domain&&e.domain!==`[Encrypted]`);return(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 truncate`,children:[n?(0,Z.jsx)(c,{size:14,className:`text-amber-500 shrink-0`}):(0,Z.jsx)(`img`,{src:`/api/icon/${e.domain.replace(/^\*\./,``)}.ico`,className:`w-4 h-4 rounded-sm shrink-0`,alt:``,referrerPolicy:`no-referrer`}),(0,Z.jsx)(`span`,{className:V(`font-bold text-sm truncate`,{"italic text-gray-400 dark:text-gray-500":n}),children:n?s(`logs.encryptedRecord`,`[加密记录]`):e.domain}),r&&(0,Z.jsx)(`span`,{title:s(`settings.e2eeEnabled`,`已加密`),className:`inline-flex items-center`,children:(0,Z.jsx)(c,{size:12,className:`text-emerald-500 shrink-0 opacity-80`})})]})}},{key:`answer`,header:s(`logs.tableAnswer`),headerClassName:`w-1/4`,cellClassName:`truncate font-mono text-[11px] opacity-70`,render:e=>e.answer||`-`},{key:`source`,header:s(`logs.tableSource`),headerClassName:`w-32`,render:e=>(0,Z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Z.jsx)(L,{minimal:!0,className:`font-mono text-[10px]`,title:e.geo_country||`Unknown`,children:Y(e.geo_country)}),e.access_point_name&&(0,Z.jsx)(`span`,{className:`text-xs opacity-70 truncate max-w-20`,title:e.access_point_name,children:e.access_point_name})]})},{key:`type`,header:s(`logs.tableType`),headerClassName:`w-20`,cellClassName:`text-center`,render:e=>(0,Z.jsx)(`code`,{className:`text-[10px]`,children:e.record_type})},{key:`status`,header:s(`logs.tableStatus`),headerClassName:`w-28`,cellClassName:`text-center`,render:e=>(0,Z.jsx)(`span`,{className:V(`bp6-tag`,`bp6-fill`,`bp6-minimal`,`bp6-round`,{"bp6-intent-success":e.action===`PASS`,"bp6-intent-danger":e.action===`BLOCK`,"bp6-intent-warning":e.action===`REDIRECT`}),children:(0,Z.jsx)(`span`,{className:`bp6-text-overflow-ellipsis bp6-fill text-center`,children:e.action})})},{key:`reason`,header:s(`logs.tableReason`),headerClassName:`rounded-tr-xl`,cellClassName:`text-xs text-gray-500 italic truncate`,render:e=>e.reason||`-`}];return(0,Z.jsx)(`div`,{className:`min-w-full inline-block align-middle py-0`,children:(0,Z.jsx)(`div`,{className:`bg-white dark:bg-gray-900 rounded-xl border border-gray-200 dark:border-gray-800 shadow-sm overflow-visible`,children:(0,Z.jsxs)(te,{interactive:!0,striped:!0,className:`w-full table-fixed`,children:[(0,Z.jsx)(`thead`,{className:`sticky top-0 z-20 backdrop-blur-md`,children:(0,Z.jsx)(`tr`,{children:l.map(e=>(0,Z.jsx)(`th`,{className:V(`px-4 py-3 text-xs font-bold uppercase text-gray-500 bg-white/80 dark:bg-gray-900/80 border-b border-gray-100 dark:border-gray-800`,e.headerClassName),children:e.header},e.key))})}),(0,Z.jsx)(`tbody`,{className:`divide-y divide-gray-100 dark:divide-gray-800`,children:e.map((o,s)=>{let c=a&&i!==null&&o.timestamp>i;return(0,Z.jsx)(`tr`,{onClick:()=>{t(o),n(!0)},className:V(`cursor-pointer`,{"animate-row-glow":c}),ref:s===e.length-1?r:null,children:l.map(e=>(0,Z.jsx)(`td`,{className:V(`px-4 py-3`,e.cellClassName),children:e.render(o,s)},e.key))},o.id)})})]})})})},ve=({logs:e,loading:t,loadingMore:n,hasMore:r,realtimeRefresh:i,isMobile:a,searchQuery:s,scrollContainerRef:c,lastLogElementRef:l,prevLatestTimestamp:u,setSelectedLog:d,setIsDrawerOpen:f,logRetentionDays:p})=>{let{t:m}=o();return(0,Z.jsxs)(`div`,{ref:c,className:V(`flex-1 overflow-y-auto relative`,a?`px-1`:`px-4`),children:[e.length===0&&!t?(0,Z.jsx)(`div`,{className:`py-20`,children:(0,Z.jsx)(k,{title:p===0?m(`logs.loggingDisabledTitle`,`日志记录已关闭`):m(s?`logs.noResults`:`logs.noRecords`),icon:p===0?`disable`:s?`search`:`outdated`,intent:p===0?j.WARNING:j.NONE,children:p===0?m(`logs.loggingDisabledDesc`,`当前配置的日志留存已设置为“关闭”,系统不记录任何查询日志。如需查看,请在设置中启用日志留存。`):s?m(`logs.noResultsDesc`,{query:s}):m(`logs.noRecordsDesc`)})}):a?(0,Z.jsx)(ge,{logs:e,setSelectedLog:d,setIsDrawerOpen:f,lastLogElementRef:l,prevLatestTimestamp:u,realtimeRefresh:i}):(0,Z.jsx)(_e,{logs:e,setSelectedLog:d,setIsDrawerOpen:f,lastLogElementRef:l,prevLatestTimestamp:u,realtimeRefresh:i}),(0,Z.jsx)(`div`,{className:`p-6 flex flex-col items-center`,children:n?(0,Z.jsx)(D,{size:16}):i?e.length>0&&(0,Z.jsx)(`span`,{className:`text-[10px] opacity-30 italic`,children:m(`logs.realtimeLoadMoreTip`)}):!r&&e.length>0&&(0,Z.jsx)(`span`,{className:`text-[10px] opacity-30 italic`,children:m(`logs.loadedAll`,{count:e.length})})})]})};function ye(e,t,n){let[r,i]=(0,X.useState)(null),[a,o]=(0,X.useState)(!1);return(0,X.useEffect)(()=>{if(e&&t?.id){o(!0),i(t);let e=new AbortController;return ie(n,t.id,t.timestamp,{signal:e.signal}).then(async r=>{if(!e.signal.aborted)try{let e=r?.encrypt_version??t.encrypt_version,a=await G.decryptLogEntry(n,r);i(n=>({...n||t,...a,encrypt_version:e??a.encrypt_version}))}catch{i(e=>({...e||t,...r}))}}).catch(e=>{e.name!==`AbortError`&&(console.error(e),i(e=>e||t))}).finally(()=>{e.signal.aborted||o(!1)}),()=>{e.abort()}}else i(null)},[e,t?.id,n]),{detailedLog:r,loading:a}}const Q=({label:e,value:t,bold:n,italic:r})=>(0,Z.jsxs)(`div`,{className:`flex justify-between items-start gap-4`,children:[(0,Z.jsx)(`span`,{className:`text-xs opacity-50 mt-1`,children:e}),(0,Z.jsx)(`span`,{className:V(`text-sm text-right`,n&&`font-bold`,r&&`italic`),children:t})]}),be=({selectedLog:e,detailedLog:t,loading:r})=>{let{t:i}=o(),a=t?.encrypt_version??e.encrypt_version??(t?.kem_key_id||e.kem_key_id?2:0),s=a>0||!!(e.kem_key_id||e.encrypted_payload||t?.kem_key_id||t?.encrypted_payload),l=a===2||!!(e.kem_key_id||t?.kem_key_id),u=s&&(!e.domain||e.domain===`[Encrypted]`);return(0,Z.jsx)(F,{title:i(`logs.basicInfo`),icon:(0,Z.jsx)(n,{size:16}),className:`shadow-none! rounded-lg!`,children:(0,Z.jsx)(M,{children:(0,Z.jsxs)(`div`,{className:`space-y-3`,children:[(0,Z.jsx)(Q,{label:i(`logs.detailDomain`),value:(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 justify-end font-bold`,children:[u?(0,Z.jsx)(c,{size:14,className:`text-amber-500`}):(0,Z.jsx)(`img`,{src:`/api/icon/${e.domain.replace(/^\*\./,``)}.ico`,className:`w-4 h-4 rounded-sm`,alt:``,referrerPolicy:`no-referrer`,onError:e=>e.currentTarget.style.display=`none`}),(0,Z.jsx)(`span`,{className:V({"italic text-gray-400 dark:text-gray-500":u}),children:u?i(`logs.encryptedRecord`,`[加密记录]`):e.domain})]}),bold:!0}),(0,Z.jsx)(Q,{label:i(`logs.detailType`),value:e.record_type}),(0,Z.jsx)(Q,{label:i(`logs.detailLatency`),value:e.latency?`${e.latency} ms`:`-`}),(0,Z.jsx)(Q,{label:i(`logs.detailAccessPoint`),value:(()=>{let n=t?.access_point_name||e.access_point_name,i=t?.access_point_id||e.access_point_id;return n?i&&i!==n?(0,Z.jsx)(`span`,{title:i,className:`cursor-help`,children:n}):n:i?(0,Z.jsx)(`span`,{className:`font-mono text-xs`,children:i}):r?(0,Z.jsx)(D,{size:12}):`-`})()}),(0,Z.jsx)(Q,{label:i(`logs.detailProfile`),value:t?.profile_name||t?.client_ip||e.client_ip||(r?(0,Z.jsx)(D,{size:12}):`-`)}),(0,Z.jsx)(Q,{label:i(`logs.detailTime`),value:ae(new Date(e.timestamp*1e3))}),(0,Z.jsx)(Q,{label:i(`logs.detailStatus`),value:(0,Z.jsx)(L,{minimal:!0,intent:e.action===`PASS`?j.SUCCESS:e.action===`BLOCK`?j.DANGER:j.WARNING,children:e.action})}),(0,Z.jsx)(Q,{label:i(`logs.detailUpstream`),value:t?.upstream||e.upstream||(r?(0,Z.jsx)(D,{size:12}):`-`)}),(0,Z.jsx)(Q,{label:i(`logs.detailReason`),value:e.reason||i(`logs.detailNoReason`),italic:!0}),(0,Z.jsx)(Q,{label:i(`logs.detailECS`),value:t?.ecs||e.ecs||(r?(0,Z.jsx)(D,{size:12}):`-`),italic:!0}),(0,Z.jsx)(Q,{label:i(`logs.detailIsClientEncrypted`,`是否用户端加密`),value:s?(0,Z.jsxs)(`div`,{className:`flex items-center gap-1.5 justify-end`,children:[(0,Z.jsx)(c,{size:13,className:u?`text-amber-500`:`text-emerald-500`}),(0,Z.jsxs)(`span`,{className:V(`text-xs font-medium`,u?`text-amber-600 dark:text-amber-400`:`text-emerald-600 dark:text-emerald-400`),children:[u?i(`logs.encryptedLocked`,`是 (未解锁)`):i(`logs.encryptedYes`,`是`),l?` (PQC)`:``]})]}):(0,Z.jsx)(`span`,{className:`text-xs text-gray-400 dark:text-gray-500`,children:i(`logs.notEncrypted`,`否`)})})]})})})},xe=({selectedLog:e})=>{let{t}=o(),n=e.record_type===`HTTPS`||e.record_type===`SVCB`||e.record_type===`TYPE65`||e.record_type===`TYPE64`,r=n&&(e.reason===`ECH Rewritten`||(e.reason?.toLowerCase().includes(`rewritten`)??!1));return(0,Z.jsx)(F,{title:(0,Z.jsxs)(`div`,{className:`flex items-center justify-between w-full pr-2`,children:[(0,Z.jsx)(`span`,{children:t(`logs.resolutionResult`)}),r&&(0,Z.jsx)(L,{minimal:!0,intent:j.PRIMARY,className:`text-xs`,children:t(`logs.rewritten`,`已重写`)})]}),icon:(0,Z.jsx)(h,{size:16}),className:`shadow-none! rounded-lg!`,children:(0,Z.jsx)(M,{children:(0,Z.jsx)(`div`,{className:`bg-gray-50 dark:bg-gray-800 p-3 font-mono text-xs break-all leading-relaxed rounded-lg`,children:(()=>{if(!e.answer)return t(`logs.noResult`);let r=e.answer.split(`
3
- `).map(e=>e.trim()).filter(Boolean);return r.length===0?t(`logs.noResult`):(0,Z.jsx)(`div`,{className:`space-y-2`,children:r.map((e,t)=>{let r=e.match(/^(\d+)\s+([^\s]+)(?:\s+(.*))?$/);if(r&&(n||e.includes(`alpn=`)||e.includes(`ech=`)||e.includes(`ipv4hint=`))){let e=r[1],n=r[2],i=(r[3]||``).split(/\s+/).filter(Boolean);return(0,Z.jsxs)(`div`,{className:`bg-white dark:bg-gray-900 p-2.5 rounded-md space-y-2 border border-gray-200 dark:border-gray-700`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 text-xs`,children:[(0,Z.jsxs)(L,{minimal:!0,intent:j.PRIMARY,children:[`Priority `,e]}),(0,Z.jsxs)(`span`,{className:`font-semibold text-gray-700 dark:text-gray-300`,children:[`Target: `,n]})]}),i.length>0&&(0,Z.jsx)(`div`,{className:`flex flex-wrap gap-1.5 pt-1 border-t border-gray-100 dark:border-gray-800 text-xs`,children:i.map((e,t)=>{let n=e.indexOf(`=`);if(n===-1)return(0,Z.jsx)(L,{minimal:!0,className:`font-mono`,children:e},t);let r=e.substring(0,n),i=e.substring(n+1);return r===`ech`?(0,Z.jsxs)(L,{minimal:!0,intent:j.SUCCESS,className:`font-mono break-all max-w-full select-all text-left whitespace-normal h-auto py-1 inline-block`,title:i,children:[(0,Z.jsx)(`span`,{className:`font-bold`,children:`ech:`}),` `,i]},t):r===`alpn`?(0,Z.jsxs)(L,{minimal:!0,intent:j.WARNING,className:`font-mono`,children:[(0,Z.jsx)(`span`,{className:`font-bold`,children:`alpn:`}),` `,i]},t):(0,Z.jsxs)(L,{minimal:!0,className:`font-mono`,children:[(0,Z.jsxs)(`span`,{className:`font-bold`,children:[r,`:`]}),` `,i]},t)})})]},t)}return(0,Z.jsx)(`div`,{className:`space-y-1`,children:e.split(`,`).map(e=>e.trim()).filter(Boolean).map((e,t)=>(0,Z.jsx)(`div`,{className:`text-xs font-mono text-gray-800 dark:text-gray-200 select-all`,children:e},t))},t)})})})()})})})},Se=({selectedLog:e,detailedLog:t,loading:n})=>{let{t:r,i18n:i}=o(),a=t?.client_ip||e.client_ip,s=t?.geo_country||e.geo_country,c=`Unknown`;if(s){let e=s.toUpperCase().trim();c=e===`LAN`||e===`LOCAL`||e===`PRIVATE`||e===`PRIVATE NETWORK`?r(`setup.privateNetwork`,`Private Network`):e===`UN`||e===`UNKNOWN`||e===`XX`?r(`common.unknown`,`Unknown`):J(s,i.language)||s}let u=t?.dest_country_code||e.dest_country_code,d=t?.dest_country||e.dest_country,f=t?.dest_isp||e.dest_isp,p=null,h=t?.dest_geoip||e.dest_geoip;if(h)try{let e=JSON.parse(h);!u&&e.country_code&&(u=e.country_code);let t=[e.city,e.region,e.country].filter(Boolean),n=d||u||void 0;p={locationTitle:t.length>0?t.join(`, `):n,isp:e.isp||f||void 0,as:e.as||void 0}}catch{}return!p&&(d||u||f)&&(p={locationTitle:d||u||void 0,isp:f||void 0}),(0,Z.jsx)(F,{title:r(`logs.networkDetails`),icon:(0,Z.jsx)(l,{size:16}),className:`shadow-none! rounded-lg!`,children:(0,Z.jsx)(M,{children:(0,Z.jsxs)(`div`,{className:`space-y-4`,children:[(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`div`,{className:`text-[10px] uppercase font-bold opacity-50 mb-1`,children:r(`logs.clientSource`)}),(0,Z.jsxs)(`div`,{className:`flex justify-between items-center`,children:[(0,Z.jsx)(`span`,{className:`font-mono`,children:a||(n?(0,Z.jsx)(D,{size:12}):`-`)}),(s||n)&&(0,Z.jsx)(L,{minimal:!0,title:c,children:s?Y(s):`-`})]})]}),(0,Z.jsxs)(`div`,{children:[(0,Z.jsxs)(`div`,{className:`flex justify-between items-center mb-1`,children:[(0,Z.jsx)(`div`,{className:`text-[10px] uppercase font-bold opacity-50`,children:r(`logs.destination`)}),(u||n)&&(0,Z.jsx)(L,{minimal:!0,title:d||u||`Unknown`,children:u?Y(u):`-`})]}),n&&!p?(0,Z.jsx)(`div`,{className:`flex items-center justify-center py-2`,children:(0,Z.jsx)(D,{size:16})}):p?(0,Z.jsx)(`div`,{className:`bg-gray-50 dark:bg-gray-800 p-3 rounded-lg mt-1`,children:(0,Z.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,Z.jsx)(m,{size:16,className:`oklch(60.9% 0.126 221.723) mt-1 shrink-0`}),(0,Z.jsxs)(`div`,{children:[p.locationTitle&&(0,Z.jsx)(`div`,{className:`font-bold text-sm`,children:p.locationTitle}),(p.isp||p.as)&&(0,Z.jsxs)(`div`,{className:`text-xs opacity-70 mt-1`,children:[p.isp,p.as&&(0,Z.jsx)(`span`,{className:`opacity-60 block mt-0.5`,children:p.as})]})]})]})}):(0,Z.jsx)(`div`,{className:`text-xs opacity-50 py-1`,children:`-`})]})]})})})},Ce=({selectedLog:e,onQuickAction:n})=>{let{t:r}=o(),i=(e.encrypt_version??0)>0&&(!e.domain||e.domain===`[Encrypted]`);return(0,Z.jsx)(F,{title:r(`logs.quickActions`),icon:(0,Z.jsx)(s,{size:16}),className:`shadow-none! rounded-lg!`,children:(0,Z.jsx)(M,{children:i?(0,Z.jsx)(`p`,{className:`text-xs text-center text-gray-500 italic py-2 m-0`,children:r(`settings.e2eeUnlockPrompt`,`此记录已加密,请先解锁私钥后再进行操作。`)}):(0,Z.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,Z.jsx)(T,{fill:!0,intent:j.SUCCESS,icon:(0,Z.jsx)(t,{size:16}),text:r(`logs.actionAllow`),onClick:()=>n?.(e.domain,`ALLOW`)}),(0,Z.jsx)(T,{fill:!0,intent:j.DANGER,icon:(0,Z.jsx)(d,{size:16}),text:r(`logs.actionBlock`),onClick:()=>n?.(e.domain,`BLOCK`)}),(0,Z.jsx)(T,{fill:!0,icon:(0,Z.jsx)(_,{size:16}),text:r(`logs.actionRedirect`),onClick:()=>n?.(e.domain,`REDIRECT`,e.record_type)})]})})})},we=({isDrawerOpen:e,setIsDrawerOpen:t,selectedLog:r,profileId:i,isMobile:a,onQuickAction:s})=>{let{t:c}=o(),{detailedLog:l,loading:u}=ye(e,r,i);return(0,Z.jsx)(ce,{isOpen:e&&r!==null,onClose:()=>t(!1),title:(0,Z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Z.jsx)(n,{size:18}),(0,Z.jsx)(`span`,{children:c(`logs.logDetails`)})]}),icon:`info-sign`,size:a?`100%`:`450px`,children:r&&(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(be,{selectedLog:r,detailedLog:l,loading:u}),(0,Z.jsx)(xe,{selectedLog:r}),(0,Z.jsx)(Se,{selectedLog:r,detailedLog:l,loading:u}),(0,Z.jsx)(Ce,{selectedLog:r,onQuickAction:s})]})})},Te=({isMobile:e,unlocking:t,onUnlockPasskey:n,onOpenRecoveryDialog:r})=>{let{t:i}=o();return(0,Z.jsx)(`div`,{className:V(`mb-2 shrink-0`,e?`px-2`:`px-4`),children:(0,Z.jsx)(k,{intent:j.PRIMARY,icon:`lock`,title:i(`settings.e2eeTitle`,`端到端加密日志`),children:(0,Z.jsxs)(`div`,{className:`flex flex-col sm:flex-row sm:items-center justify-between gap-3 mt-1`,children:[(0,Z.jsx)(`p`,{className:`text-xs opacity-80 m-0`,children:i(`settings.e2eeUnlockPrompt`,`日志已通过端到端加密保护。请验证已授权的硬件 Passkey 或输入紧急恢复密钥以在本地解密。`)}),(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 flex-wrap shrink-0`,children:[(0,Z.jsx)(T,{intent:j.PRIMARY,icon:`key`,small:!0,loading:t,onClick:n,className:`font-medium`,children:i(`settings.e2eeUnlockNow`,`验证 Passkey 解锁`)}),(0,Z.jsx)(T,{intent:j.NONE,icon:(0,Z.jsx)(a,{size:14}),small:!0,disabled:t,onClick:r,className:`font-medium`,children:i(`settings.e2eeUnlockRecovery`,`使用恢复密钥解锁`)})]})]})})})},Ee=({isOpen:e,onClose:t,recoveryKeyInput:n,setRecoveryKeyInput:r,recoveryError:i,unlocking:a,onSubmit:s})=>{let{t:c}=o();return(0,Z.jsx)(E,{isOpen:e,onClose:t,title:c(`account.e2ee.unlockWithRecoveryTitle`,`使用恢复密钥解锁`),icon:`key`,className:`dark:bg-gray-900`,children:(0,Z.jsxs)(`form`,{onSubmit:s,autoComplete:`off`,children:[(0,Z.jsxs)(`div`,{className:C,children:[(0,Z.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-gray-400 mb-3`,children:c(`account.e2ee.unlockWithRecoveryDesc`,`请输入 30 位紧急恢复密钥。注意:根据单次使用规则,恢复密钥验证成功后将立即自动轮换。`)}),i&&(0,Z.jsx)(k,{intent:j.DANGER,className:`mb-3 text-xs`,children:i}),(0,Z.jsx)(I,{label:c(`account.e2ee.recoveryKeyInputLabel`,`恢复密钥`),labelFor:`recovery-key-input-logs`,children:(0,Z.jsx)(N,{id:`recovery-key-input-logs`,name:`recovery_key_input_logs`,autoComplete:`off`,autoCorrect:`off`,autoCapitalize:`off`,spellCheck:!1,"data-1p-ignore":`true`,"data-lpignore":`true`,"data-bwignore":`true`,placeholder:`123456-789012-345678-901234-567890`,value:n,onChange:e=>r(e.target.value),leftIcon:`key`,className:`font-mono text-xs`,autoFocus:!0})})]}),(0,Z.jsx)(`div`,{className:O,children:(0,Z.jsxs)(`div`,{className:B,children:[(0,Z.jsx)(T,{onClick:t,text:c(`common.cancel`,`取消`)}),(0,Z.jsx)(T,{type:`submit`,intent:j.PRIMARY,loading:a,disabled:!n.trim(),text:c(`account.e2ee.unlockConfirm`,`解锁日志`)})]})})]})})},De=({rotatedKey:e,onClose:t,copiedKey:n,onCopyKey:r})=>{let{t:i}=o();return(0,Z.jsxs)(E,{isOpen:!!e,onClose:t,title:i(`account.recoveryKey.autoRotatedTitle`,`恢复密钥已自动轮换`),icon:`warning-sign`,isCloseButtonShown:!1,canOutsideClickClose:!1,className:`dark:bg-gray-900`,children:[(0,Z.jsxs)(`div`,{className:C,children:[(0,Z.jsx)(k,{intent:j.WARNING,icon:(0,Z.jsx)(d,{size:16}),className:`mb-4 text-xs`,children:i(`account.recoveryKey.autoRotatedNotice`,`根据恢复密钥单次使用规则,您的原恢复密钥已失效,系统已为您生成全新 30 位紧急恢复密钥。请务必立即复制并妥善离线保存,关闭后将无法再次查看!`)}),e&&(0,Z.jsxs)(`div`,{className:`space-y-3`,children:[(0,Z.jsx)(`div`,{className:`p-3 bg-gray-100 dark:bg-gray-800 rounded border border-gray-200 dark:border-gray-700 font-mono text-center text-lg font-bold tracking-widest select-all text-gray-900 dark:text-gray-100`,children:e}),(0,Z.jsx)(`div`,{className:`flex justify-center`,children:(0,Z.jsx)(T,{intent:j.PRIMARY,icon:n?(0,Z.jsx)(u,{size:14,className:`text-green-400`}):(0,Z.jsx)(f,{size:14}),text:n?i(`common.copied`,`已复制`):i(`common.copyKey`,`复制新恢复密钥`),onClick:()=>r(e)})})]})]}),(0,Z.jsx)(`div`,{className:O,children:(0,Z.jsx)(`div`,{className:B,children:(0,Z.jsx)(T,{intent:j.SUCCESS,onClick:t,text:i(`account.recoveryKey.savedAndClose`,`我已妥善保存并继续`)})})})]})};function Oe(e){let[t,n]=(0,X.useState)(`24h`),[r,i]=(0,X.useState)({start:``,end:``}),[a,o]=(0,X.useState)(null),[s,c]=(0,X.useState)(null),[l,u]=(0,X.useState)([]),[d,f]=(0,X.useState)(null),[p,m]=(0,X.useState)(null),[h,g]=(0,X.useState)(``);return(0,X.useEffect)(()=>{H(e).then(u).catch(console.error)},[e]),(0,X.useEffect)(()=>{m(null)},[d]),{range:t,setRange:n,customRange:r,setCustomRange:i,statusFilter:a,setStatusFilter:o,accessPointIdFilter:s,setAccessPointIdFilter:c,accessPoints:l,destCountryFilter:d,setDestCountryFilter:f,ispFilter:p,setIspFilter:m,searchQuery:h,setSearchQuery:g}}function ke(e){let[t,n]=(0,X.useState)(30);return(0,X.useEffect)(()=>{re(e).then(e=>{try{let t=JSON.parse(e.settings||`{}`);n(t.log_retention_days===void 0?30:Number(t.log_retention_days))}catch(e){console.error(`[useProfileRetention] Failed to parse settings:`,e)}}).catch(e=>console.error(`[useProfileRetention] Failed to fetch profile details:`,e))},[e]),t}function Ae(e,t){let n=Math.floor(Date.now()/1e3);if(e===`custom`&&t.start&&t.end)return{since:Math.floor(new Date(t.start).getTime()/1e3),until:Math.floor(new Date(t.end).getTime()/1e3)};let r;switch(e){case`10m`:r=n-600;break;case`1h`:r=n-3600;break;case`24h`:r=n-86400;break;case`7d`:r=n-604800;break;case`30d`:r=n-2592e3;break;default:r=n-86400;break}return{since:r,until:n}}function je(e){if(!(!e||e.length===0)&&`serviceWorker`in navigator&&navigator.serviceWorker.controller){let t=Array.from(new Set(e.map(e=>e.domain)));navigator.serviceWorker.controller.postMessage({type:`PREFETCH_ICONS`,domains:t})}}async function Me(e){let{profileId:t,currentRange:n,customRange:r,since:i,until:a,limit:o,isInitial:s,statusFilter:c,accessPointIdFilter:l,destCountryFilter:u,ispFilter:d,searchQuery:f,lastTimestamp:p,signal:m}=e,h=new URLSearchParams({range:n,limit:String(o)});n===`custom`&&r.start&&r.end&&(h.set(`start`,String(i)),h.set(`end`,String(a))),c&&h.set(`status`,c),l&&h.set(`access_point_id`,l),u&&h.set(`dest_country`,u),d&&h.set(`isp`,d),f&&h.set(`search`,f),!s&&p!==void 0&&h.set(`before`,String(p));let g=se(t,h.toString(),{signal:m}),_=Promise.resolve(null);if(s){let e=new URLSearchParams({range:n});n===`custom`&&r.start&&r.end&&(e.set(`start`,String(i)),e.set(`end`,String(a))),f&&e.set(`search`,f),_=U(t,`summary`,e.toString(),{signal:m})}let[v,y]=await Promise.all([g,_]),b=null;if(y){let e={total:0,pass:0,block:0,redirect:0};y.forEach(t=>{let n=t.count;e.total+=n,t.action===`PASS`?e.pass=n:t.action===`BLOCK`?e.block=n:t.action===`REDIRECT`&&(e.redirect=n)}),b=e}return{logs:v||[],stats:b}}async function Ne(e,t,n,r){if(!await K.init()||t.aborted)return{success:!1};let{profileId:i,searchQuery:a,statusFilter:o,accessPointIdFilter:s,destCountryFilter:c,ispFilter:l,since:u,until:d,limit:f}=e,p=await K.queryLogs({profileId:i,search:a||void 0,action:o||void 0,accessPointId:s||void 0,destCountry:c||void 0,isp:l||void 0,since:u,until:d,before:void 0,limit:f,offset:0});if(t.aborted)return{success:!1};p.rows.length>0&&r&&r({rows:p.rows,hasMore:p.rows.length>=f,stats:p.stats});try{let e=await K.syncProfileLogs(i,void 0,u,t,n);if(!t.aborted&&(e>0||p.rows.length===0)&&(p=await K.queryLogs({profileId:i,search:a||void 0,action:o||void 0,accessPointId:s||void 0,destCountry:c||void 0,isp:l||void 0,since:u,until:d,before:void 0,limit:f,offset:0}),t.aborted))return{success:!1}}catch(e){e.name!==`AbortError`&&console.warn(`[localDbStrategy] Incremental sync error:`,e)}return p.rows.length>0?{success:!0,result:{rows:p.rows,hasMore:p.rows.length>=f,stats:p.stats}}:{success:!1}}async function Pe(e,t,n){if(!await K.init()||n.aborted)return{success:!1};let{profileId:r,searchQuery:i,statusFilter:a,accessPointIdFilter:o,destCountryFilter:s,ispFilter:c,since:l,until:u,limit:d}=e,f=await K.queryLogs({profileId:r,search:i||void 0,action:a||void 0,accessPointId:o||void 0,destCountry:s||void 0,isp:c||void 0,since:l,until:u,before:t,limit:d,offset:0});if(n.aborted)return{success:!1};if(f.rows.length>=d)return{success:!0,result:{rows:f.rows,hasMore:f.rows.length>=d}};if(t>l)try{let e=await K.backfillLogs(r,t,l,d,n);if(n.aborted)return{success:!1};if(e.length>0){let f=await K.queryLogs({profileId:r,search:i||void 0,action:a||void 0,accessPointId:o||void 0,destCountry:s||void 0,isp:c||void 0,since:l,until:u,before:t,limit:d,offset:0});return n.aborted?{success:!1}:{success:!0,result:{rows:f.rows,hasMore:f.rows.length>=d&&e.length>=d}}}return{success:!0,result:{rows:f.rows,hasMore:!1}}}catch(e){return e.name!==`AbortError`&&console.warn(`[localDbStrategy] Backfill error:`,e),{success:!0,result:{rows:f.rows,hasMore:!1}}}return{success:!0,result:{rows:f.rows,hasMore:!1}}}function Fe({profileId:e,range:t,customRange:n,statusFilter:r,accessPointIdFilter:i,destCountryFilter:a,ispFilter:o,searchQuery:s,realtimeRefresh:c}){let[l,u]=(0,X.useState)([]),[d,f]=(0,X.useState)(!0),[p,m]=(0,X.useState)(!1),[h,g]=(0,X.useState)(!1),[_,v]=(0,X.useState)(!0),[y,b]=(0,X.useState)(null),[x,S]=(0,X.useState)(null),C=(0,X.useRef)([]);(0,X.useEffect)(()=>{C.current=l},[l]);let w=(0,X.useRef)(null),T=(0,X.useRef)(!1);return(0,X.useEffect)(()=>()=>{w.current&&w.current.abort()},[]),{logs:l,setLogs:u,loading:d,loadingMore:p,syncing:h,hasMore:_,setHasMore:v,stats:y,setStats:b,prevLatestTimestamp:x,setPrevLatestTimestamp:S,fetchLogs:(0,X.useCallback)(async(t,l=!0,d=!1,p=!1)=>{w.current&&w.current.abort();let h=new AbortController;w.current=h,T.current=!0,l?f(!0):m(!0);try{let _=c?25:50,{since:y,until:x}=Ae(t,n),E={profileId:e,searchQuery:s,statusFilter:r,accessPointIdFilter:i,destCountryFilter:a,ispFilter:o,since:y,until:x,limit:_},D=!1;if(l){d||g(!0);let e=await Ne(E,h.signal,p,e=>{D=!0,S(d&&C.current.length>0?C.current[0].timestamp:null),u(e.rows),v(c?!1:e.hasMore),c&&e.rows.length>0&&W.updateCursor(e.rows[0].timestamp,e.rows[0].id),e.stats&&b(e.stats),f(!1)});if(h.signal.aborted)return;e.success&&e.result&&(D=!0,S(d&&C.current.length>0?C.current[0].timestamp:null),u(e.result.rows),v(c?!1:e.result.hasMore),c&&e.result.rows.length>0&&W.updateCursor(e.result.rows[0].timestamp,e.result.rows[0].id),e.result.stats&&b(e.result.stats))}else{let e=C.current.length>0?C.current[C.current.length-1].timestamp:void 0;if(e!==void 0){let t=await Pe(E,e,h.signal);if(h.signal.aborted)return;t.success&&t.result&&(D=!0,u(e=>[...e,...t.result.rows]),v(c?!1:t.result.hasMore))}else D=!0,v(!1)}if(D){je(C.current),w.current===h&&(f(!1),m(!1),g(!1),T.current=!1);return}let O=await Me({profileId:e,currentRange:t,customRange:n,since:y,until:x,limit:_,isInitial:l,statusFilter:r,accessPointIdFilter:i,destCountryFilter:a,ispFilter:o,searchQuery:s,lastTimestamp:!l&&C.current.length>0?C.current[C.current.length-1].timestamp:void 0,signal:h.signal});if(h.signal.aborted)return;l?(S(d&&C.current.length>0?C.current[0].timestamp:null),u(O.logs),v(c?!1:O.logs.length>=_),O.stats&&b(O.stats)):(u(e=>[...e,...O.logs]),v(c?!1:O.logs.length>=_)),O.logs.length>0&&(c&&W.updateCursor(O.logs[0].timestamp,O.logs[0].id),je(O.logs))}catch(e){e.name!==`AbortError`&&console.error(e)}finally{w.current===h&&(f(!1),m(!1),g(!1),T.current=!1)}},[e,c,n,s,r,i,a,o]),isFetchingRef:T,logsRef:C}}function Ie({realtimeRefresh:e,statusFilter:t,accessPointIdFilter:n,destCountryFilter:r,ispFilter:i,searchQuery:a,pageSize:o,logsRef:s,setLogs:c,setStats:l,setPrevLatestTimestamp:u}){(0,X.useEffect)(()=>{if(e)return W.onNewLogs(e=>{if(!e||e.length===0)return;let d=e.filter(e=>{if(t&&e.action!==t||n&&e.access_point_id!==n||r&&(e.dest_country_code||e.dest_country)!==r||i&&e.dest_isp!==i)return!1;if(a){let t=a.toLowerCase(),n=e.domain?.toLowerCase().includes(t),r=e.client_ip?.toLowerCase().includes(t),i=e.reason?.toLowerCase().includes(t);if(!n&&!r&&!i)return!1}return!0});d.length!==0&&(u(s.current.length>0?s.current[0].timestamp:null),c(e=>{let t=new Set(e.map(e=>`${e.timestamp}-${e.id}`)),n=d.filter(e=>!t.has(`${e.timestamp}-${e.id}`));return n.length===0?e:[...n,...e].slice(0,o)}),l(t=>{if(!t)return t;let n=0,r=0,i=0;for(let t of e)t.action===`PASS`?n++:t.action===`BLOCK`?r++:t.action===`REDIRECT`&&i++;return{total:t.total+e.length,pass:t.pass+n,block:t.block+r,redirect:t.redirect+i}}))})},[e,t,n,r,i,a,o,s,c,l,u])}function Le({profileId:e,range:t,customRange:n,statusFilter:r,accessPointIdFilter:i,destCountryFilter:a,ispFilter:o,searchQuery:s,realtimeRefresh:c}){let l=ke(e),{logs:u,setLogs:d,loading:f,loadingMore:p,syncing:m,hasMore:h,stats:g,setStats:_,prevLatestTimestamp:v,setPrevLatestTimestamp:y,fetchLogs:b,isFetchingRef:x,logsRef:S}=Fe({profileId:e,range:t,customRange:n,statusFilter:r,accessPointIdFilter:i,destCountryFilter:a,ispFilter:o,searchQuery:s,realtimeRefresh:c});Ie({realtimeRefresh:c,statusFilter:r,accessPointIdFilter:i,destCountryFilter:a,ispFilter:o,searchQuery:s,pageSize:25,logsRef:S,setLogs:d,setStats:_,setPrevLatestTimestamp:y});let C=(0,X.useRef)(null),w=(0,X.useRef)(null),T=(0,X.useCallback)(()=>{c||x.current||f||p||!h||b(t,!1)},[f,p,h,t,c,b,x]),E=(0,X.useCallback)(e=>{w.current&&w.current.disconnect(),!(f||p||c||!h)&&(w.current=new IntersectionObserver(e=>{e[0]?.isIntersecting&&h&&!x.current&&T()},{root:C.current,rootMargin:`100px`}),e&&w.current.observe(e))},[f,p,h,T,c,x]);return(0,X.useEffect)(()=>{if(t===`custom`&&(!n.start||!n.end))return;let e=setTimeout(()=>{b(t,!0)},s?500:0);return()=>clearTimeout(e)},[t,n.start,n.end,s,b]),{logs:u,loading:f,loadingMore:p,syncing:m,hasMore:h,stats:g,logRetentionDays:l,prevLatestTimestamp:v,scrollContainerRef:C,lastLogElementRef:E,fetchLogs:b,isFetchingRef:x,logsRef:S}}function Re({profileId:e,range:t,searchQuery:n,realtimeRefresh:r,scrollContainerRef:i,isFetchingRef:a,fetchLogs:o,logsRef:s}){let c=(0,X.useRef)({range:t,searchQuery:n,fetchLogs:o,logsRef:s});(0,X.useEffect)(()=>{c.current={range:t,searchQuery:n,fetchLogs:o,logsRef:s}}),(0,X.useEffect)(()=>{if(!r){W.disconnect();return}let t=!1,n=null,o=()=>{n||=setInterval(()=>{let{range:e,searchQuery:n,fetchLogs:r}=c.current;!t&&document.visibilityState===`visible`&&i.current&&i.current.scrollTop<50&&!a.current&&!n&&e!==`custom`&&r(e,!0,!0)},8e3)},s=()=>{n&&=(clearInterval(n),null)},l=W.onStatusChange(e=>{t=e,e?s():o()}),u=c.current.logsRef.current,d=u.length>0?u[0]:null,f=d?d.timestamp:Math.floor(Date.now()/1e3)-60,p=d?d.id:0;W.connect(e,f,p);let m=setTimeout(()=>{t||o()},2500),h=()=>{if(document.visibilityState===`visible`)if(t){let e=c.current.logsRef.current,t=e.length>0?e[0]:null;t&&W.updateCursor(t.timestamp,t.id)}else{let{range:e,fetchLogs:t}=c.current;t(e,!0,!0)}};return document.addEventListener(`visibilitychange`,h),()=>{clearTimeout(m),s(),l(),W.disconnect(),document.removeEventListener(`visibilitychange`,h)}},[e,r])}function $(e){let t=new Date(e*1e3),n=-t.getTimezoneOffset(),r=n>=0?`+`:`-`,i=e=>String(e).padStart(2,`0`);return t.getFullYear()+`-`+i(t.getMonth()+1)+`-`+i(t.getDate())+`T`+i(t.getHours())+`:`+i(t.getMinutes())+`:`+i(t.getSeconds())+`.`+(e=>String(e).padStart(3,`0`))(t.getMilliseconds())+(n===0?`Z`:r+i(Math.floor(Math.abs(n)/60))+`:`+i(Math.abs(n)%60))}function ze(e){let t=[`profile_id`,`access_point_id`,`time`,`client_ip`,`geo_country`,`domain`,`record_type`,`action`,`reason`,`answer`,`dest_geoip`,`ecs`,`upstream`,`latency`],n=[t.join(`,`)];for(let r of e){let e=t.map(e=>{let t=``;t=e===`time`?$(r.timestamp):r[e]!==null&&r[e]!==void 0?String(r[e]):``;let n=t.replace(/"/g,`""`);return n.includes(`,`)||n.includes(`
4
- `)||n.includes(`\r`)||n.includes(`"`)?`"${n}"`:n});n.push(e.join(`,`))}return n.join(`
5
- `)}function Be(e,t){let n=new Blob([e],{type:`text/csv;charset=utf-8;`}),r=URL.createObjectURL(n),i=document.createElement(`a`);i.setAttribute(`href`,r),i.setAttribute(`download`,t),document.body.appendChild(i),i.click(),document.body.removeChild(i),URL.revokeObjectURL(r)}function Ve(e,t,n,r){return`query_logs_${e}_${$(t)}_${$(n)}_${r.toString()}.csv`}function He({profileId:e,range:t,customRange:n,statusFilter:r,accessPointIdFilter:i,destCountryFilter:a,ispFilter:s,searchQuery:c,toasterRef:l}){let{t:u}=o(),[d,f]=(0,X.useState)(!1);return{exporting:d,handleExportLogs:async()=>{f(!0);try{let o=new URLSearchParams({range:t});if(t===`custom`&&n.start&&n.end){let e=Math.floor(new Date(n.start).getTime()/1e3),t=Math.floor(new Date(n.end).getTime()/1e3);o.set(`start`,String(e)),o.set(`end`,String(t))}r&&o.set(`status`,r),i&&o.set(`access_point_id`,i),a&&o.set(`dest_country`,a),s&&o.set(`isp`,s),c&&o.set(`search`,c);let{exportProfileLogs:d}=await b(async()=>{let{exportProfileLogs:e}=await import(`./services-BYhiWUn8.js`);return{exportProfileLogs:e}},__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10])),f=await d(e,o.toString());if(!f||f.length===0){l?.current?.show({message:u(`logs.noResults`,`No logs found to export`),intent:j.WARNING});return}Be(ze(f),Ve(e,f[0].timestamp,f[f.length-1].timestamp,o)),l?.current?.show({message:u(`logs.exportSuccess`,`Logs exported successfully`),intent:j.SUCCESS})}catch(e){console.error(`Failed to export logs`,e),l?.current?.show({message:u(`logs.exportError`,`Failed to export logs`),intent:j.DANGER})}finally{f(!1)}}}}function Ue({profileId:e,toasterRef:t}){let[n,r]=(0,X.useState)(!1),i=Oe(e),a=Le({profileId:e,realtimeRefresh:n,range:i.range,customRange:i.customRange,statusFilter:i.statusFilter,accessPointIdFilter:i.accessPointIdFilter,destCountryFilter:i.destCountryFilter,ispFilter:i.ispFilter,searchQuery:i.searchQuery});Re({profileId:e,realtimeRefresh:n,range:i.range,searchQuery:i.searchQuery,scrollContainerRef:a.scrollContainerRef,isFetchingRef:a.isFetchingRef,fetchLogs:a.fetchLogs,logsRef:a.logsRef});let o=He({profileId:e,range:i.range,customRange:i.customRange,statusFilter:i.statusFilter,accessPointIdFilter:i.accessPointIdFilter,destCountryFilter:i.destCountryFilter,ispFilter:i.ispFilter,searchQuery:i.searchQuery,toasterRef:t});return{realtimeRefresh:n,setRealtimeRefresh:r,...i,...a,...o}}function We({profileId:e,range:t,fetchLogs:n,toasterRef:r}){let{t:i}=o(),[a,s]=(0,X.useState)(!1),[c,l]=(0,X.useState)(!1),[u,d]=(0,X.useState)(!1),[f,p]=(0,X.useState)(!1),[m,h]=(0,X.useState)(``),[g,_]=(0,X.useState)(``),[v,y]=(0,X.useState)(null),[b,x]=(0,X.useState)(!1),S=(0,X.useRef)(!1),C=(0,X.useRef)(e);C.current!==e&&(C.current=e,S.current=!1);let w=(0,X.useCallback)(async()=>{try{let r=await G.getStatus(e),i=!!r.enabled;s(i);let a=G.isProfileUnlocked(e);if(l(a),i&&!a&&r.wrappedPasskeys&&r.wrappedPasskeys.length>0&&!S.current){S.current=!0;try{await G.unlockProfile(e)&&(l(!0),await K.reDecryptLocalLogs(e),n(t,!0))}catch(e){console.debug(`[useLogsE2ee] Silent auto-unlock skipped or cancelled:`,e)}}}catch{s(!1)}},[e,n,t]);return(0,X.useEffect)(()=>{w()},[w]),{isE2eeEnabled:a,isE2eeUnlocked:c,unlocking:u,recoveryDialogOpen:f,setRecoveryDialogOpen:p,recoveryKeyInput:m,setRecoveryKeyInput:h,recoveryError:g,setRecoveryError:_,rotatedKey:v,setRotatedKey:y,copiedKey:b,handleCopyRotatedKey:e=>{navigator.clipboard.writeText(e),x(!0),setTimeout(()=>x(!1),2e3)},handleUnlockPasskey:async()=>{try{d(!0),await G.unlockProfile(e)&&(l(!0),await K.reDecryptLocalLogs(e),r?.current?.show({message:i(`settings.e2eeUnlockSuccess`,`私钥已成功在此设备解锁`),intent:j.SUCCESS}),n(t,!0))}catch(e){console.error(`Failed to unlock E2EE via Passkey:`,e),r?.current?.show({message:e.message||i(`settings.e2eeUnlockError`,`验证 Passkey 解锁失败`),intent:j.DANGER})}finally{d(!1)}},handleUnlockRecoveryKey:async a=>{a.preventDefault();let o=m.trim();if(o){d(!0),_(``);try{await G.unlockWithRecoveryKey(o);try{let e=await oe({recoveryKey:o});await G.wrapCurrentKeyForRecovery(e.recovery_key),y(e.recovery_key)}catch(e){console.warn(`[useLogsE2ee] Recovery key auto-rotation failed:`,e)}l(!0),p(!1),h(``),await K.reDecryptLocalLogs(e),r?.current?.show({message:i(`settings.e2eeUnlockSuccess`,`私钥已成功在此设备解锁`),intent:j.SUCCESS}),n(t,!0)}catch(e){console.error(`Failed to unlock E2EE via recovery key:`,e),_(e.message||i(`account.e2ee.recoveryUnlockFailed`,`恢复密钥无效或解析失败`))}finally{d(!1)}}}}}const Ge=({profileId:e,onQuickAction:t,toasterRef:n})=>{let r=ne(),[i,a]=(0,X.useState)(null),[o,s]=(0,X.useState)(!1),{realtimeRefresh:c,setRealtimeRefresh:l,range:u,setRange:d,customRange:f,setCustomRange:p,statusFilter:m,setStatusFilter:h,accessPointIdFilter:g,setAccessPointIdFilter:_,accessPoints:v,destCountryFilter:y,setDestCountryFilter:b,ispFilter:x,setIspFilter:S,searchQuery:C,setSearchQuery:w,logs:T,loading:E,loadingMore:O,syncing:k,hasMore:A,stats:j,logRetentionDays:M,prevLatestTimestamp:N,scrollContainerRef:ee,lastLogElementRef:P,fetchLogs:F,exporting:I,handleExportLogs:L}=Ue({profileId:e,toasterRef:n}),{isE2eeEnabled:te,isE2eeUnlocked:R,unlocking:z,recoveryDialogOpen:B,setRecoveryDialogOpen:V,recoveryKeyInput:re,setRecoveryKeyInput:H,recoveryError:U,setRecoveryError:ie,rotatedKey:ae,setRotatedKey:oe,copiedKey:se,handleCopyRotatedKey:W,handleUnlockPasskey:G,handleUnlockRecoveryKey:K}=We({profileId:e,range:u,fetchLogs:F,toasterRef:n}),q=new Date().toLocaleString(`sv-SE`).replace(` `,`T`).slice(0,16);return E&&T.length===0?(0,Z.jsx)(`div`,{className:`h-full flex items-center justify-center`,children:(0,Z.jsx)(D,{})}):(0,Z.jsxs)(`div`,{className:`h-full flex flex-col overflow-hidden bg-gray-50/30 dark:bg-gray-950/10 max-w-7xl mx-auto w-full pt-14`,children:[(0,Z.jsx)(he,{profileId:e,range:u,setRange:d,customRange:f,setCustomRange:p,nowStr:q,fetchLogs:F,isMobile:r,realtimeRefresh:c,setRealtimeRefresh:l,statusFilter:m,setStatusFilter:h,accessPointIdFilter:g,setAccessPointIdFilter:_,accessPoints:v,destCountryFilter:y,setDestCountryFilter:b,ispFilter:x,setIspFilter:S,searchQuery:C,setSearchQuery:w,stats:j,logRetentionDays:M,onExport:L,exporting:I,loading:E,syncing:k}),te&&!R&&(0,Z.jsx)(Te,{isMobile:r,unlocking:z,onUnlockPasskey:G,onOpenRecoveryDialog:()=>{ie(``),H(``),V(!0)}}),(0,Z.jsx)(ve,{logs:T,loading:E,loadingMore:O,hasMore:A,realtimeRefresh:c,isMobile:r,searchQuery:C,scrollContainerRef:ee,lastLogElementRef:P,prevLatestTimestamp:N,setSelectedLog:a,setIsDrawerOpen:s,logRetentionDays:M}),(0,Z.jsx)(we,{isDrawerOpen:o,setIsDrawerOpen:s,selectedLog:i,profileId:e,isMobile:r,onQuickAction:t}),(0,Z.jsx)(Ee,{isOpen:B,onClose:()=>V(!1),recoveryKeyInput:re,setRecoveryKeyInput:H,recoveryError:U,unlocking:z,onSubmit:K}),(0,Z.jsx)(De,{rotatedKey:ae,onClose:()=>oe(null),copiedKey:se,onCopyKey:W})]})};export{Ge as LogsView};
@@ -1 +0,0 @@
1
- import{i as e}from"./rolldown-runtime-C4Xdq4VV.js";import{A as t,B as n,C as r,E as i,Et as a,F as o,G as s,I as c,M as l,P as u,Qt as d,R as f,Tt as p,W as m,at as h,it as g,lt as _,q as v,rt as y,tt as b,w as x,z as S}from"./vendor-react-De1zEwOV.js";import{S as C,b as w}from"./vendor-icons-other-BTYC6Wvz.js";import"./vendor-i18next-CevVzhh3.js";import{A as T,B as E,F as D,L as O,M as k,N as A,O as j,P as M,R as N,S as P,T as F,V as I,a as L,d as R,f as z,i as B,n as V,o as H,r as U,v as W,z as G}from"./vendor-ui-core-ClwQiwMI.js";import{_t as K,t as ee,vt as q}from"./vendor-utils-rmW6cqPl.js";import{$t as te,D as ne,F as J,L as re,N as ie,O as ae,P as oe,Q as se,X as ce,_ as le,a as ue,h as de,n as Y,ot as fe,q as pe,st as me,t as he,z as ge}from"./index-CrB_HdIL.js";import{t as _e}from"./SwipeableDrawer-DkPacJ1O.js";var X=e(C(),1),Z=e(w(),1);const ve=()=>{let{t:e}=d();return(0,Z.jsxs)(`div`,{className:`flex flex-col sm:flex-row justify-between items-start sm:items-center gap-4`,children:[(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(T,{className:`font-bold text-gray-900 dark:text-white m-0`,children:e(`setup.title`)}),(0,Z.jsx)(`p`,{className:`bp6-text-muted m-0 mt-1`,children:e(`setup.subtitle`)})]}),(0,Z.jsx)(`div`,{className:`flex items-center`,children:(0,Z.jsx)(he,{})})]})},ye=({isVerifying:e,verifyResult:n,handleVerify:r,isMobile:i,clientInfo:o,showIp:s,setShowIp:c,showLocation:l,setShowLocation:f,traceInfo:p,edgeLocation:m})=>{let{t:h}=d(),{isServerfull:_}=Y(),[x,S]=(0,X.useState)(!1),C=(0,Z.jsxs)(`div`,{className:q(`bg-white dark:bg-gray-900 p-4 rounded-lg border border-gray-100 dark:border-gray-800 shadow-sm flex items-start gap-3 select-none h-full transition-all`,!_&&`cursor-pointer hover:border-purple-300 dark:hover:border-purple-700 hover:shadow-md`),children:[(0,Z.jsx)(u,{size:18,className:`text-purple-500 mt-1 shrink-0`}),(0,Z.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Z.jsx)(`div`,{className:`text-[10px] uppercase font-bold opacity-40`,children:_?h(`setup.serverLocation`,`服务器位置`):h(`setup.edgeServer`)}),(0,Z.jsx)(`div`,{className:`font-bold truncate`,title:_?m||``:m||p?.colo||``,children:_?m||h(`setup.detecting`):m||p?.colo||h(`setup.detecting`)})]})]});return(0,Z.jsx)(H,{title:h(`setup.verifyConnection`),icon:(0,Z.jsx)(a,{size:16}),children:(0,Z.jsx)(L,{children:(0,Z.jsxs)(`div`,{className:`flex flex-col space-y-6`,children:[(0,Z.jsxs)(`div`,{className:`flex flex-col md:flex-row items-center justify-between bg-gray-50 dark:bg-gray-800/50 p-6 rounded-xl border border-gray-100 dark:border-gray-800 gap-6`,children:[(0,Z.jsxs)(`div`,{className:`flex flex-col md:flex-row items-center gap-4 text-center md:text-left`,children:[(0,Z.jsx)(`div`,{className:`p-3 rounded-full ${n?.success?`bg-green-100 text-green-600`:n?`bg-red-100 text-red-600`:`bg-blue-100 text-blue-600`}`,children:e?(0,Z.jsx)(M,{size:24}):n?.success?(0,Z.jsx)(t,{size:24}):(0,Z.jsx)(u,{size:24})}),(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`div`,{className:`font-bold text-lg`,children:e?h(`setup.verifying`):n?.success?h(`setup.connected`):h(`setup.notConnected`)}),(0,Z.jsx)(`div`,{className:`text-sm opacity-60`,children:n?.success?n.profileMatch?h(`setup.profileMatch`):h(`setup.profileMismatch`):h(`setup.verifyHint`)})]})]}),(0,Z.jsx)(A,{size:`large`,intent:n?.success?I.SUCCESS:I.PRIMARY,icon:`refresh`,text:h(`setup.refreshStatus`),onClick:r,loading:e,fill:i})]}),o&&(0,Z.jsxs)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 md:grid-cols-3 gap-4`,children:[(0,Z.jsxs)(`div`,{className:`bg-white dark:bg-gray-900 p-4 rounded-lg border border-gray-100 dark:border-gray-800 shadow-sm flex items-start gap-3`,children:[(0,Z.jsx)(b,{size:18,className:`text-blue-500 mt-1`}),(0,Z.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Z.jsx)(`div`,{className:`text-[10px] uppercase font-bold opacity-40`,children:h(`setup.egressIp`)}),(0,Z.jsx)(`button`,{onClick:()=>c(!s),className:`text-gray-400 hover:text-blue-500 transition-colors`,children:s?(0,Z.jsx)(y,{size:16}):(0,Z.jsx)(g,{size:16})})]}),(0,Z.jsx)(`div`,{className:`font-mono font-bold text-blue-600 dark:text-blue-400 truncate`,children:(0,Z.jsx)(`span`,{className:q(`transition-[filter] duration-200 inline-block`,!s&&`filter blur-[6px] select-none`),children:o.ip})})]})]}),(0,Z.jsxs)(`div`,{className:`bg-white dark:bg-gray-900 p-4 rounded-lg border border-gray-100 dark:border-gray-800 shadow-sm flex items-start gap-3`,children:[(0,Z.jsx)(v,{size:18,className:`text-red-500 mt-1`}),(0,Z.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Z.jsx)(`div`,{className:`text-[10px] uppercase font-bold opacity-40`,children:h(`setup.currentLocation`)}),(0,Z.jsx)(`button`,{onClick:()=>f(!l),className:`text-gray-400 hover:text-red-500 transition-colors`,children:l?(0,Z.jsx)(y,{size:16}):(0,Z.jsx)(g,{size:16})})]}),(0,Z.jsx)(`div`,{className:`font-bold truncate`,children:(0,Z.jsx)(`span`,{className:q(`transition-[filter] duration-200 inline-block`,!l&&`filter blur-[6px] select-none`),children:(()=>{let e=[o.city,o.region,o.country].filter(e=>!!(e&&e!==`UNKNOWN`));return e.length>0?e.join(`, `):h(`setup.detecting`)})()})})]})]}),_?C:(0,Z.jsx)(F,{isOpen:x,onInteraction:S,placement:`bottom-end`,portalClassName:`z-20000`,fill:!0,targetProps:{className:`h-full`},content:(0,Z.jsxs)(`div`,{className:`p-3 select-text w-72 sm:w-80 max-w-[85vw] space-y-2`,children:[(0,Z.jsx)(`div`,{className:`text-[11px] font-mono font-bold text-gray-500 dark:text-gray-400 tracking-wide border-b border-gray-100 dark:border-gray-800 pb-1.5`,children:`/cdn-cgi/trace`}),(0,Z.jsx)(`pre`,{className:`m-0 font-mono text-xs leading-relaxed whitespace-pre-wrap break-all overflow-x-hidden max-h-64 overflow-y-auto text-gray-800 dark:text-gray-200`,children:p?.raw||h(`setup.noTraceData`,`暂无 Trace 数据`)})]}),children:C})]})]})})})},Q=({step:e,className:t,size:n=144})=>{let r=e===1?47:50,i=e===1?45.5:45;return(0,Z.jsx)(`div`,{"aria-hidden":`true`,className:K(`absolute -top-7 -left-7 pointer-events-none select-none z-0`,`text-blue-600/[0.08] dark:text-blue-400/[0.12]`,`transition-all duration-500 ease-out`,`blur-none group-hover:blur-md group-hover:opacity-0`,t),style:{width:n,height:n},children:(0,Z.jsxs)(`svg`,{viewBox:`0 0 100 100`,fill:`none`,xmlns:`http://www.w3.org/2000/svg`,className:`w-full h-full`,children:[(0,Z.jsx)(`circle`,{cx:`50`,cy:`50`,r:`46`,stroke:`currentColor`,strokeWidth:`4`}),(0,Z.jsx)(`text`,{x:r,y:i,textAnchor:`middle`,dominantBaseline:`central`,fill:`currentColor`,fontSize:`80`,fontWeight:`900`,fontFamily:`'Helvetica Neue', Helvetica, Arial, sans-serif`,children:e})]})})},be=({accessPoints:e,selectedApId:t,onSelectAp:n,accessPointName:r,onManageAccessPoints:i,isMobile:a})=>{let{t:o}=d();return(0,Z.jsxs)(H,{title:o(`setup.accessPointsCardTitle`,`接入点`),icon:(0,Z.jsx)(s,{size:16}),className:`group relative overflow-hidden [&_.bp6-section-header]:relative [&_.bp6-section-header]:z-10 [&_.bp6-section-card]:relative [&_.bp6-section-card]:z-10`,children:[(0,Z.jsx)(Q,{step:1}),(0,Z.jsx)(L,{children:(0,Z.jsxs)(`div`,{className:`flex flex-col sm:flex-row items-start sm:items-center justify-between gap-4`,children:[(0,Z.jsxs)(`div`,{className:`flex flex-col gap-1.5 w-full sm:w-auto`,children:[(0,Z.jsx)(`span`,{className:`text-xs opacity-50 font-medium`,children:o(`setup.selectAccessPointToConfigure`)}),(0,Z.jsxs)(`div`,{className:`flex items-center gap-3`,children:[e.length>0?(0,Z.jsx)(R,{value:t||``,onChange:e=>n(e.target.value),options:e.map(e=>({label:e.name,value:e.id})),className:`font-semibold text-gray-900 dark:text-gray-100`}):(0,Z.jsx)(`div`,{className:`font-semibold text-gray-900 dark:text-gray-100 flex items-center gap-2`,children:r||o(`setup.defaultAccessPointName`,`设备-1`)}),e.length>0&&(0,Z.jsx)(U,{minimal:!0,round:!0,intent:I.PRIMARY,className:`text-xs`,children:e.length})]})]}),(0,Z.jsx)(A,{variant:`outlined`,intent:I.NONE,icon:(0,Z.jsx)(l,{size:14}),text:o(`setup.manageAccessPoints`,`管理接入点`),onClick:i,fill:a,className:`shrink-0`})]})})]})},xe=({dohUrl:e,copyToClipboard:t,isMobile:n})=>{let{t:r}=d();return(0,Z.jsxs)(H,{title:r(`setup.accessPointTitle`,`Access DoH URL`),icon:`globe`,className:`group relative overflow-hidden [&_.bp6-section-header]:relative [&_.bp6-section-header]:z-10 [&_.bp6-section-card]:relative [&_.bp6-section-card]:z-10`,rightElement:(0,Z.jsx)(F,{placement:`bottom-end`,usePortal:!0,content:(0,Z.jsxs)(`div`,{className:`p-4 max-w-sm`,children:[(0,Z.jsx)(k,{children:r(`setup.whatIsDoh`)}),(0,Z.jsx)(`p`,{className:`text-sm mb-2`,children:r(`setup.dohDesc`)}),(0,Z.jsxs)(`ul`,{className:`list-disc list-inside text-sm opacity-80 mb-3 space-y-1`,children:[(0,Z.jsx)(`li`,{children:r(`setup.dohBenefit1`)}),(0,Z.jsx)(`li`,{children:r(`setup.dohBenefit2`)})]}),(0,Z.jsx)(`div`,{className:`text-xs border-t border-gray-100 dark:border-gray-700 pt-2`,children:(0,Z.jsxs)(`a`,{href:`https://en.wikipedia.org/wiki/DNS_over_HTTPS`,target:`_blank`,rel:`noreferrer`,className:`flex items-center gap-1 text-blue-500 hover:underline`,children:[(0,Z.jsx)(h,{size:10}),` `,r(`setup.learnMore`)]})})]}),children:(0,Z.jsx)(A,{icon:`help`,variant:`minimal`,intent:I.NONE})}),children:[(0,Z.jsx)(Q,{step:2}),(0,Z.jsx)(L,{children:(0,Z.jsxs)(`div`,{className:`w-full bg-gray-100 dark:bg-gray-800 p-3 rounded-lg border border-gray-200 dark:border-gray-700 flex flex-col sm:flex-row items-stretch sm:items-center justify-between gap-3`,children:[(0,Z.jsx)(`span`,{className:`font-mono text-blue-600 dark:text-blue-400 break-all text-xs sm:text-sm`,children:e}),(0,Z.jsx)(A,{intent:I.PRIMARY,icon:`duplicate`,text:r(`setup.copyUrl`),fill:n,onClick:()=>t(e),className:`shrink-0`})]})})]})};function Se(e){let t=e.trim();try{return new URL(t.startsWith(`http://`)||t.startsWith(`https://`)?t:`https://${t}`).hostname||t}catch{return t.replace(/^https?:\/\//,``).split(`/`)[0].split(`:`)[0]||t}}function $(e,t){let n=(e||``).trim(),r=(t||``).trim();if(!r&&n.includes(`(`)&&n.endsWith(`)`)){let e=n.match(/^(.+?)\s*\((.+?)\)$/);e&&(n=e[1].trim(),r=e[2].trim())}let i=n&&n!==`DNS Worker`?n:``,a=r&&r!==`DNS Worker`?r:``;return i&&a?i.toLowerCase()===a.toLowerCase()?i:`${i} - ${a}`:i||a||``}function Ce(e,t,n,r){let i,a,o,s;typeof e==`object`?(i=e.profileKey,a=e.profileName,o=e.accessPointName,s=e.origin):(i=e,a=t,s=n||``,o=r);let c=s.trim(),l=Se(c),u=`${c}/${i}`,d=$(a,o),f=crypto.randomUUID(),p=crypto.randomUUID(),m=d?`DNS Worker - ${l} (${d})`:`DNS Worker (${l})`,h=d?`DNS Worker DoH - ${l} (${d})`:`DNS Worker DoH - ${l}`,g=d?`DNS Worker DoH configuration profile for ${d} via ${l}`:`DNS Worker DoH configuration profile via ${l}`,_=d?`Configures encrypted DNS over HTTPS (DoH) for ${d} via ${l}`:`Configures encrypted DNS over HTTPS (DoH) via ${l}`;return ee({PayloadContent:[{DNSSettings:{DNSProtocol:`HTTPS`,ServerHTTPVersion:3,ServerURL:u},OnDemandRules:[{Action:`Connect`,InterfaceTypeMatch:`WiFi`},{Action:`Connect`,InterfaceTypeMatch:`Cellular`},{Action:`Disconnect`}],PayloadDescription:_,PayloadDisplayName:h,PayloadIdentifier:`com.apple.dnsSettings.managed.${f}`,PayloadName:h,PayloadType:`com.apple.dnsSettings.managed`,PayloadUUID:f,PayloadVersion:1}],PayloadDescription:g,PayloadDisplayName:m,PayloadIdentifier:`com.dnsworker.profile.${i}`,PayloadName:m,PayloadRemovalDisallowed:!1,PayloadType:`Configuration`,PayloadUUID:p,PayloadVersion:1},{indent:` `})}const we=({isMobile:e,copyToClipboard:t,profileKey:n,profileName:r,accessPointName:a,currentIps:o,dotDomain:s})=>{let{t:l}=d(),{isCloudflare:u}=Y();return(0,Z.jsxs)(`div`,{className:`group relative overflow-hidden rounded-xl border border-gray-200 dark:border-gray-800 bg-white dark:bg-gray-900 shadow-sm`,children:[(0,Z.jsx)(Q,{step:3}),(0,Z.jsxs)(V,{id:`setup-tabs`,renderActiveTabPanelOnly:!0,vertical:!e,size:`large`,className:K(`p-4 md:p-6 setup-tabs-container relative z-10 bg-transparent`,e&&[`[&_.bp6-tab-list]:overflow-x-auto!`,`[&_.bp6-tab-list]:flex-nowrap!`,`[&_.bp6-tab-list]:pb-1`,`[&_.bp6-tab-list]:scrollbar-none`,`[&_.bp6-tab-list]:[-ms-overflow-style:none]`,`[&_.bp6-tab-list::-webkit-scrollbar]:hidden`,`[&_.bp6-tab]:shrink-0`]),children:[(0,Z.jsx)(B,{id:`browsers`,title:(0,Z.jsxs)(`span`,{children:[(0,Z.jsx)(b,{size:16,className:`inline mr-2`}),l(`setup.browsers`)]}),panel:(0,Z.jsxs)(`div`,{className:`space-y-4 md:ml-4 mt-4 md:mt-0`,children:[(0,Z.jsx)(k,{className:`font-bold`,children:l(`setup.browserTitle`)}),(0,Z.jsx)(`p`,{className:`text-sm`,children:l(`setup.browserSteps`)}),(0,Z.jsx)(`p`,{className:`text-[10px] opacity-50 cursor-pointer`,onClick:()=>t(`chrome://settings/security`),children:l(`setup.browserTips`,`or copy this URL to the address bar: `)+`chrome://settings/security`})]})}),(0,Z.jsx)(B,{id:`apple`,title:(0,Z.jsxs)(`span`,{children:[(0,Z.jsx)(p,{size:16,className:`inline mr-2`}),l(`setup.apple`)]}),panel:(0,Z.jsxs)(`div`,{className:`space-y-4 md:ml-4 mt-4 md:mt-0`,children:[(0,Z.jsx)(k,{className:`font-bold`,children:l(`setup.appleTitle`)}),(0,Z.jsx)(`p`,{className:`text-sm`,children:l(`setup.appleDesc`)}),(0,Z.jsx)(`p`,{className:`text-[10px] opacity-50 text-center`,children:l(`setup.appleWarning`)}),(0,Z.jsxs)(`div`,{className:`p-6 bg-gray-50 dark:bg-gray-800 rounded-xl border border-dashed border-gray-300 dark:border-gray-700 flex flex-col items-center justify-center`,children:[(0,Z.jsx)(D,{icon:`document`,size:40,className:`opacity-20 mb-4`}),(0,Z.jsx)(A,{intent:I.PRIMARY,text:l(`setup.downloadConfig`),icon:`download`,onClick:()=>{let e=Ce({profileKey:n,profileName:r,accessPointName:a,origin:window.location.origin}),t=new Blob([e],{type:`application/x-apple-aspen-config`}),i=URL.createObjectURL(t),o=document.createElement(`a`);o.href=i;let s=$(r,a),c=Se(window.location.origin);o.download=`dns_worker-${(s||c).replace(/[^a-zA-Z0-9_\-\u4e00-\u9fa5]/g,`_`).replace(/_+/g,`_`).replace(/^_|_$/g,``)}-${n}.mobileconfig`,o.click(),URL.revokeObjectURL(i)}})]}),(0,Z.jsx)(`p`,{className:`text-[10px] opacity-50 mt-4! text-center`,children:l(`setup.appleInstallHint`)})]})}),(0,Z.jsx)(B,{id:`windows`,title:(0,Z.jsxs)(`span`,{children:[(0,Z.jsx)(m,{size:16,className:`inline mr-2`}),l(`setup.windows`)]}),panel:(0,Z.jsxs)(`div`,{className:`space-y-4 md:ml-4 mt-4 md:mt-0`,children:[(0,Z.jsx)(k,{className:`font-bold`,children:l(`setup.windowsTitle`)}),(0,Z.jsxs)(`ol`,{className:`list-decimal list-inside space-y-4 text-sm leading-relaxed`,children:[(0,Z.jsx)(`li`,{children:(0,Z.jsx)(`a`,{href:`ms-settings:network-status`,children:l(`setup.windowsStep0`)})}),(0,Z.jsx)(`li`,{children:l(`setup.windowsStep1`)}),(0,Z.jsxs)(`li`,{children:[l(`setup.windowsStep2`),(0,Z.jsx)(`div`,{className:`mt-2 flex flex-wrap gap-2`,children:o.map(e=>(0,Z.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,Z.jsx)(U,{minimal:!0,interactive:!0,onClick:()=>t(e.ip),icon:`duplicate`,className:`font-mono`,children:e.ip}),(0,Z.jsx)(`span`,{className:`text-[9px] opacity-50 ml-1 font-mono`,children:e.area})]},e.ip))})]}),(0,Z.jsx)(`li`,{children:l(`setup.windowsStep3`)}),(0,Z.jsx)(`li`,{children:l(`setup.windowsStep4`)})]})]})}),(0,Z.jsx)(B,{id:`linux`,title:(0,Z.jsxs)(`span`,{children:[(0,Z.jsx)(x,{size:16,className:`inline mr-2`}),l(`setup.linux`)]}),panel:(0,Z.jsxs)(`div`,{className:`space-y-4 md:ml-4 mt-4 md:mt-0`,children:[(0,Z.jsx)(k,{className:`font-bold`,children:l(`setup.linuxTitle`)}),(0,Z.jsx)(`p`,{className:`text-sm`,children:l(`setup.linuxDesc`)}),(0,Z.jsxs)(`div`,{className:`mt-4`,children:[(0,Z.jsx)(`p`,{className:`text-sm font-bold mb-2`,children:l(`setup.linuxStep1`)}),(0,Z.jsxs)(`div`,{className:`relative group`,children:[(0,Z.jsx)(`pre`,{className:`bg-gray-100 dark:bg-gray-800 p-4 rounded-lg overflow-x-auto text-xs font-mono border border-gray-200 dark:border-gray-700`,children:(0,Z.jsx)(`code`,{children:`curl -sL "${window.location.origin}/setup.sh?key=${n}&origin=${window.location.origin}" | sudo bash`})}),(0,Z.jsx)(A,{className:`absolute top-2 right-2 opacity-0 group-hover:opacity-100 transition-opacity`,icon:`duplicate`,minimal:!0,small:!0,onClick:()=>{t(`curl -sL "${window.location.origin}/setup.sh?key=${n}&origin=${window.location.origin}" | sudo bash`)}})]})]}),(0,Z.jsx)(`div`,{className:`mt-4`,children:(0,Z.jsx)(`p`,{className:`text-sm font-bold`,children:l(`setup.linuxStep2`)})})]})}),(0,Z.jsx)(B,{id:`routeros`,title:(0,Z.jsxs)(`span`,{children:[(0,Z.jsx)(c,{size:16,className:`inline mr-2`}),l(`setup.routeros`)]}),panel:(0,Z.jsxs)(`div`,{className:`space-y-4 md:ml-4 mt-4 md:mt-0`,children:[(0,Z.jsx)(k,{className:`font-bold`,children:l(`setup.routerosTitle`)}),(0,Z.jsx)(`p`,{className:`text-sm`,children:l(`setup.routerosDesc`)}),(0,Z.jsxs)(`div`,{className:`mt-4`,children:[(0,Z.jsx)(`p`,{className:`text-sm font-bold mb-2`,children:l(`setup.routerosStep1`)}),(0,Z.jsxs)(`div`,{className:`relative group`,children:[(0,Z.jsx)(`pre`,{className:`bg-gray-100 dark:bg-gray-800 p-4 rounded-lg overflow-x-auto text-xs font-mono border border-gray-200 dark:border-gray-700`,children:(0,Z.jsx)(`code`,{children:`/ip dns set use-doh-server="${window.location.origin}/${n}" verify-doh-cert=yes`})}),(0,Z.jsx)(A,{className:`absolute top-2 right-2 opacity-0 group-hover:opacity-100 transition-opacity`,icon:`duplicate`,minimal:!0,small:!0,onClick:()=>{t(`/ip dns set use-doh-server="${window.location.origin}/${n}" verify-doh-cert=yes`)}})]})]}),(0,Z.jsx)(`p`,{className:`text-sm`,children:l(`setup.routerosNote`)}),(0,Z.jsxs)(`a`,{href:`https://help.mikrotik.com/docs/spaces/ROS/pages/37748767/DNS`,target:`_blank`,rel:`noreferrer`,className:`flex items-center gap-1 text-xs text-blue-500 hover:underline`,children:[(0,Z.jsx)(h,{size:10}),` `,l(`setup.routerosDocs`)]})]})}),(0,Z.jsx)(B,{id:`android`,title:(0,Z.jsxs)(`span`,{children:[(0,Z.jsx)(i,{size:16,className:`inline mr-2`}),l(`setup.android`)]}),panel:(0,Z.jsxs)(`div`,{className:`space-y-4 md:ml-4 mt-4 md:mt-0`,children:[(0,Z.jsx)(k,{className:`font-bold`,children:l(`setup.androidTitle`)}),(0,Z.jsx)(`p`,{className:`text-sm`,children:l(`setup.androidDesc`)}),u?(0,Z.jsxs)(P,{intent:I.WARNING,icon:`warning-sign`,className:`text-xs`,children:[(0,Z.jsx)(`div`,{className:`font-semibold mb-1`,children:l(`setup.dotUnavailableCfTitle`)}),(0,Z.jsx)(`div`,{children:l(`setup.dotUnavailableCfDesc`)})]}):(()=>{let e=/^(\d{1,3}\.){3}\d{1,3}$/.test(window.location.hostname)||window.location.hostname===`localhost`||window.location.hostname===`127.0.0.1`||window.location.hostname.includes(`:`),r=(s||``).trim().replace(/^\*\./,``),i=!J(r)&&r||(e?``:window.location.hostname);return(0,Z.jsxs)(`div`,{className:`p-4 bg-gray-50 dark:bg-gray-800/60 rounded-xl border border-gray-200 dark:border-gray-700 space-y-3`,children:[(0,Z.jsx)(`div`,{className:`text-xs font-semibold text-gray-700 dark:text-gray-300`,children:l(`setup.androidDotTitle`,`私有 DNS (DoT / DoQ)`)}),(0,Z.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-gray-400`,children:l(`setup.androidDotDesc`,`支持 Android 原生“私有 DNS (DoT)”及各类现代 DoQ 客户端。提供商主机名:`)}),i?(0,Z.jsx)(`div`,{className:`space-y-3 pt-1`,children:(0,Z.jsx)(`div`,{className:`flex flex-col sm:flex-row sm:items-center gap-1.5 sm:gap-2`,children:(0,Z.jsx)(U,{minimal:!0,interactive:!0,onClick:()=>t(`${n}.${i}`),icon:`duplicate`,className:`font-mono text-xs sm:text-sm py-1 px-3 self-start`,intent:I.PRIMARY,children:`${n}.${i}`})})}):(0,Z.jsx)(P,{intent:I.WARNING,icon:`warning-sign`,className:`text-xs`,children:l(`setup.androidIpNotice`,`检测到当前通过 IP 或本地地址访问面板。DoT / DoQ 仅接受域名,请在 .env 中配置 SERVERFULL_DOT_DOMAIN (例如 dns.example.com) 后刷新。`)})]})})(),!u&&(0,Z.jsx)(P,{intent:I.PRIMARY,icon:`info-sign`,className:`text-xs`,children:l(`setup.androidWarning`)})]})})]})]})};function Te({profileId:e,accessPoints:t,onRefresh:n,toasterRef:r}){let{t:i}=d(),[a,o]=(0,X.useState)(!1),[s,c]=(0,X.useState)(``),[l,u]=(0,X.useState)(!1),[f,p]=(0,X.useState)(null),[m,h]=(0,X.useState)(``),[g,_]=(0,X.useState)(!1),[v,y]=(0,X.useState)(null),[b,x]=(0,X.useState)(null),[S,C]=(0,X.useState)(!1),[w,T]=(0,X.useState)(!1),[E,D]=(0,X.useState)(null),[O,k]=(0,X.useState)(!1),[A,j]=(0,X.useState)(``);return{isAddDialogOpen:a,setIsAddDialogOpen:o,newApName:s,setNewApName:c,isAdding:l,renameApId:f,setRenameApId:p,renameApName:m,setRenameApName:h,isRenaming:g,rotatingApId:v,deletingApId:b,newApNameFocused:S,setNewApNameFocused:C,renameApNameFocused:w,setRenameApNameFocused:T,rotateConfirmApId:E,setRotateConfirmApId:D,isSearchOpen:O,setIsSearchOpen:k,searchQuery:A,setSearchQuery:j,filteredAccessPoints:t.filter(e=>e.name.toLowerCase().includes(A.toLowerCase())||e.token.toLowerCase().includes(A.toLowerCase())),isValidApName:e=>ue.test(e),handleAdd:async()=>{let a=s.trim();if(a){if(t.some(e=>e.name.toLowerCase()===a.toLowerCase())){r.current?.show({message:i(`setup.accessPointNameExists`,`Access Point name already exists`),intent:I.DANGER});return}u(!0);try{await ge(e,a),r.current?.show({message:i(`setup.accessPointCreated`),intent:I.SUCCESS}),o(!1),c(``),n()}catch(e){let t=e.message||`Failed to create access point`,n=t;if(t.startsWith(`Access point limit exceeded`)){let e=t.match(/\(max (\d+)\)/),r=e?e[1]:`100`;n=i(`setup.accessPointLimitExceeded`,{max:r,defaultValue:`Access Point limit exceeded (max ${r})`})}r.current?.show({message:n,intent:I.DANGER})}finally{u(!1)}}},handleRename:async()=>{let a=m.trim();if(!(!a||!f)){if(t.some(e=>e.id!==f&&e.name.toLowerCase()===a.toLowerCase())){r.current?.show({message:i(`setup.accessPointNameExists`,`Access Point name already exists`),intent:I.DANGER});return}_(!0);try{await fe(e,f,a),r.current?.show({message:i(`setup.accessPointRenamed`),intent:I.SUCCESS}),p(null),n()}catch(e){r.current?.show({message:e.message||`Failed to rename access point`,intent:I.DANGER})}finally{_(!1)}}},handleRotate:async t=>{y(t);try{await me(e,t),r.current?.show({message:i(`setup.tokenRotated`),intent:I.SUCCESS}),n()}catch(e){console.error(e)}finally{y(null)}},handleDelete:async t=>{if(confirm(i(`setup.deleteAccessPointConfirm`))){x(t);try{await pe(e,t),r.current?.show({message:i(`setup.accessPointDeleted`),intent:I.SUCCESS}),n()}catch(e){console.error(e)}finally{x(null)}}}}}const Ee=({isOpen:e,onClose:t,newApName:n,setNewApName:r,newApNameFocused:i,setNewApNameFocused:a,handleAdd:o,isAdding:s,isValidApName:c})=>{let{t:l}=d();return(0,Z.jsxs)(j,{isOpen:e,onClose:t,title:l(`setup.addAccessPoint`),children:[(0,Z.jsx)(`div`,{className:O,children:(0,Z.jsx)(W,{content:l(`setup.accessPointNameFormatTip`,`1-30 characters, letters, numbers, hyphens and underscores allowed`),isOpen:i,position:E.TOP,intent:I.PRIMARY,className:`w-full`,children:(0,Z.jsx)(`div`,{className:`w-full block`,children:(0,Z.jsx)(z,{autoFocus:!0,large:!0,placeholder:l(`setup.accessPointName`),value:n,onChange:e=>r(e.target.value),onFocus:()=>a(!0),onBlur:()=>a(!1)})})})}),(0,Z.jsx)(`div`,{className:N,children:(0,Z.jsxs)(`div`,{className:G,children:[(0,Z.jsx)(A,{onClick:t,children:l(`common.cancel`,`Cancel`)}),(0,Z.jsx)(A,{intent:I.PRIMARY,onClick:o,loading:s,disabled:!c(n),children:l(`common.create`)})]})})]})},De=({isOpen:e,onClose:t,renameApName:n,setRenameApName:r,renameApNameFocused:i,setRenameApNameFocused:a,handleRename:o,isRenaming:s,isValidApName:c})=>{let{t:l}=d();return(0,Z.jsxs)(j,{isOpen:e,onClose:t,title:l(`setup.renameAccessPoint`),children:[(0,Z.jsx)(`div`,{className:O,children:(0,Z.jsx)(W,{content:l(`setup.accessPointNameFormatTip`,`1-30 characters, letters, numbers, hyphens and underscores allowed`),isOpen:i,position:E.TOP,intent:I.PRIMARY,className:`w-full`,children:(0,Z.jsx)(`div`,{className:`w-full block`,children:(0,Z.jsx)(z,{autoFocus:!0,large:!0,placeholder:l(`setup.accessPointName`),value:n,onChange:e=>r(e.target.value),onFocus:()=>a(!0),onBlur:()=>a(!1)})})})}),(0,Z.jsx)(`div`,{className:N,children:(0,Z.jsxs)(`div`,{className:G,children:[(0,Z.jsx)(A,{onClick:t,children:l(`common.cancel`,`Cancel`)}),(0,Z.jsx)(A,{intent:I.PRIMARY,onClick:o,loading:s,disabled:!c(n),children:l(`common.save`)})]})})]})},Oe=({ap:e,totalApCount:t,toasterRef:i,onRenameTrigger:a,rotateConfirmApId:o,setRotateConfirmApId:c,rotatingApId:l,handleRotate:u,deletingApId:p,handleDelete:m})=>{let{t:h}=d();return(0,Z.jsx)(H,{title:(0,Z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Z.jsx)(s,{size:16}),(0,Z.jsx)(`span`,{children:e.name})]}),className:`shadow-none! rounded-lg!`,children:(0,Z.jsxs)(L,{children:[(0,Z.jsxs)(`div`,{className:`space-y-3`,children:[(0,Z.jsxs)(`div`,{className:`flex justify-between items-start gap-4`,children:[(0,Z.jsx)(`span`,{className:`text-xs opacity-50 mt-1`,children:`DoH URL`}),(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 text-sm font-mono bg-blue-50 text-blue-600 dark:bg-blue-900/20 dark:text-blue-400 px-2 py-1 rounded cursor-pointer hover:bg-blue-100 dark:hover:bg-blue-900/40 transition-colors break-all`,onClick:()=>{navigator.clipboard.writeText(`${window.location.origin}/${e.token}`),i.current?.show({message:h(`setup.copied`),intent:I.SUCCESS})},title:h(`setup.copyUrl`),children:[(0,Z.jsx)(`span`,{className:`select-all`,children:`${window.location.origin}/${e.token}`}),(0,Z.jsx)(_,{size:14,className:`shrink-0`})]})]}),(0,Z.jsxs)(`div`,{className:`flex justify-between items-start gap-4`,children:[(0,Z.jsx)(`span`,{className:`text-xs opacity-50 mt-1`,children:h(`setup.accessPointToken`)}),(0,Z.jsx)(`span`,{className:`text-sm font-mono bg-gray-100 dark:bg-gray-800 px-2 py-1 rounded select-all break-all`,children:e.token})]}),(0,Z.jsxs)(`div`,{className:`flex justify-between items-start gap-4`,children:[(0,Z.jsx)(`span`,{className:`text-xs opacity-50 mt-1`,children:`Created`}),(0,Z.jsx)(`span`,{className:`text-sm`,children:de(new Date(e.created_at*1e3))})]})]}),(0,Z.jsxs)(`div`,{className:`mt-4 flex gap-2 flex-wrap`,children:[(0,Z.jsx)(A,{small:!0,icon:(0,Z.jsx)(n,{size:14}),text:h(`setup.renameAccessPoint`),onClick:()=>a(e.id,e.name)}),(0,Z.jsx)(F,{isOpen:o===e.id,onInteraction:e=>{e||c(null)},content:(0,Z.jsxs)(`div`,{className:`p-4 space-y-3 dark:bg-gray-800 dark:text-white max-w-xs`,children:[(0,Z.jsx)(`p`,{className:`text-xs font-semibold leading-relaxed`,children:h(`setup.rotateTokenConfirmDesc`,`Rotating the key will immediately disconnect devices using the old key. Are you sure you want to continue?`)}),(0,Z.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,Z.jsx)(A,{small:!0,minimal:!0,text:h(`common.cancel`,`Cancel`),onClick:()=>c(null)}),(0,Z.jsx)(A,{small:!0,intent:I.DANGER,text:h(`common.confirm`,`Confirm`),onClick:()=>{c(null),u(e.id)}})]})]}),placement:`top`,children:(0,Z.jsx)(A,{small:!0,icon:(0,Z.jsx)(f,{size:14}),text:h(`setup.rotateToken`),loading:l===e.id,onClick:()=>c(e.id)})}),(0,Z.jsx)(A,{small:!0,intent:I.DANGER,icon:(0,Z.jsx)(r,{size:14}),text:h(`setup.deleteAccessPoint`),loading:p===e.id,onClick:()=>m(e.id),disabled:t<=1,title:t<=1?`Cannot delete the only access point`:void 0})]})]})})},ke=({isOpen:e,onClose:t,profileId:n,isMobile:r,accessPoints:i,loading:a,onRefresh:s,toasterRef:c})=>{let{t:l}=d(),{isAddDialogOpen:u,setIsAddDialogOpen:f,newApName:p,setNewApName:m,isAdding:h,renameApId:g,setRenameApId:_,renameApName:v,setRenameApName:y,isRenaming:b,rotatingApId:x,deletingApId:C,newApNameFocused:w,setNewApNameFocused:T,renameApNameFocused:E,setRenameApNameFocused:D,rotateConfirmApId:O,setRotateConfirmApId:k,isSearchOpen:j,setIsSearchOpen:N,searchQuery:P,setSearchQuery:F,filteredAccessPoints:L,isValidApName:R,handleAdd:B,handleRename:V,handleRotate:H,handleDelete:U}=Te({profileId:n,accessPoints:i,onRefresh:s,toasterRef:c});return(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsxs)(_e,{isOpen:e,onClose:t,title:j?(0,Z.jsx)(z,{leftIcon:`search`,placeholder:l(`setup.searchAccessPoints`,`Search...`),value:P,onChange:e=>F(e.target.value),rightElement:(0,Z.jsx)(A,{icon:`cross`,minimal:!0,onClick:()=>{N(!1),F(``)}}),autoFocus:!0}):(0,Z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Z.jsx)(`span`,{children:l(`setup.manageAccessPoints`)}),(0,Z.jsx)(A,{icon:(0,Z.jsx)(o,{size:14}),minimal:!0,onClick:()=>N(!0),className:`opacity-50 hover:opacity-100`})]}),icon:`diagram-tree`,size:r?`100%`:`450px`,children:[(0,Z.jsx)(A,{fill:!0,intent:I.PRIMARY,icon:(0,Z.jsx)(S,{size:16}),text:l(`setup.addAccessPoint`),onClick:()=>f(!0),large:!0}),a?(0,Z.jsx)(`div`,{className:`flex justify-center p-8`,children:(0,Z.jsx)(M,{})}):(0,Z.jsx)(`div`,{className:`space-y-4 mt-4`,children:L.map(e=>(0,Z.jsx)(Oe,{ap:e,totalApCount:i.length,toasterRef:c,onRenameTrigger:(e,t)=>{_(e),y(t)},rotateConfirmApId:O,setRotateConfirmApId:k,rotatingApId:x,handleRotate:H,deletingApId:C,handleDelete:U},e.id))})]}),(0,Z.jsx)(Ee,{isOpen:u,onClose:()=>{f(!1),m(``)},newApName:p,setNewApName:m,newApNameFocused:w,setNewApNameFocused:T,handleAdd:B,isAdding:h,isValidApName:R}),(0,Z.jsx)(De,{isOpen:!!g,onClose:()=>_(null),renameApName:v,setRenameApName:y,renameApNameFocused:E,setRenameApNameFocused:D,handleRename:V,isRenaming:b,isValidApName:R})]})},Ae=({profileId:e,profileKey:t,profileName:n,toasterRef:r})=>{let i=te(),{t:a}=d(),[o,s]=(0,X.useState)([]),[c,l]=(0,X.useState)(!1),[u,f]=(0,X.useState)(!1),[p,m]=(0,X.useState)(null),h=async()=>{l(!0);try{s(await ce(e))}catch(e){console.error(e)}finally{l(!1)}};(0,X.useEffect)(()=>{h()},[e]);let[g,_]=(0,X.useState)(n||``);(0,X.useEffect)(()=>{n?_(n):e&&se(e).then(e=>{e?.name&&_(e.name)}).catch(()=>{})},[e,n]);let v=(0,X.useMemo)(()=>o.length===0?null:o.find(e=>e.id===p)||o[0],[o,p]),y=v?v.token:t,b=v?v.name:void 0,x=`${window.location.origin}/${y}`,[S,C]=(0,X.useState)(null),[w,T]=(0,X.useState)(!1),[E,D]=(0,X.useState)(!1),[O,k]=(0,X.useState)(!1),[A,j]=(0,X.useState)(null),[M,N]=(0,X.useState)(null),[P,F]=(0,X.useState)({ipv4:[],ipv6:[]}),[L,R]=(0,X.useState)(null),z=e=>{navigator.clipboard.writeText(e),r?.current?.show({message:a(`setup.copied`),intent:I.SUCCESS})},B=async()=>{T(!0),R(null);try{let[t,n]=await Promise.all([ne(),oe()]);if(t.ip&&(t.country===`UNKNOWN`||!t.country))try{let e=await fetch(`/api/geoip?ip=${encodeURIComponent(t.ip)}`);if(e.ok){let n=await e.json();n.success&&(n.country&&(t.country=n.country),n.region&&(t.region=n.region),n.city&&(t.city=n.city),n.timezone?.id&&(t.timezone=n.timezone.id),n.connection?.org&&(t.asOrganization=n.connection.org))}}catch{}C(t),j(n),t.timezone&&t.timezone!==`UNKNOWN`&&le(t.timezone);let r=window.location.hostname===`localhost`||window.location.hostname===`127.0.0.1`||window.location.hostname===`::1`||window.location.hostname.startsWith(`192.168.`)||window.location.hostname.startsWith(`10.`)||/^172\.(1[6-9]|2\d|3[01])\./.test(window.location.hostname),i=!!(t.dotDomain&&!J(t.dotDomain));ae(r&&i||i?t.dotDomain:window.location.hostname||``).then(e=>N(e)).catch(e=>console.warn(`Failed fetching domain geo location:`,e));let a=t.substituteDomain||`www.okx.com`;ie().then(e=>{F(t=>t.ipv4.length>0||t.ipv6.length>0?t:{ipv4:e.ip?[e.ip]:[],ipv6:e.ipv6?[e.ipv6]:[]})}).catch(()=>{}),re(a).then(e=>{(e.ipv4.length>0||e.ipv6.length>0)&&F(e)}).catch(e=>console.warn(`Failed resolving substitute domain DNS IPs:`,e)),R({success:!!t.connectedProfileId,profileMatch:t.connectedProfileId===e})}catch(e){console.error(`Verification failed`,e)}finally{T(!1)}};(0,X.useEffect)(()=>{B()},[e]);let V=(0,X.useMemo)(()=>{let e=[],t=(P.ipv4||[]).slice(0,2),n=(P.ipv6||[]).slice(0,2),r=S?.substituteDomain||`www.okx.com`;for(let n of t)e.push({ip:n,area:`${r} IPv4`});for(let t of n)e.push({ip:t,area:`${r} IPv6`});return e},[P,S?.substituteDomain]);return(0,Z.jsxs)(`div`,{className:`mx-auto space-y-8 pb-24 ${i?`p-1`:`px-8 max-w-5xl`}`,children:[(0,Z.jsx)(ve,{isMobile:i}),(0,Z.jsx)(ye,{isVerifying:w,verifyResult:L,handleVerify:B,isMobile:i,clientInfo:S,showIp:E,setShowIp:D,showLocation:O,setShowLocation:k,traceInfo:A,edgeLocation:M}),(0,Z.jsx)(be,{accessPoints:o,selectedApId:v?.id||null,onSelectAp:m,accessPointName:b,onManageAccessPoints:()=>f(!0),isMobile:i}),(0,Z.jsx)(xe,{dohUrl:x,copyToClipboard:z,isMobile:i}),(0,Z.jsx)(we,{isMobile:i,copyToClipboard:z,profileKey:y,profileName:g||void 0,accessPointName:b,currentIps:V,dotDomain:S?.dotDomain}),(0,Z.jsx)(ke,{isOpen:u,onClose:()=>f(!1),profileId:e,isMobile:i,accessPoints:o,loading:c,onRefresh:h,toasterRef:r})]})};export{Ae as SetupView};
@@ -1 +0,0 @@
1
- import{_ as e,g as t,h as n}from"./index-CrB_HdIL.js";export{t as setSystemLocale,e as setSystemTimeZone};