dns-worker 1.2.1 → 1.2.2-alpha.20cfce0
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.
- package/.env.serverfull +8 -1
- package/dist/serverfull.mjs +294 -196
- package/dist/serverfull.mjs.map +4 -4
- package/migrations/0068_add_isp_hourly_rollups.sql +34 -0
- package/migrations/0069_drop_redundant_logs_indexes.sql +7 -0
- package/package.json +11 -10
- package/static/assets/AccountView-CqywJPAC.js +4 -0
- package/static/assets/{AnalyticsView-DPHx2dY5.js → AnalyticsView-D1LY_X2f.js} +2 -2
- package/static/assets/DestinationMap-CEtw2aBM.js +1 -0
- package/static/assets/FilteringView-BaOVBg9x.js +1 -0
- package/static/assets/LogsView-DMaq2SQ4.js +5 -0
- package/static/assets/{RulesView-CtQt9Fju.js → RulesView-1w0Gsfmf.js} +1 -1
- package/static/assets/SettingsView-BjAq5oi0.js +1 -0
- package/static/assets/{SetupView-DNfTcqJY.js → SetupView-Bl8r4gHO.js} +1 -1
- package/static/assets/{SwipeableDrawer-BuCjl9Vd.js → SwipeableDrawer-UY1QWnPj.js} +1 -1
- package/static/assets/SystemView-g6-diSqy.js +1 -0
- package/static/assets/{TrendChart-wgomUkAw.js → TrendChart-8stYkr8m.js} +1 -1
- package/static/assets/date-BRZZxWiW.js +1 -0
- package/static/assets/de-DE-B5QHxkUz.js +12 -0
- package/static/assets/es-ES-DVG_43hu.js +12 -0
- package/static/assets/fr-FR-C_o9fNbs.js +12 -0
- package/static/assets/index-Bw8TL1xo.js +17 -0
- package/static/assets/index-Dya4nLaI.css +2 -0
- package/static/assets/ja-JP-h0clNIRK.js +12 -0
- package/static/assets/ko-KR-Rr4R4ErI.js +12 -0
- package/static/assets/ru-RU-BKC7ewDw.js +12 -0
- package/static/assets/{services-BF0oUgkb.js → services-DFTZgwAw.js} +1 -1
- package/static/assets/{sqlite.worker-DfuIqYyd.js → sqlite.worker-D8vG3D1o.js} +7 -3
- package/static/assets/{useLogsE2ee-CARmudiz.js → useLogsE2ee-3yU9j9w3.js} +1 -1
- package/static/assets/{vendor-ui-core-C4974KNo.js → vendor-ui-core-CodM8CpF.js} +1 -1
- package/static/assets/vi-VN-DO0is0TQ.js +12 -0
- package/static/assets/zh-CN-D9qLjfXt.js +12 -0
- package/static/assets/zh-TW-qJFPjt4I.js +12 -0
- package/static/index.html +3 -3
- package/static/assets/AccountView-0QcFZ1Jr.js +0 -4
- package/static/assets/DestinationMap-B3EEJV7e.js +0 -1
- package/static/assets/FilteringView-PYhZsfXI.js +0 -1
- package/static/assets/LogsView-DS6lzitI.js +0 -5
- package/static/assets/SettingsView-B6nhXQtx.js +0 -1
- package/static/assets/SystemView-CpIEbDsf.js +0 -1
- package/static/assets/date-BFCCct66.js +0 -1
- package/static/assets/de-DE-DkZSdTly.js +0 -12
- package/static/assets/es-ES-B6WvDhm2.js +0 -12
- package/static/assets/fr-FR-83O7dpp-.js +0 -12
- package/static/assets/index-DEIEgGUw.js +0 -17
- package/static/assets/index-DzxNVvDJ.css +0 -2
- package/static/assets/ja-JP-TsIw1jL8.js +0 -12
- package/static/assets/ko-KR-BJCV1gAO.js +0 -12
- package/static/assets/ru-RU-D7sFMEOm.js +0 -12
- package/static/assets/vi-VN-B01Yq7PJ.js +0 -12
- package/static/assets/zh-CN-DmAkz3rO.js +0 -12
- package/static/assets/zh-TW-osJQe9X5.js +0 -12
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/date-BFCCct66.js","assets/index-DEIEgGUw.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-DYK5a2J9.js","assets/vendor-i18next-DlmslyBB.js","assets/vendor-ui-core-C4974KNo.js","assets/vendor-utils-Bab4qB3W.js","assets/index-DzxNVvDJ.css"])))=>i.map(i=>d[i]);
|
|
2
|
-
import{i as e}from"./rolldown-runtime-C4Xdq4VV.js";import{$ as t,A as n,At as r,B as i,C as a,D as o,M as s,O as c,Q as l,U as u,V as d,Z as f,b as p,bt as m,et as h,ft as g,gt as _,j as v,nn as y,nt as b,ot as x,q as S,st as C,tt as w,w as T,x as E,y as D,yt as O}from"./vendor-react-DYK5a2J9.js";import{S as k,b as A,x as j}from"./vendor-icons-other-BTYC6Wvz.js";import{i as ee}from"./vendor-i18next-DlmslyBB.js";import{B as M,C as N,D as te,F as P,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 G,j as K,p as q,r as J,t as ae,u as oe,v as se,x as Y,z as X}from"./vendor-ui-core-C4974KNo.js";import{_t as ce}from"./vendor-utils-Bab4qB3W.js";import{$t as le,A as Z,At as ue,Bt as de,Ft as fe,Gt as pe,Ht as me,It as he,Jt as ge,K as _e,Kt as ve,Lt as ye,Mt as be,Nt as xe,Pt as Se,Qt as Ce,Rt as we,Ut as Te,Wt as Ee,Xt as De,Yt as Oe,Zt as ke,b as Ae,cn as je,d as Me,en as Ne,f as Pe,h as Fe,hn as Ie,i as Le,jt as Re,kt as ze,l as Be,m as Ve,nn as He,o as Ue,p as We,qt as Ge,r as Ke,rn as qe,s as Je,tn as Ye,u as Xe,v as Ze,x as Qe,y as $e,zt as et}from"./index-DEIEgGUw.js";import{t as tt}from"./async-R_IFRE5c.js";var Q=e(k(),1),$=e(A(),1);const nt=({recoveryKeys:e,copied:t,onCopy:n,onDone:r})=>{let{t:i}=y();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)(s,{size:20,className:`text-green-500`}),(0,$.jsx)(K,{style:{margin:0},children:i(`account.totp.recoveryKeysTitle`,`Save Your Recovery Keys`)})]}),(0,$.jsx)(V,{intent:H.WARNING,className:`mb-4`,children:i(`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)(g,{size:14}),text:t?i(`account.totp.copied`,`Copied!`):i(`account.totp.copyKeys`,`Copy All Keys`),intent:t?H.SUCCESS:H.NONE,onClick:n}),(0,$.jsx)(L,{fill:!0,intent:H.PRIMARY,text:i(`account.totp.done`,`Done, I've saved them`),onClick:r})]})]})},rt=({onRefresh:e,toasterRef:t,user:n})=>{let{t:r}=y(),[i,a]=(0,Q.useState)([]),[o,s]=(0,Q.useState)(!0),[c,l]=(0,Q.useState)(!0),[u,d]=(0,Q.useState)(null),[f,p]=(0,Q.useState)(!1),[m,h]=(0,Q.useState)(null),[g,_]=(0,Q.useState)(!1),[v,b]=(0,Q.useState)(``),[x,S]=(0,Q.useState)(!1),[C,w]=(0,Q.useState)(!1),[T,E]=(0,Q.useState)(``),[D,O]=(0,Q.useState)(null),[k,A]=(0,Q.useState)(``),[j,ee]=(0,Q.useState)(!1),[M,N]=(0,Q.useState)(!1),[te,P]=(0,Q.useState)(``),[F,I]=(0,Q.useState)(null),[ne,L]=(0,Q.useState)(!1),[R,z]=(0,Q.useState)(null),B=(0,Q.useCallback)(async()=>{s(!0);try{a(await et()||[])}catch{}finally{s(!1)}},[]);(0,Q.useEffect)(()=>{l(Ye()),B()},[B]);let V=()=>{b(``),E(``),S(!1),_(!0)},re=async t=>{t.preventDefault();let n=v.trim();if(!Ve(n)){E(r(`account.passkey.formatTip`,`1-30 characters, letters, numbers, hyphens and underscores allowed`));return}w(!0),E(``);try{let t=await Ne({name:n,credential:await qe(await we())}),r=t?.passkey?.id||t?.id;if(r&&Z.isUnlocked())try{await Z.wrapCurrentKeyForPasskey(r)}catch(e){console.warn(`[Passkeys] Failed to wrap existing E2EE key for new passkey:`,e)}_(!1),b(``),await B(),e?.(),t?.recovery_keys&&t.recovery_keys.length>0&&d(t.recovery_keys)}catch(e){console.error(`Passkey registration failed:`,e),E(e instanceof Error?e.message:r(`account.passkey.regFailed`,`Registration failed`))}finally{w(!1)}},U=()=>{u&&navigator.clipboard.writeText(u.join(`
|
|
3
|
-
`)).then(()=>{p(!0),setTimeout(()=>p(!1),2e3)})},ie=e=>{O(e),A(e.name),P(``),ee(!1)},W=async e=>{e.preventDefault();let t=k.trim();if(!(!D||!t)){if(!Ve(t)){P(r(`account.passkey.formatTip`,`1-30 characters, letters, numbers, hyphens and underscores allowed`));return}N(!0),P(``);try{await me(D.id,t),O(null),await B()}catch(e){P(e instanceof Error?e.message:r(`common.errorNetwork`))}finally{N(!1)}}},[G,K]=(0,Q.useState)(``),[q,J]=(0,Q.useState)(``);return{passkeys:i,loading:o,supported:c,recoveryKeys:u,setRecoveryKeys:d,copiedKeys:f,handleCopyRecoveryKeys:U,isAddOpen:g,setIsAddOpen:_,passkeyName:v,setPasskeyName:b,nameFocused:x,setNameFocused:S,registering:C,addError:T,setAddError:E,handleOpenAdd:V,handleRegister:re,editingPasskey:D,setEditingPasskey:O,editName:k,setEditName:A,renameFocused:j,setRenameFocused:ee,renaming:M,renameError:te,setRenameError:P,handleOpenRename:ie,handleRenameSubmit:W,deletingId:F,deleteConfirmOpen:ne,setDeleteConfirmOpen:L,targetToDelete:R,deletePassword:G,setDeletePassword:K,deleteError:q,setDeleteError:J,handleOpenDelete:e=>{z(e),K(``),J(``),L(!0)},handleDeleteSubmit:async()=>{if(R){I(R.id),J(``);try{let t=G;n?.password_version===2&&n.username&&(t=await Me(G,n.username)),await xe(R.id,{password:t}),L(!1),z(null),K(``),await B(),e?.()}catch(e){J(e instanceof Error?e.message:r(`common.errorNetwork`))}finally{I(null)}}},testingId:m,handleTestPasskey:async e=>{h(e?e.id:`all`);try{let n=await ge(e?.id);n.success&&(t?.current?.show({message:r(`account.passkey.testSuccess`,{name:n.passkey?.name||e?.name||``,defaultValue:`Passkey verified successfully: ${n.passkey?.name||e?.name||``}`}),intent:H.SUCCESS,icon:`tick-circle`}),await B())}catch(e){let n=e instanceof Error?e.message:String(e);n.includes(`cancelled`)||n.includes(`NotAllowedError`)||n.includes(`timed out`)||n.includes(`abort`)?t?.current?.show({message:r(`account.passkey.testCancelled`,`Passkey verification cancelled`),intent:H.WARNING,icon:`warning-sign`}):t?.current?.show({message:n||r(`account.passkey.testFailed`,`Passkey verification failed`),intent:H.DANGER,icon:`error`})}finally{h(null)}},fetchPasskeys:B}},it=({passkeys:e,loading:t,deletingId:n,testingId:r,onTestPasskey:i,onOpenRename:a,onOpenDelete:o})=>{let{t:c}=y();return t?(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)(b,{size:28,className:`mx-auto mb-2 opacity-40`}),(0,$.jsx)(`p`,{children:c(`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)(b,{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:[c(`account.passkey.created`,`Added`),`:`,` `,Fe(new Date(e.created_at*1e3))]}),e.last_used_at?(0,$.jsxs)(`span`,{children:[c(`account.passkey.lastUsed`,`Last used`),`:`,` `,Fe(new Date(e.last_used_at*1e3))]}):(0,$.jsx)(`span`,{children:c(`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)(s,{size:14}),title:c(`account.passkey.testThis`,`Test this passkey`),loading:r===e.id,onClick:()=>i?.(e)}),(0,$.jsx)(L,{minimal:!0,small:!0,icon:(0,$.jsx)(u,{size:14}),title:c(`common.rename`,`Rename`),onClick:()=>a(e)}),(0,$.jsx)(L,{minimal:!0,small:!0,intent:H.DANGER,icon:(0,$.jsx)(T,{size:14}),title:c(`common.delete`,`Delete`),loading:n===e.id,onClick:()=>o(e)})]})]},e.id))})},at=({isOpen:e,onClose:t,passkeyName:n,setPasskeyName:r,nameFocused:i,setNameFocused:a,registering:o,addError:s,setAddError:c,onSubmit:l})=>{let{t:u}=y();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)(q,{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)(se,{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:X,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})]})})]})})},ot=({isOpen:e,onClose:t,editName:n,setEditName:r,renameFocused:i,setRenameFocused:a,renaming:o,renameError:s,setRenameError:c,onSubmit:l})=>{let{t:u}=y();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)(q,{label:u(`account.passkey.appNameLabel`,`Application (Domain)`),children:(0,$.jsx)(W,{readOnly:!0,disabled:!0,leftIcon:`globe`,value:window.location.hostname})}),(0,$.jsx)(q,{label:u(`account.passkey.nameLabel`,`Passkey Name`),helperText:u(`account.passkey.formatTip`,`1-30 characters, letters, numbers, hyphens and underscores allowed`),children:(0,$.jsx)(se,{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:X,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})]})})]})})},st=({isOpen:e,onClose:t,targetToDelete:n,deleting:r,onConfirm:i,password:a,setPassword:o,error:s})=>{let{t:c}=y();return(0,$.jsx)(R,{isOpen:e,onClose:()=>!r&&t(),title:c(`account.passkey.deleteTitle`,`Delete Passkey`),className:`max-w-md`,children:(0,$.jsxs)(`form`,{onSubmit:e=>{e.preventDefault(),a&&i()},children:[(0,$.jsxs)(`div`,{className:I,children:[(0,$.jsx)(`p`,{children:c(`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})}),o&&(0,$.jsx)(q,{label:c(`account.totp.enterPassword`,`Enter your password to confirm:`),labelFor:`delete-passkey-password`,className:`mt-3`,children:(0,$.jsx)(W,{id:`delete-passkey-password`,type:`password`,placeholder:c(`account.totp.passwordPlaceholder`,`Account password`),value:a||``,onChange:e=>o(e.target.value),autoFocus:!0})}),s&&(0,$.jsx)(V,{intent:H.DANGER,className:`mt-2 text-xs`,children:s})]}),(0,$.jsx)(`div`,{className:B,children:(0,$.jsxs)(`div`,{className:X,children:[(0,$.jsx)(L,{text:c(`common.cancel`,`Cancel`),onClick:t,disabled:r}),(0,$.jsx)(L,{intent:H.DANGER,text:c(`common.delete`,`Delete`),type:`submit`,loading:r,disabled:r||!(a||``).trim()})]})})]})})},ct=({onRefresh:e,user:t})=>{let{t:n}=y(),r=(0,Q.useRef)(null),{passkeys:i,loading:a,supported:o,recoveryKeys:c,setRecoveryKeys:l,copiedKeys:u,handleCopyRecoveryKeys:f,isAddOpen:p,setIsAddOpen:m,passkeyName:h,setPasskeyName:g,nameFocused:_,setNameFocused:b,registering:x,addError:S,setAddError:C,handleOpenAdd:T,handleRegister:E,editingPasskey:D,setEditingPasskey:O,editName:k,setEditName:A,renameFocused:j,setRenameFocused:ee,renaming:M,renameError:N,setRenameError:te,handleOpenRename:P,handleRenameSubmit:F,deletingId:I,deleteConfirmOpen:ne,setDeleteConfirmOpen:R,targetToDelete:z,deletePassword:B,setDeletePassword:re,deleteError:U,handleOpenDelete:ie,handleDeleteSubmit:W,testingId:G,handleTestPasskey:q}=rt({onRefresh:e,toasterRef:r,user:t});return c?(0,$.jsx)(nt,{recoveryKeys:c,copied:u,onCopy:f,onDone:()=>l(null)}):(0,$.jsxs)(`div`,{className:`space-y-4`,children:[(0,$.jsx)(ae,{ref:r}),(0,$.jsxs)(`div`,{className:`flex flex-col sm:flex-row sm:items-center justify-between gap-3 mb-4`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[(0,$.jsx)(w,{size:20,className:`text-purple-500`}),(0,$.jsx)(K,{style:{margin:0},children:n(`account.passkey.title`,`Passkeys`)}),(0,$.jsx)(J,{intent:i.length>0?H.SUCCESS:H.NONE,minimal:!0,round:!0,className:`whitespace-nowrap`,children:i.length>0?n(`account.passkey.count`,{count:i.length,defaultValue:`${i.length} configured`}):n(`account.passkey.none`,`None configured`)})]}),(0,$.jsxs)(`div`,{className:`flex items-center gap-2 flex-wrap shrink-0`,children:[o&&i.length>0&&(0,$.jsx)(L,{intent:H.NONE,outlined:!0,icon:(0,$.jsx)(s,{size:16}),text:n(`account.passkey.testBtn`,`Test Passkey`),onClick:()=>q(),loading:G===`all`,className:`whitespace-nowrap`}),o&&(0,$.jsx)(L,{intent:H.PRIMARY,icon:(0,$.jsx)(d,{size:16}),text:n(`account.passkey.addBtn`,`Add Passkey`),onClick:T,className:`whitespace-nowrap`})]})]}),(0,$.jsx)(`p`,{className:`text-sm text-gray-600 dark:text-gray-400 mb-4`,children:n(`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:null,className:`mb-4`,children:(0,$.jsxs)(`div`,{className:`flex items-center gap-2 text-sm`,children:[(0,$.jsx)(v,{className:`w-4 h-4 shrink-0`}),(0,$.jsx)(`span`,{children:n(`account.passkey.notSupported`,`Your browser or device does not support Passkeys (WebAuthn).`)})]})}),(0,$.jsx)(it,{passkeys:i,loading:a,deletingId:I,testingId:G,onTestPasskey:q,onOpenRename:P,onOpenDelete:ie}),(0,$.jsx)(at,{isOpen:p,onClose:()=>m(!1),passkeyName:h,setPasskeyName:g,nameFocused:_,setNameFocused:b,registering:x,addError:S,setAddError:C,onSubmit:E}),(0,$.jsx)(ot,{isOpen:!!D,onClose:()=>O(null),editName:k,setEditName:A,renameFocused:j,setRenameFocused:ee,renaming:M,renameError:N,setRenameError:te,onSubmit:F}),(0,$.jsx)(st,{isOpen:ne,onClose:()=>R(!1),targetToDelete:z,deleting:!!I,onConfirm:W,password:B,setPassword:re,error:U})]})},lt=({isOpen:e,onClose:t})=>{let{t:n}=y(),[r,i]=(0,Q.useState)(``),[a,o]=(0,Q.useState)(!1),[s,c]=(0,Q.useState)(``),[l,u]=(0,Q.useState)(!1);(0,Q.useEffect)(()=>{e&&(i(``),c(``),u(!1),o(!1))},[e]);let d=async e=>{let t=(e??r).trim().replace(/\s/g,``);if(t.length!==6){c(n(`account.totp.invalidCode`,`Please enter a 6-digit code`));return}o(!0),c(``),u(!1);try{await Oe(t),u(!0)}catch(e){c((e instanceof Error?e.message:String(e))||n(`account.totp.testFailed`,`Invalid verification code`))}finally{o(!1)}};return(0,$.jsx)(R,{isOpen:e,onClose:t,title:n(`account.totp.testTitle`,`Test Authenticator App (TOTP)`),icon:(0,$.jsx)(b,{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:n(`account.totp.testDesc`,`Enter the 6-digit verification code from your authenticator app to verify that it is generating valid codes.`)}),l&&(0,$.jsx)(V,{intent:H.SUCCESS,icon:null,children:(0,$.jsxs)(`div`,{className:`flex items-center gap-2 text-sm`,children:[(0,$.jsx)(_,{className:`w-4 h-4 shrink-0`}),(0,$.jsx)(`span`,{children:n(`account.totp.testSuccess`,`Verification successful! Your authenticator app is configured properly.`)})]})}),s&&(0,$.jsx)(V,{intent:H.DANGER,children:s}),(0,$.jsxs)(`form`,{onSubmit:e=>{e.preventDefault(),d()},className:`space-y-4`,children:[(0,$.jsx)(q,{label:n(`account.totp.verificationCode`,`6-Digit Verification Code`),labelFor:`test-totp-input`,children:(0,$.jsx)(W,{id:`test-totp-input`,value:r,onChange:e=>{let t=e.target.value.replace(/\D/g,``).slice(0,6);i(t),c(``),u(!1),t.length===6&&d(t)},placeholder:`123456`,maxLength:6,autoFocus:!0,inputMode:`numeric`,autoComplete:`one-time-code`,className:`font-mono text-lg tracking-widest`,disabled:a})}),(0,$.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,$.jsx)(L,{text:l?n(`common.close`,`Close`):n(`common.cancel`,`Cancel`),onClick:t}),!l&&(0,$.jsx)(L,{intent:H.PRIMARY,text:n(`account.totp.verifyBtn`,`Verify`),type:`submit`,loading:a,disabled:r.length!==6})]})]})]})})},ut=({user:e,disableDialogOpen:t,setDisableDialogOpen:r,disablePassword:i,setDisablePassword:a,disableError:s,setDisableError:c,disableLoading:l,onDisable:u})=>{let{t:d}=y(),[f,p]=Q.useState(!1),[m,h]=Q.useState(!1);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 mb-4`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[(0,$.jsx)(o,{size:20,className:`text-blue-500`}),(0,$.jsx)(K,{style:{margin:0},children:d(`account.totp.title`,`Authenticator App (TOTP)`)}),(0,$.jsx)(J,{intent:H.SUCCESS,minimal:!0,round:!0,className:`whitespace-nowrap`,children:d(`account.totp.enabled`,`Enabled`)})]}),(0,$.jsxs)(`div`,{className:`flex items-center gap-2 flex-wrap shrink-0`,children:[(0,$.jsx)(L,{outlined:!0,icon:(0,$.jsx)(b,{size:14}),text:d(`account.totp.testBtn`,`Test Code`),onClick:()=>h(!0),className:`whitespace-nowrap`}),(0,$.jsx)(L,{intent:H.DANGER,outlined:!0,icon:(0,$.jsx)(n,{size:14}),text:d(`account.totp.disable`,`Disable Authenticator App (TOTP)`),onClick:()=>r(!0),className:`whitespace-nowrap`})]})]}),(0,$.jsx)(`div`,{className:`space-y-4`,children:(0,$.jsx)(`p`,{className:`text-sm text-gray-600 dark:text-gray-400`,children:d(`account.totp.activeDesc`,`Authenticator app (TOTP) is active and generating 6-digit verification codes for your account.`)})}),(0,$.jsx)(R,{isOpen:t,onClose:()=>{r(!1),a(``),c(``),p(!1)},title:d(`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:d(`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)(q,{label:d(`account.currentPassword`),children:(0,$.jsx)(W,{type:f?`text`:`password`,leftIcon:`lock`,value:i,onChange:e=>a(e.target.value),rightElement:(0,$.jsx)(L,{minimal:!0,icon:f?`eye-open`:`eye-off`,onClick:()=>p(!f),title:f?d(`auth.hidePassword`,`Hide password`):d(`auth.showPassword`,`Show password`)}),required:!0})}),(0,$.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,$.jsx)(L,{text:d(`account.cancel`),onClick:()=>r(!1)}),(0,$.jsx)(L,{intent:H.DANGER,text:d(`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:d(`account.cancel`),onClick:()=>r(!1)}),(0,$.jsx)(L,{intent:H.DANGER,text:d(`account.totp.confirmDisable`,`Disable TOTP`),loading:l,onClick:u})]})]})}),(0,$.jsx)(lt,{isOpen:m,onClose:()=>h(!1)})]})},dt=({setupData:e,setupToken:t,setSetupToken:n,setupError:r,setupLoading:i,onStartSetup:a,onConfirmSetup:s,onCancel:l})=>{let{t:u}=y();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 mb-4`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[(0,$.jsx)(o,{size:20,className:`text-blue-500`}),(0,$.jsx)(K,{style:{margin:0},children:u(`account.totp.title`,`Authenticator App (TOTP)`)}),(0,$.jsx)(J,{minimal:!0,round:!0,intent:H.NONE,className:`whitespace-nowrap`,children:u(`account.totp.disabled`,`Disabled`)})]}),!e&&(0,$.jsx)(L,{intent:H.PRIMARY,icon:(0,$.jsx)(c,{size:14}),text:u(`account.totp.setupBtn`,`Set Up Authenticator App (TOTP)`),loading:i,onClick:a,className:`whitespace-nowrap self-start sm:self-auto`})]}),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:s,className:`space-y-3`,children:[(0,$.jsx)(q,{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})]})]})},ft=({user:e,onRefresh:t})=>{let{t:n}=y(),[r,i]=(0,Q.useState)(null),[a,o]=(0,Q.useState)(``),[s,c]=(0,Q.useState)(null),[l,u]=(0,Q.useState)(!1),[d,f]=(0,Q.useState)(``),[p,m]=(0,Q.useState)(!1),[h,g]=(0,Q.useState)(!1),[_,v]=(0,Q.useState)(``),[b,x]=(0,Q.useState)(!1),[S,C]=(0,Q.useState)(``),[w,T]=(0,Q.useState)(!1);return s?(0,$.jsx)(nt,{recoveryKeys:s,copied:p,onCopy:()=>{s&&navigator.clipboard.writeText(s.join(`
|
|
4
|
-
`)).then(()=>{m(!0),setTimeout(()=>m(!1),2e3)})},onDone:()=>c(null)}):e.totp_enabled?(0,$.jsx)(ut,{user:e,settingsLoading:w,onToggleSkipPassword:async e=>{T(!0);try{await le(e),t()}catch{}finally{T(!1)}},disableDialogOpen:h,setDisableDialogOpen:g,disablePassword:_,setDisablePassword:v,disableError:S,setDisableError:C,disableLoading:b,onDisable:async r=>{r.preventDefault(),x(!0),C(``);try{let n=_;e.password_version===2&&(n=await Me(_,e.username)),await Se(n),g(!1),v(``),t()}catch(e){C(e.message||n(`common.errorNetwork`))}finally{x(!1)}}}):(0,$.jsx)(dt,{setupData:r,setupToken:a,setSetupToken:o,setupError:d,setupLoading:l,onStartSetup:async()=>{u(!0),f(``);try{i(await Ge())}catch(e){f(e.message||n(`common.errorNetwork`))}finally{u(!1)}},onConfirmSetup:async e=>{if(e.preventDefault(),r){u(!0),f(``);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 Re({secret:r.secret,totpTokenHash:u,salt:n})).recovery_keys),i(null),o(``),t()}catch(e){f(e.message||n(`common.errorNetwork`))}finally{u(!1)}}},onCancel:()=>{i(null),o(``),f(``)}})},pt=({method:e,onSelectMethod:n,hasPasskey:r,hasRecoveryKey:i,hasTotp:a,hasPassword:o})=>{let{t:c}=y();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)(w,{size:14}),text:c(`account.mfa.passkey`,`Passkey`),onClick:()=>n(`passkey`)}),i&&(0,$.jsx)(L,{small:!0,active:e===`recovery_key`,intent:e===`recovery_key`?H.PRIMARY:H.NONE,icon:(0,$.jsx)(w,{size:14}),text:c(`account.recoveryKey.verifyBtn`,`Recovery Key`),onClick:()=>n(`recovery_key`)}),a&&(0,$.jsx)(L,{small:!0,active:e===`totp`,intent:e===`totp`?H.PRIMARY:H.NONE,icon:(0,$.jsx)(s,{size:14}),text:c(`account.mfa.totp`,`TOTP`),onClick:()=>n(`totp`)}),o&&(0,$.jsx)(L,{small:!0,active:e===`password`,intent:e===`password`?H.PRIMARY:H.NONE,icon:(0,$.jsx)(t,{size:14}),text:c(`account.mfa.password`,`Password`),onClick:()=>n(`password`)})]})})})},mt=({loading:e,onVerify:t})=>{let{t:n}=y();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)(w,{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)(w,{size:16}),text:n(`account.usePasskeyInstead`,`Authenticate with Passkey`)})]})},ht=({totpCode:e,setTotpCode:t,loading:n,onVerify:r})=>{let{t:i}=y();return(0,$.jsxs)(`div`,{className:`py-2 space-y-4`,children:[(0,$.jsx)(q,{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`)})]})},gt=({password:e,setPassword:t,showPassword:n,setShowPassword:r,loading:i,onSubmit:a})=>{let{t:o}=y();return(0,$.jsxs)(`form`,{onSubmit:a,className:`py-2 space-y-4`,children:[(0,$.jsx)(q,{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`)})]})},_t=({recoveryKey:e,setRecoveryKey:t,loading:n,onSubmit:r})=>{let{t:i}=y();return(0,$.jsxs)(`form`,{onSubmit:r,autoComplete:`off`,className:`py-2 space-y-4`,children:[(0,$.jsx)(q,{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 vt=(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 yt=({isOpen:e,onClose:t,user:n,title:r,onVerify:i,allowedMethods:a})=>{let{t:o}=y(),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`),d=s.includes(`recovery_key`),f=vt(n,a),[p,m]=(0,Q.useState)(f),[h,g]=(0,Q.useState)(``),[_,v]=(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),m(f),g(``),v(!1),x(``),C(``),D(``)):O&&!e&&k(!1),(0,Q.useEffect)(()=>{p===`passkey`&&!c?m(d?`recovery_key`:l?`totp`:`password`):p===`totp`&&!l?m(c?`passkey`:d?`recovery_key`:`password`):p===`recovery_key`&&!d&&m(c?`passkey`:l?`totp`:`password`)},[c,l,d,p]);let A=async e=>{if(e&&e.preventDefault(),!h){D(o(`auth.passwordRequired`,`Password is required`));return}T(!0),D(``);try{let e=h;n?.password_version===2&&n?.username&&(e=await Me(h,n.username)),await i({password:e}),t()}catch(e){D(Xe(e,o))}finally{T(!1)}},j=async()=>{T(!0),D(``);try{await i({passkeyAssertion:await He(await ye())}),t()}catch(e){D(Xe(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(Xe(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(Xe(e,o))}finally{T(!1)}},N=(c?1:0)+(d?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)(pt,{method:p,onSelectMethod:e=>{m(e),D(``)},hasPasskey:c,hasRecoveryKey:d,hasTotp:l,hasPassword:u}),E&&(0,$.jsx)(V,{intent:H.DANGER,className:`mb-4`,children:E}),p===`recovery_key`&&(0,$.jsx)(_t,{recoveryKey:S,setRecoveryKey:C,loading:w,onSubmit:M}),p===`passkey`&&(0,$.jsx)(mt,{loading:w,onVerify:j}),p===`totp`&&(0,$.jsx)(ht,{totpCode:b,setTotpCode:x,loading:w,onVerify:ee}),p===`password`&&(0,$.jsx)(gt,{password:h,setPassword:g,showPassword:_,setShowPassword:v,loading:w,onSubmit:A})]})})},bt=({user:e,onRefresh:n})=>{let{t:r}=y(),[a,o]=(0,Q.useState)(!1),[c,l]=(0,Q.useState)(!1),[u,d]=(0,Q.useState)(null),[f,p]=(0,Q.useState)(!1),[h,_]=(0,Q.useState)(!1),[b,S]=(0,Q.useState)(null),T=!!(e.has_recovery_keys||e.recovery_keys_encrypted),E=()=>{S(null),l(!0)},D=()=>{l(!1),o(!0)},O=async e=>{let t=await pe(e);d(t.recovery_key),p(!1);let i=!1;if(Z.isUnlocked())try{await Z.wrapCurrentKeyForRecovery(t.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(t.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(t.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){S({text:r(`account.recoveryKey.rotateSuccessE2eeWarning`,`恢复密钥已成功轮换!注意:由于端到端加密此前处于锁定状态且未能解密,旧 E2EE 密文仍需使用轮换前的旧恢复密钥解锁,或可在下方端到端加密卡片中点击「重置密钥对」。`),intent:H.WARNING}),n();return}}catch{}S({text:r(`account.recoveryKey.rotateSuccess`,`恢复密钥已成功轮换!请立即妥善离线保存新密钥,旧密钥已失效。`),intent:H.SUCCESS}),n()},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)(w,{size:18,className:`text-amber-500`}),(0,$.jsx)(K,{style:{margin:0},children:r(`account.recoveryKey.title`,`紧急恢复密钥`)}),(0,$.jsx)(J,{intent:T?H.SUCCESS:H.NONE,minimal:!0,round:!0,children:T?r(`account.recoveryKey.configured`,`已配置`):r(`account.recoveryKey.notConfigured`,`未配置`)}),(0,$.jsx)(se,{content:r(`account.recoveryKey.oneWayTooltip`,`采用 SHA-256 单向密码学散列保护,服务端不存储明文且不可解密,仅支持身份轮换验证。`),position:M.TOP,children:(0,$.jsx)(J,{intent:H.PRIMARY,minimal:!0,round:!0,icon:(0,$.jsx)(s,{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)(i,{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 进行轮换。密钥一旦被使用将立即自动轮换。`)}),b&&(0,$.jsx)(V,{intent:b.intent,className:`my-2`,children:b.text}),u&&(0,$.jsxs)(Y,{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)(v,{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:f?(0,$.jsx)(x,{size:14}):(0,$.jsx)(C,{size:14}),onClick:()=>p(!f),title:f?r(`auth.showPassword`,`显示`):r(`auth.hidePassword`,`隐藏`)}),(0,$.jsx)(L,{minimal:!0,small:!0,icon:h?(0,$.jsx)(m,{size:14,className:`text-green-500`}):(0,$.jsx)(g,{size:14}),onClick:()=>k(u),title:r(`common.copy`,`复制`),text:h?r(`common.copied`,`已复制`):r(`common.copy`,`复制`)}),(0,$.jsx)(L,{minimal:!0,small:!0,icon:`cross`,onClick:()=>d(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:f?`••••••-••••••-••••••-••••••-••••••`:u}),(0,$.jsxs)(`p`,{className:`text-xs text-amber-700 dark:text-amber-400 flex items-center gap-1`,children:[(0,$.jsx)(t,{size:14,className:`shrink-0`}),r(`account.recoveryKey.oneWayWarning`,`注意:此密钥仅在此显示一次,关闭后将无法再次查看!服务端仅保存不可逆散列,请务必将其妥善复制并离线安全保存。`)]})]}),(0,$.jsx)(te,{isOpen:c,onConfirm:D,onCancel:()=>l(!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)(yt,{isOpen:a,onClose:()=>o(!1),user:e,allowedMethods:[`passkey`,`recovery_key`],title:r(`account.recoveryKey.rotateVerifyTitle`,`验证身份以轮换恢复密钥`),onVerify:O})]})},xt=({user:e,onRefresh:t})=>{let{t:n}=y(),[r,i]=(0,Q.useState)(!1),a=!!(e.mfa_enabled??(e.totp_enabled||e.passkeys_count&&e.passkeys_count>0)),o=async e=>{i(!0);try{await ke(e),t()}catch(e){alert(e.message||n(`common.errorNetwork`,`Network error`))}finally{i(!1)}};return(0,$.jsxs)(Y,{elevation:F.ONE,className:`space-y-6`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`div`,{className:`flex flex-col sm:flex-row sm:items-center justify-between gap-2 mb-3`,children:(0,$.jsxs)(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[(0,$.jsx)(s,{size:20,className:a?`text-green-500`:`text-gray-400`}),(0,$.jsx)(K,{style:{margin:0},children:n(`account.mfa.title`,`Multi-Factor Authentication (MFA)`)}),(0,$.jsx)(J,{intent:a?H.SUCCESS:H.NONE,minimal:!0,round:!0,className:`whitespace-nowrap`,children:a?n(`account.mfa.enabled`,`Configured`):n(`account.mfa.notConfigured`,`Not Configured`)})]})}),(0,$.jsx)(`p`,{className:`text-sm text-gray-600 dark:text-gray-400 mb-4`,children:n(`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.`)}),a?(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:n(`account.mfa.passwordlessTitle`,`Passwordless Login`)}),(0,$.jsx)(`div`,{className:`text-xs text-gray-500 dark:text-gray-400`,children:n(`account.mfa.passwordlessDesc`,`When enabled, logging in will skip the password requirement and verify your identity directly via Passkey or TOTP.`)})]}),(0,$.jsx)(G,{checked:!!e.totp_skip_password,onChange:e=>o(e.currentTarget.checked),disabled:r,className:`mb-0 shrink-0`})]})]}):(0,$.jsx)(V,{intent:H.PRIMARY,icon:null,children:(0,$.jsxs)(`div`,{className:`flex items-start gap-2 text-sm`,children:[(0,$.jsx)(b,{className:`w-4 h-4 shrink-0 mt-0.5`}),(0,$.jsx)(`span`,{children:n(`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)(ct,{user:e,onRefresh:t}),(0,$.jsx)(U,{}),(0,$.jsx)(ft,{user:e,onRefresh:t}),(0,$.jsx)(U,{}),(0,$.jsx)(bt,{user:e,onRefresh:t})]})},St={signup:{label:`account.activity.signup`,icon:(0,$.jsx)(E,{size:14}),intent:H.SUCCESS},login_success:{label:`account.activity.loginSuccess`,icon:(0,$.jsx)(l,{size:14}),intent:H.SUCCESS},login_fail:{label:`account.activity.loginFail`,icon:(0,$.jsx)(a,{size:14}),intent:H.DANGER},logout:{label:`account.activity.logout`,icon:(0,$.jsx)(f,{size:14}),intent:H.NONE},password_change_success:{label:`account.activity.pwChangeSuccess`,icon:(0,$.jsx)(w,{size:14}),intent:H.SUCCESS},password_change_fail:{label:`account.activity.pwChangeFail`,icon:(0,$.jsx)(a,{size:14}),intent:H.DANGER},totp_verify_success:{label:`account.activity.totpVerifySuccess`,icon:(0,$.jsx)(s,{size:14}),intent:H.SUCCESS},totp_verify_fail:{label:`account.activity.totpVerifyFail`,icon:(0,$.jsx)(a,{size:14}),intent:H.DANGER},totp_setup:{label:`account.activity.totpSetup`,icon:(0,$.jsx)(c,{size:14}),intent:H.PRIMARY},totp_removed:{label:`account.activity.totpRemoved`,icon:(0,$.jsx)(n,{size:14}),intent:H.WARNING},recovery_key_used:{label:`account.activity.recoveryKeyUsed`,icon:(0,$.jsx)(w,{size:14}),intent:H.WARNING},recovery_key_rotated:{label:`account.activity.recoveryKeyRotated`,icon:(0,$.jsx)(w,{size:14}),intent:H.WARNING},session_revoked:{label:`account.activity.sessionRevoked`,icon:(0,$.jsx)(f,{size:14}),intent:H.WARNING},passkey_registered:{label:`account.activity.passkeyRegistered`,icon:(0,$.jsx)(w,{size:14}),intent:H.PRIMARY},passkey_deleted:{label:`account.activity.passkeyDeleted`,icon:(0,$.jsx)(n,{size:14}),intent:H.WARNING},passkey_verify_success:{label:`account.activity.passkeyVerifySuccess`,icon:(0,$.jsx)(s,{size:14}),intent:H.SUCCESS},passkey_verify_fail:{label:`account.activity.passkeyVerifyFail`,icon:(0,$.jsx)(a,{size:14}),intent:H.DANGER}},Ct=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`},wt=(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},Tt=({userAgent:e})=>{let{t}=y();if(!e)return(0,$.jsx)(`span`,{className:`text-gray-500`,children:`—`});let n=wt(e,t(`account.sessions.unknownDevice`,`Unknown Device`));return(0,$.jsxs)(`div`,{children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(P,{icon:Ct(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})]})},Et=({hoveredSessionId:e,setHoveredSessionId:t})=>{let{t:n}=y(),[a,o]=(0,Q.useState)([]),[s,c]=(0,Q.useState)(!0),[l,u]=(0,Q.useState)(!0),[d,f]=(0,Q.useState)(!1),p=(0,Q.useCallback)(async e=>{c(!0);try{let t=new URLSearchParams({limit:`20`});e&&t.set(`before`,String(e));let n=await fe(t.toString());o(e?e=>[...e,...n]:n),u(n.length===20)}catch{}finally{c(!1)}},[]);(0,Q.useEffect)(()=>{p()},[p]);let m=()=>{let e=a[a.length-1];e&&p(e.timestamp)},h=e=>St[e]??{label:e,icon:(0,$.jsx)(r,{size:14}),intent:H.NONE};return(0,$.jsxs)(Y,{elevation:F.ONE,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between cursor-pointer`,onClick:()=>f(!d),children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(r,{size:20,className:`text-purple-500`}),(0,$.jsx)(K,{style:{margin:0},children:n(`account.activity.title`,`Account Activity`)}),a.length>0&&(0,$.jsxs)(J,{minimal:!0,round:!0,intent:H.NONE,children:[a.length,l?`+`:``]})]}),(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(L,{minimal:!0,icon:(0,$.jsx)(i,{size:14}),onClick:e=>{e.stopPropagation(),p()}}),(0,$.jsx)(O,{size:16,className:`text-gray-400 transition-transform ${d?`rotate-180`:``}`})]})]}),d&&(0,$.jsx)(`div`,{className:`mt-4`,children:s&&a.length===0?(0,$.jsx)(`div`,{className:`flex justify-center py-8`,children:(0,$.jsx)(z,{size:24})}):a.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)(oe,{interactive:!0,striped:!0,className:`w-full text-sm whitespace-nowrap`,children:[(0,$.jsx)(`thead`,{children:(0,$.jsxs)(`tr`,{children:[(0,$.jsx)(`th`,{className:`whitespace-nowrap`,children:n(`account.activity.action`,`Action`)}),(0,$.jsx)(`th`,{className:`whitespace-nowrap`,children:n(`account.activity.time`,`Time`)}),(0,$.jsx)(`th`,{className:`whitespace-nowrap`,children:n(`account.activity.session`,`Session`)}),(0,$.jsx)(`th`,{className:`whitespace-nowrap`,children:n(`account.activity.ip`,`IP Address`)}),(0,$.jsx)(`th`,{className:`whitespace-nowrap`,children:n(`account.activity.device`,`Device`)})]})}),(0,$.jsx)(`tbody`,{children:a.map(r=>{let i=h(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)(J,{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:Fe(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)(Tt,{userAgent:r.user_agent||null})})]},r.id)})})]}),l&&(0,$.jsx)(`div`,{className:`flex justify-center mt-3`,children:(0,$.jsx)(L,{minimal:!0,loading:s,text:n(`account.activity.loadMore`,`Load More`),onClick:m})})]})})]})},Dt=({hoveredSessionId:e,setHoveredSessionId:t})=>{let{t:n}=y(),[r,a]=(0,Q.useState)([]),[o,s]=(0,Q.useState)(!0),[c,l]=(0,Q.useState)(null),[u,d]=(0,Q.useState)(!1),[p,m]=(0,Q.useState)(!1),h=r.filter(e=>!e.is_current).length,g=(0,Q.useCallback)(async()=>{s(!0);try{let e=await de(),t=Date.now();a((e||[]).filter(e=>e.expires_at*1e3>t))}catch{}finally{s(!1)}},[]);(0,Q.useEffect)(()=>{g()},[g]);let _=async e=>{l(e);try{(await Ee(e)).is_current?window.location.reload():a(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)(Y,{elevation:F.ONE,children:[(0,$.jsxs)(`div`,{className:`flex flex-col sm:flex-row sm:items-center justify-between gap-3 mb-4`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(S,{size:20,className:`text-green-500`}),(0,$.jsx)(K,{style:{margin:0},children:n(`account.sessions.title`,`Active Sessions`)})]}),(0,$.jsxs)(`div`,{className:`flex items-center gap-2 flex-wrap shrink-0`,children:[h>0&&(0,$.jsx)(L,{small:!0,minimal:!0,intent:H.DANGER,icon:(0,$.jsx)(f,{size:14}),text:n(`account.sessions.revokeOthers`,`Revoke Other Sessions`),loading:u,onClick:()=>m(!0),className:`whitespace-nowrap`}),(0,$.jsx)(L,{minimal:!0,icon:(0,$.jsx)(i,{size:14}),onClick:()=>g()})]})]}),o?(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)(oe,{interactive:!0,striped:!0,className:`w-full text-sm whitespace-nowrap`,children:[(0,$.jsx)(`thead`,{children:(0,$.jsxs)(`tr`,{children:[(0,$.jsx)(`th`,{className:`whitespace-nowrap`,children:n(`account.sessions.device`,`Device`)}),(0,$.jsx)(`th`,{className:`whitespace-nowrap`,children:n(`account.sessions.session`,`Session`)}),(0,$.jsx)(`th`,{className:`whitespace-nowrap`,children:n(`account.sessions.ip`,`IP Address`)}),(0,$.jsx)(`th`,{className:`whitespace-nowrap`,children:n(`account.sessions.loginTime`,`Login Time`)}),(0,$.jsx)(`th`,{className:`whitespace-nowrap`,children:n(`account.sessions.expires`,`Expires`)}),(0,$.jsx)(`th`,{className:`whitespace-nowrap`,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)(Tt,{userAgent:r.user_agent}),r.is_current&&(0,$.jsx)(J,{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?Fe(new Date(r.created_at*1e3)):`—`}),(0,$.jsx)(`td`,{className:`text-xs text-gray-500 align-middle`,children:Fe(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)(f,{size:14}),text:n(`account.sessions.revoke`,`Revoke`),loading:c===r.id,onClick:()=>_(r.id)})})]},r.id))})]})}),(0,$.jsx)(te,{isOpen:p,cancelButtonText:n(`common.cancel`,`Cancel`),confirmButtonText:n(`account.sessions.confirmRevokeOthers`,`Revoke Other Sessions`),intent:H.DANGER,icon:`log-out`,onCancel:()=>m(!1),onConfirm:async()=>{d(!0);try{await Te(),a(e=>e.filter(e=>e.is_current)),m(!1)}catch(e){alert(e.message||n(`account.sessions.revokeFailed`,`Failed to revoke session.`))}finally{d(!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.`)})})]})},Ot=({isAdmin:e,onLogsCleared:t,user:n})=>{let{t:r}=y(),[i,a]=(0,Q.useState)(!1),[o,s]=(0,Q.useState)(!1),[c,l]=(0,Q.useState)(``),[u,d]=(0,Q.useState)(!1),[f,p]=(0,Q.useState)(``);return(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(K,{className:`text-red-500 flex items-center gap-2`,children:[(0,$.jsx)(T,{size:20}),` `,r(`account.dangerZone`)]}),(0,$.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-6`,children:[(0,$.jsxs)(Y,{elevation:F.ONE,className:`flex flex-col justify-between`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(K,{children:r(`account.clearLogs`)}),(0,$.jsx)(`p`,{className:`text-xs opacity-60 mb-3`,children:r(`account.clearLogsDesc`)})]}),(0,$.jsx)(L,{fill:!0,intent:H.DANGER,text:r(`account.clearLogsBtn`),icon:`trash`,loading:i,onClick:async()=>{if(confirm(r(`account.confirmClearLogs`))){a(!0);try{await ze(),alert(r(`account.clearLogsSuccess`)),t?.()}catch(e){console.error(e)}finally{a(!1)}}}})]}),!e&&(0,$.jsxs)(Y,{elevation:F.ONE,className:`flex flex-col justify-between`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(K,{children:r(`account.deleteAccount`)}),(0,$.jsx)(`p`,{className:`text-xs opacity-60 mb-4`,children:r(`account.deleteAccountDesc`)})]}),(0,$.jsx)(L,{fill:!0,intent:H.DANGER,text:r(`account.deleteAccountBtn`),icon:`delete`,onClick:()=>{l(``),p(``),s(!0)}})]})]}),(0,$.jsx)(V,{intent:H.WARNING,icon:`info-sign`,title:r(`account.inactivityPolicy`),children:(0,$.jsx)(`p`,{className:`text-sm`,children:r(`account.inactivityDesc`)})}),(0,$.jsx)(R,{isOpen:o,onClose:()=>!u&&s(!1),title:r(`account.deleteAccount`),className:`max-w-md`,children:(0,$.jsxs)(`form`,{onSubmit:async e=>{if(e.preventDefault(),c){d(!0),p(``);try{let e=c;n?.password_version===2&&n.username&&(e=await Me(c,n.username)),await be({password:e}),window.location.href=`/`}catch(e){p(e.message||r(`common.errorNetwork`))}finally{d(!1)}}},children:[(0,$.jsxs)(`div`,{className:I,children:[(0,$.jsx)(`p`,{className:`text-sm opacity-80 mb-3 text-red-500 font-medium`,children:r(`account.confirmDeleteAccount`)}),(0,$.jsx)(q,{label:r(`account.totp.enterPassword`,`Enter your password to confirm:`),labelFor:`delete-account-password`,children:(0,$.jsx)(W,{id:`delete-account-password`,type:`password`,placeholder:r(`account.totp.passwordPlaceholder`,`Account password`),value:c,onChange:e=>l(e.target.value),autoFocus:!0})}),f&&(0,$.jsx)(V,{intent:H.DANGER,className:`mt-2 text-xs`,children:f})]}),(0,$.jsx)(`div`,{className:B,children:(0,$.jsxs)(`div`,{className:X,children:[(0,$.jsx)(L,{text:r(`common.cancel`,`Cancel`),onClick:()=>s(!1),disabled:u}),(0,$.jsx)(L,{intent:H.DANGER,text:r(`account.deleteAccountBtn`,`Delete Account`),type:`submit`,loading:u,disabled:u||!c.trim()})]})})]})})]})},kt=[{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`}],At=({me:e,isEditingUsername:t,setIsEditingUsername:n,editUsername:r,setEditUsername:i,usernameLoading:a,usernameFocused:o,setUsernameFocused:s,onUpdateUsername:c,onUpdateTimezone:l})=>{let{t:d}=y();return(0,$.jsxs)(Y,{elevation:F.ONE,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2 mb-4`,children:[(0,$.jsx)(p,{size:20,className:`text-blue-500`}),(0,$.jsx)(K,{style:{margin:0},children:d(`account.personalInfo`)})]}),(0,$.jsxs)(`div`,{className:`space-y-4`,children:[(0,$.jsx)(q,{label:d(`account.username`),children:(0,$.jsx)(`div`,{className:`flex gap-2`,children:t?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(se,{content:d(`account.formatTipUsername`),isOpen:o,position:M.TOP,intent:H.PRIMARY,className:`w-full`,children:(0,$.jsx)(`div`,{className:`w-full block`,children:(0,$.jsx)(W,{fill:!0,value:r,onChange:e=>i(e.target.value),onFocus:()=>s(!0),onBlur:()=>s(!1),autoFocus:!0})})}),(0,$.jsxs)(N,{children:[(0,$.jsx)(L,{icon:(0,$.jsx)(m,{size:16}),intent:H.SUCCESS,loading:a,onClick:c}),(0,$.jsx)(L,{icon:(0,$.jsx)(D,{size:16}),onClick:()=>{n(!1),i(e?.username||``)}})]})]}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(W,{fill:!0,value:e?.username,readOnly:!0}),(0,$.jsx)(L,{icon:(0,$.jsx)(u,{size:16}),onClick:()=>n(!0)})]})})}),(0,$.jsx)(q,{label:d(`account.userId`),children:(0,$.jsx)(W,{leftIcon:`id-number`,value:e?.id,disabled:!0})}),(0,$.jsx)(q,{label:d(`account.timezone`,`Timezone`),children:(0,$.jsx)(ie,{fill:!0,value:e?.timezone||``,onChange:e=>l?.(e.target.value||null),options:kt})})]})]})},jt=({me:e,onRefresh:n})=>{let{t:r}=y(),i=!!(e?.passkeys_count&&e.passkeys_count>0),a=!!e?.totp_enabled,[o,c]=(0,Q.useState)(`password`),[l,u]=(0,Q.useState)(``),[d,f]=(0,Q.useState)(!1),[p,m]=(0,Q.useState)(``),[h,g]=(0,Q.useState)(``),[_,v]=(0,Q.useState)(!1),[b,x]=(0,Q.useState)(!1),[S,C]=(0,Q.useState)(!1),[T,E]=(0,Q.useState)(null);return(0,Q.useEffect)(()=>{o===`passkey`&&!i?c(a?`totp`:`password`):o===`totp`&&!a&&c(i?`passkey`:`password`)},[i,a,o]),(0,$.jsxs)(Y,{elevation:F.ONE,className:`isolate`,style:{isolation:`isolate`},children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2 mb-4`,children:[(0,$.jsx)(w,{size:20,className:`text-orange-500`}),(0,$.jsx)(K,{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)(t,{size:14}),text:r(`account.mfa.password`,`Password`),onClick:()=>{c(`password`),E(null)}}),i&&(0,$.jsx)(L,{small:!0,active:o===`passkey`,intent:o===`passkey`?H.PRIMARY:H.NONE,icon:(0,$.jsx)(w,{size:14}),text:r(`account.mfa.passkey`,`Passkey`),onClick:()=>{c(`passkey`),E(null)}}),a&&(0,$.jsx)(L,{small:!0,active:o===`totp`,intent:o===`totp`?H.PRIMARY:H.NONE,icon:(0,$.jsx)(s,{size:14}),text:r(`account.mfa.totp`,`TOTP`),onClick:()=>{c(`totp`),E(null)}})]})})}),T&&(0,$.jsx)(V,{intent:T.intent,className:`mb-4`,children:T.text}),(0,$.jsxs)(`form`,{onSubmit:async t=>{if(t.preventDefault(),!Ue.test(h)){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}C(!0),E(null);try{let t=await Me(h,e.username);if(o===`passkey`)await Ce({passkeyAssertion:await He(await ye()),newPassword:t});else if(o===`totp`){if(p.length!==6){E({text:r(`account.totp.invalidCode`,`Please enter a 6-digit code`),intent:H.DANGER}),C(!1);return}let e=crypto.randomUUID(),n=new TextEncoder().encode(p+e),i=await crypto.subtle.digest(`SHA-256`,n);await Ce({totpTokenHash:Array.from(new Uint8Array(i)).map(e=>e.toString(16).padStart(2,`0`)).join(``),totpSalt:e,newPassword:t})}else{if(!l){E({text:r(`auth.passwordRequired`,`Current password is required`),intent:H.DANGER}),C(!1);return}let n=l;(e.password_version??1)===2&&(n=await Me(l,e.username)),await Ce({oldPassword:n,newPassword:t})}E({text:r(`account.passwordSuccess`,`Password updated successfully!`),intent:H.SUCCESS}),u(``),m(``),g(``),n&&n()}catch(e){E({text:Xe(e,r),intent:H.DANGER})}finally{C(!1)}},className:`space-y-4`,children:[o===`password`&&(0,$.jsx)(q,{label:r(`account.currentPassword`,`Current Password`),children:(0,$.jsx)(W,{leftIcon:`lock`,type:d?`text`:`password`,value:l,onChange:e=>u(e.target.value),rightElement:(0,$.jsx)(L,{minimal:!0,icon:d?`eye-open`:`eye-off`,onClick:()=>f(!d),title:r(d?`auth.hidePassword`:`auth.showPassword`)}),required:!0})}),o===`totp`&&(0,$.jsx)(q,{label:r(`account.totpCode`,`Authenticator Code`),children:(0,$.jsx)(Le,{length:6,value:p,onChange:m,disabled:S})}),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)(q,{label:r(`account.newPassword`,`New Password`),children:(0,$.jsx)(se,{content:r(`account.formatTipPassword`,`Password must be 12-100 characters and contain letters, numbers, and symbols.`),isOpen:b,position:M.TOP,intent:H.PRIMARY,className:`w-full`,children:(0,$.jsx)(`div`,{className:`w-full block`,children:(0,$.jsx)(W,{leftIcon:`lock`,type:_?`text`:`password`,value:h,onChange:e=>g(e.target.value),onFocus:()=>x(!0),onBlur:()=>x(!1),rightElement:(0,$.jsx)(L,{minimal:!0,icon:_?`eye-open`:`eye-off`,onClick:()=>v(!_),title:r(_?`auth.hidePassword`:`auth.showPassword`)}),required:!0})})})}),(0,$.jsx)(L,{fill:!0,intent:o===`passkey`?H.PRIMARY:H.WARNING,type:`submit`,loading:S,icon:o===`passkey`?(0,$.jsx)(w,{size:16}):void 0,text:o===`passkey`?r(`account.changePasswordWithPasskey`,`Verify with Passkey & Update`):r(`account.updatePassword`,`Update Password`)})]})]})},Mt=({isOpen:e,onClose:n,user:r,onSuccess:i})=>{let{t:a}=y(),o=!!(r?.passkeys_count&&r.passkeys_count>0),c=!!r?.totp_enabled,[l,u]=(0,Q.useState)(`password`),[d,f]=(0,Q.useState)(``),[p,m]=(0,Q.useState)(``),[h,g]=(0,Q.useState)(``),[_,v]=(0,Q.useState)(!1),[b,x]=(0,Q.useState)(``),[S,C]=(0,Q.useState)(!1),[T,E]=(0,Q.useState)(``),D=(0,Q.useRef)(null),O=(0,Q.useRef)(null);(0,Q.useEffect)(()=>{l===`passkey`&&!o?u(c?`totp`:`password`):l===`totp`&&!c&&u(o?`passkey`:`password`)},[o,c,l]);let k=async(e,t)=>{if(e&&e.preventDefault(),d.length!==4||!Je.test(d)){E(a(`auth.pinFormatTip`,`PIN must be exactly 4 digits`));return}if(d!==p){E(a(`auth.pinMatchTip`,`PINs do not match`));return}C(!0),E(``);try{let e=r?.id||sessionStorage.getItem(`obex_user_id`)||localStorage.getItem(`obex_user_id`);if(!e){E(a(`auth.sessionExpired`,`Session expired. Logging out...`)),setTimeout(()=>{A()},1500);return}let n=await Pe(d,e),o={};if(l===`passkey`)o.passkeyAssertion=await He(await ye());else if(l===`totp`){let e=(t||b).replace(/\s/g,``);if(e.length!==6){E(a(`account.totp.invalidCode`,`Please enter a 6-digit code`)),C(!1);return}let n=crypto.randomUUID();o.totpTokenHash=await We(e,n),o.totpSalt=n}else{if(!h){E(a(`auth.passwordRequired`,`Password is required for verification`)),C(!1);return}let e=h;r?.password_version===2&&r?.username&&(e=await Me(h,r.username)),o.password=e}await ve(n,o),f(``),m(``),g(``),x(``),i()}catch(e){E(Xe(e,a))}finally{C(!1)}},A=()=>{E(``),f(``),m(``),g(``),v(!1),x(``),u(`password`),n()};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)(q,{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:d,onChange:f,type:`password`,disabled:S,autoFocus:!0,onComplete:()=>D.current?.focus()})}),(0,$.jsx)(q,{label:a(`auth.confirmPin`,`Confirm New PIN`),labelFor:`confirm-pin-input`,children:(0,$.jsx)(Le,{ref:D,length:4,value:p,onChange:m,type:`password`,disabled:S,onComplete:()=>{l===`totp`?O.current?.focus():l===`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||c)&&(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:l===`password`,intent:l===`password`?H.PRIMARY:H.NONE,icon:(0,$.jsx)(t,{size:14}),text:a(`account.mfa.password`,`Password`),onClick:()=>{u(`password`),E(``)}}),o&&(0,$.jsx)(L,{small:!0,active:l===`passkey`,intent:l===`passkey`?H.PRIMARY:H.NONE,icon:(0,$.jsx)(w,{size:14}),text:a(`account.mfa.passkey`,`Passkey`),onClick:()=>{u(`passkey`),E(``)}}),c&&(0,$.jsx)(L,{small:!0,active:l===`totp`,intent:l===`totp`?H.PRIMARY:H.NONE,icon:(0,$.jsx)(s,{size:14}),text:a(`account.mfa.totp`,`TOTP`),onClick:()=>{u(`totp`),E(``)}})]})})]}),l===`password`&&(0,$.jsx)(q,{label:a(`auth.currentPassword`,`Current Password`),labelFor:`verify-pw-input`,children:(0,$.jsx)(W,{id:`verify-pw-input`,type:_?`text`:`password`,placeholder:a(`auth.passwordPlaceholder`,`Enter current password`),value:h,onChange:e=>g(e.target.value),leftIcon:`lock`,rightElement:(0,$.jsx)(L,{minimal:!0,icon:_?`eye-open`:`eye-off`,onClick:()=>v(!_),title:_?a(`auth.hidePassword`,`Hide password`):a(`auth.showPassword`,`Show password`)}),required:!0})}),l===`totp`&&(0,$.jsx)(q,{label:a(`auth.totpCode`,`TOTP Code`),labelFor:`verify-totp-input`,children:(0,$.jsx)(Le,{ref:O,length:6,value:b,onChange:x,disabled:S,onComplete:e=>k(void 0,e),autoFocus:!0})}),l===`passkey`&&(0,$.jsx)(V,{intent:H.PRIMARY,icon:null,children:(0,$.jsxs)(`div`,{className:`flex items-start gap-2 text-xs`,children:[(0,$.jsx)(w,{className:`w-4 h-4 shrink-0 mt-0.5`}),(0,$.jsx)(`span`,{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:X,children:[(0,$.jsx)(L,{onClick:A,children:a(`common.cancel`,`Cancel`)}),(0,$.jsx)(L,{type:`submit`,intent:H.PRIMARY,loading:S,children:a(`common.save`,`Save`)})]})})]})})},Nt=({isOpen:e,onClose:n,user:r,onSuccess:i})=>{let{t:a}=y(),o=!!(r?.passkeys_count&&r.passkeys_count>0),c=!!r?.totp_enabled,[l,u]=(0,Q.useState)(`password`),[d,f]=(0,Q.useState)(``),[p,m]=(0,Q.useState)(!1),[h,g]=(0,Q.useState)(``),[_,b]=(0,Q.useState)(!1),[x,S]=(0,Q.useState)(``);(0,Q.useEffect)(()=>{l===`passkey`&&!o?u(c?`totp`:`password`):l===`totp`&&!c&&u(o?`passkey`:`password`)},[o,c,l]);let C=async(e,t)=>{e&&e.preventDefault(),b(!0),S(``);try{let e={};if(l===`passkey`)e.passkeyAssertion=await He(await ye());else if(l===`totp`){let n=(t||h).replace(/\s/g,``);if(n.length!==6){S(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(!d){S(a(`auth.passwordRequired`,`Password is required for verification`)),b(!1);return}let t=d;r?.password_version===2&&r?.username&&(t=await Me(d,r.username)),e.password=t}await ue(e),f(``),g(``),i()}catch(e){S(Xe(e,a))}finally{b(!1)}},T=()=>{S(``),f(``),m(!1),g(``),u(`password`),n()};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:C,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:null,children:(0,$.jsxs)(`div`,{className:`flex items-start gap-2.5 text-sm`,children:[(0,$.jsx)(v,{className:`w-5 h-5 shrink-0 mt-0.5`}),(0,$.jsx)(`span`,{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||c)&&(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:l===`password`,intent:l===`password`?H.PRIMARY:H.NONE,icon:(0,$.jsx)(t,{size:14}),text:a(`account.mfa.password`,`Password`),onClick:()=>{u(`password`),S(``)}}),o&&(0,$.jsx)(L,{small:!0,active:l===`passkey`,intent:l===`passkey`?H.PRIMARY:H.NONE,icon:(0,$.jsx)(w,{size:14}),text:a(`account.mfa.passkey`,`Passkey`),onClick:()=>{u(`passkey`),S(``)}}),c&&(0,$.jsx)(L,{small:!0,active:l===`totp`,intent:l===`totp`?H.PRIMARY:H.NONE,icon:(0,$.jsx)(s,{size:14}),text:a(`account.mfa.totp`,`TOTP`),onClick:()=>{u(`totp`),S(``)}})]})})]}),l===`password`&&(0,$.jsx)(q,{label:a(`auth.currentPassword`,`Current Password`),labelFor:`disable-pw-input`,children:(0,$.jsx)(W,{id:`disable-pw-input`,type:p?`text`:`password`,placeholder:a(`auth.passwordPlaceholder`,`Enter current password`),value:d,onChange:e=>f(e.target.value),leftIcon:`lock`,rightElement:(0,$.jsx)(L,{minimal:!0,icon:p?`eye-open`:`eye-off`,onClick:()=>m(!p),title:p?a(`auth.hidePassword`,`Hide password`):a(`auth.showPassword`,`Show password`)}),required:!0})}),l===`totp`&&(0,$.jsx)(q,{label:a(`auth.totpCode`,`TOTP Code`),labelFor:`disable-totp-input`,children:(0,$.jsx)(Le,{length:6,value:h,onChange:g,disabled:_,onComplete:e=>C(void 0,e),autoFocus:!0})}),l===`passkey`&&(0,$.jsx)(V,{intent:H.PRIMARY,icon:null,children:(0,$.jsxs)(`div`,{className:`flex items-start gap-2 text-xs`,children:[(0,$.jsx)(w,{className:`w-4 h-4 shrink-0 mt-0.5`}),(0,$.jsx)(`span`,{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:X,children:[(0,$.jsx)(L,{onClick:T,children:a(`common.cancel`,`Cancel`)}),(0,$.jsx)(L,{type:`submit`,intent:H.DANGER,loading:_,children:a(`common.disable`,`Disable`)})]})})]})})},Pt=({user:e,onRefresh:t,onSavingChange:n,toasterRef:r})=>{let{t:i}=y(),[a,o]=(0,Q.useState)(!1),[c,l]=(0,Q.useState)(e?.session_lock_timeout||15);(0,Q.useEffect)(()=>{e?.session_lock_timeout!==void 0&&l(e.session_lock_timeout)},[e?.session_lock_timeout]);let[u,d]=(0,Q.useState)(!1),[f,p]=(0,Q.useState)(!1),m=!!e?.pin_enabled,h=async e=>{let a=Number(e.currentTarget.value),s=c;l(a),o(!0),n?.(!0);try{await tt(De({session_lock_timeout:a}),1e4),r?.current?.show({message:i(`common.saveSuccess`,`保存成功`),intent:H.SUCCESS,icon:`tick`}),t()}catch(e){console.error(`Failed to change session lock timeout`,e),l(s),r?.current?.show({message:e.message||i(`common.saveFailed`,`保存失败`),intent:H.DANGER,icon:`error`})}finally{o(!1),n?.(!1)}},g=()=>{d(!0)};return(0,$.jsxs)(Y,{elevation:F.ONE,children:[(0,$.jsxs)(`div`,{className:`flex flex-col sm:flex-row sm:items-center justify-between gap-3 mb-4`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[(0,$.jsx)(s,{size:20,className:`text-indigo-600`}),(0,$.jsx)(K,{className:`m-0!`,children:i(`auth.sessionLockTitle`,`Idle Session Lock`)})]}),!m&&(0,$.jsx)(L,{icon:`key`,intent:H.PRIMARY,onClick:g,disabled:a,className:`whitespace-nowrap self-start sm:self-auto`,children:i(`auth.configurePin`,`Configure 4-Digit PIN`)})]}),(0,$.jsx)(`p`,{className:`text-gray-500 text-sm mb-4`,children:i(`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:i(`auth.inactivityTimeout`,`Inactivity Timeout`)}),(0,$.jsx)(ie,{value:c,onChange:h,disabled:!m||a,options:[{label:i(`auth.timeout1m`,`1 Minute`),value:1},{label:i(`auth.timeout2m`,`2 Minutes`),value:2},{label:i(`auth.timeout5m`,`5 Minutes`),value:5},{label:i(`auth.timeout15m`,`15 Minutes`),value:15},{label:i(`auth.timeout30m`,`30 Minutes`),value:30},{label:i(`auth.timeout60m`,`60 Minutes`),value:60}]})]})}),m&&(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3`,children:[(0,$.jsx)(L,{icon:`edit`,onClick:g,disabled:a,children:i(`auth.changePin`,`Change PIN`)}),(0,$.jsx)(L,{icon:`trash`,intent:H.DANGER,onClick:()=>{p(!0)},disabled:a,children:i(`auth.disablePin`,`Disable PIN & Lock`)}),(0,$.jsx)(L,{icon:`lock`,intent:H.WARNING,onClick:async()=>{o(!0);try{await je(),window.dispatchEvent(new Event(`session_paused`))}catch(e){console.error(`Failed to lock session immediately`,e)}finally{o(!1)}},disabled:a,children:i(`auth.lockNow`,`Lock Now`)})]}),(0,$.jsx)(Mt,{isOpen:u,onClose:()=>d(!1),user:e,onSuccess:()=>{d(!1),t()}}),(0,$.jsx)(Nt,{isOpen:f,onClose:()=>p(!1),user:e,onSuccess:()=>{p(!1),t()}})]})},Ft=({toasterRef:e,onSavingChange:t})=>{let{t:n}=y(),[r,a]=(0,Q.useState)([]),[o,s]=(0,Q.useState)(!0),[l,u]=(0,Q.useState)(!1),[f,p]=(0,Q.useState)(``),[m,g]=(0,Q.useState)([]),[_,v]=(0,Q.useState)(null),[b,x]=(0,Q.useState)(null),S=(0,Q.useCallback)(async()=>{try{a(await Ae())}catch(e){console.warn(`Failed to fetch user lists`,e)}finally{s(!1)}},[]);(0,Q.useEffect)(()=>{S(),_e().then(e=>{e&&Array.isArray(e)&&g(e.map(e=>({label:String(n(e.label,{defaultValue:e.label})),url:String(e.url||``)})))}).catch(e=>console.warn(`Failed to fetch presets`,e))},[S,n]);let C=async()=>{let r=f.trim();if(r){u(!0),v(null),t?.(!0);try{await Ze(r),p(``),e?.current?.show({message:n(`account.userFilterLists.addSuccess`,`用户级过滤规则已成功添加并应用于所有配置`),intent:H.SUCCESS,icon:`tick`}),await S()}catch(t){let n=t instanceof Error?t.message:String(t);v(n),e?.current?.show({message:n,intent:H.DANGER,icon:`error`})}finally{u(!1),t?.(!1)}}},w=async(t,r)=>{try{await Qe(t,r),a(e=>e.map(e=>e.id===t?{...e,enabled:r}:e)),e?.current?.show({message:r?n(`account.userFilterLists.enabledToast`,`规则已在账号全局启用`):n(`account.userFilterLists.disabledToast`,`规则已在账号全局停用`),intent:H.PRIMARY,icon:r?`tick`:`disable`})}catch(t){console.error(t),e?.current?.show({message:t instanceof Error?t.message:String(t),intent:H.DANGER,icon:`error`}),await S()}},E=async t=>{try{await $e(t),x(null),a(e=>e.filter(e=>e.id!==t)),e?.current?.show({message:n(`account.userFilterLists.deleteSuccess`,`已删除用户级规则`),intent:H.PRIMARY,icon:`trash`})}catch(t){console.error(t),e?.current?.show({message:t instanceof Error?t.message:String(t),intent:H.DANGER,icon:`error`})}};return(0,$.jsxs)(Y,{elevation:F.ZERO,className:`p-6 border border-gray-100 dark:border-gray-800 rounded-xl space-y-6`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsxs)(K,{className:`flex items-center gap-2 mb-1 font-semibold text-gray-900 dark:text-gray-100`,children:[(0,$.jsx)(h,{className:`w-5 h-5 text-indigo-500 shrink-0`}),(0,$.jsx)(`span`,{children:n(`account.userFilterLists.title`,`用户级过滤列表`)})]}),(0,$.jsx)(`p`,{className:`text-sm text-gray-500 dark:text-gray-400`,children:n(`account.userFilterLists.description`,`在此配置的过滤规则列表将自动应用于您的所有配置 (Profiles)。系统级规则带有“系统”标签,自建规则带有“用户”标签。`)})]}),_&&(0,$.jsx)(V,{intent:H.DANGER,icon:`error`,className:`text-sm`,children:(0,$.jsxs)(`div`,{className:`flex justify-between items-center`,children:[(0,$.jsx)(`span`,{children:_}),(0,$.jsx)(L,{minimal:!0,small:!0,icon:`cross`,onClick:()=>v(null)})]})}),(0,$.jsxs)(`div`,{className:`space-y-4`,children:[m.length>0&&(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`span`,{className:`text-xs font-medium text-gray-500 mb-2 block`,children:n(`account.userFilterLists.quickPresets`,`快捷预设`)}),(0,$.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:m.map(e=>(0,$.jsx)(J,{interactive:!0,minimal:!0,round:!0,className:`cursor-pointer hover:opacity-80 transition-opacity`,onClick:()=>p(e.url),children:e.label},e.url))})]}),(0,$.jsxs)(`div`,{className:`flex flex-col sm:flex-row gap-2`,children:[(0,$.jsx)(q,{className:`mb-0 flex-1`,helperText:n(`account.userFilterLists.urlHelper`,`支持 AdGuard、Hosts、EasyList 等标准格式 URL`),children:(0,$.jsx)(W,{leftIcon:`globe`,placeholder:`https://example.com/filters.txt`,value:f,onChange:e=>p(e.target.value),disabled:l,onKeyDown:e=>{e.key===`Enter`&&C()}})}),(0,$.jsx)(L,{intent:H.PRIMARY,icon:(0,$.jsx)(d,{size:16}),text:n(`account.userFilterLists.addBtn`,`添加列表`),onClick:()=>void C(),loading:l,disabled:!f.trim()||l,className:`self-start sm:mt-0`})]})]}),(0,$.jsxs)(`div`,{className:`pt-2`,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between mb-3`,children:[(0,$.jsx)(`span`,{className:`text-sm font-semibold text-gray-800 dark:text-gray-200`,children:n(`account.userFilterLists.activeListsTitle`,`生效列表清单`)}),(0,$.jsx)(L,{icon:(0,$.jsx)(i,{size:14,className:o?`animate-spin`:``}),minimal:!0,small:!0,disabled:o,onClick:()=>{s(!0),S()}})]}),o?(0,$.jsxs)(`div`,{className:`flex items-center justify-center py-8 text-gray-400 gap-2`,children:[(0,$.jsx)(z,{size:16}),(0,$.jsx)(`span`,{className:`text-sm`,children:n(`common.loading`,`加载中...`)})]}):r.length===0?(0,$.jsx)(`div`,{className:`text-center py-8 text-gray-400 text-sm border border-dashed border-gray-200 dark:border-gray-800 rounded-lg`,children:n(`account.userFilterLists.empty`,`暂无用户级与系统级过滤列表。您可在上方添加自建列表。`)}):(0,$.jsx)(`div`,{className:`overflow-x-auto border border-gray-100 dark:border-gray-800 rounded-lg`,children:(0,$.jsxs)(oe,{interactive:!0,striped:!0,className:`w-full text-sm whitespace-nowrap`,children:[(0,$.jsx)(`thead`,{children:(0,$.jsxs)(`tr`,{children:[(0,$.jsx)(`th`,{className:`py-2.5 px-3 text-left font-semibold whitespace-nowrap`,children:n(`account.userFilterLists.colUrl`,`列表 URL`)}),(0,$.jsx)(`th`,{className:`py-2.5 px-3 text-left font-semibold w-24 whitespace-nowrap`,children:n(`account.userFilterLists.colType`,`类型`)}),(0,$.jsx)(`th`,{className:`py-2.5 px-3 text-left font-semibold w-36 whitespace-nowrap`,children:n(`account.userFilterLists.colLastSync`,`最近同步`)}),(0,$.jsx)(`th`,{className:`py-2.5 px-3 text-center font-semibold w-24 whitespace-nowrap`,children:n(`account.userFilterLists.colStatus`,`状态`)}),(0,$.jsx)(`th`,{className:`py-2.5 px-3 text-right font-semibold w-20 whitespace-nowrap`,children:n(`account.userFilterLists.colActions`,`操作`)})]})}),(0,$.jsx)(`tbody`,{children:r.map(e=>(0,$.jsxs)(`tr`,{children:[(0,$.jsx)(`td`,{className:`py-2 px-3 font-mono text-xs max-w-xs sm:max-w-md truncate`,title:e.url,children:e.url}),(0,$.jsx)(`td`,{className:`py-2 px-3 whitespace-nowrap`,children:e.is_system===1?(0,$.jsx)(J,{intent:H.PRIMARY,minimal:!0,round:!0,className:`text-xs font-sans whitespace-nowrap`,children:n(`filtering.tagSystem`,`系统`)}):(0,$.jsx)(J,{intent:H.SUCCESS,minimal:!0,round:!0,className:`text-xs font-sans whitespace-nowrap`,children:n(`filtering.tagUser`,`用户`)})}),(0,$.jsx)(`td`,{className:`py-2 px-3 text-xs opacity-70 whitespace-nowrap`,children:e.last_synced_at?Fe(new Date(e.last_synced_at*1e3)):n(`filtering.neverSynced`,`未同步`)}),(0,$.jsx)(`td`,{className:`py-2 px-3 text-center whitespace-nowrap`,children:(0,$.jsx)(G,{checked:e.enabled,onChange:t=>void w(e.id,t.target.checked),className:`mb-0 inline-block`,innerLabelChecked:n(`common.yes`,`开`),innerLabel:n(`common.no`,`关`)})}),(0,$.jsx)(`td`,{className:`py-2 px-3 text-right whitespace-nowrap`,children:e.is_system===0?(0,$.jsx)(re,{isOpen:b===e.id,onInteraction:t=>x(t?e.id:null),placement:`top-end`,content:(0,$.jsxs)(`div`,{className:`p-3 space-y-3 max-w-xs`,children:[(0,$.jsx)(`p`,{className:`text-xs font-semibold leading-relaxed m-0 text-gray-800 dark:text-gray-200`,children:n(`account.userFilterLists.deleteConfirm`,`确定从账号中删除此过滤列表吗?该规则将从您的所有配置中移除。`)}),(0,$.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,$.jsx)(L,{small:!0,variant:`minimal`,text:n(`common.cancel`,`取消`),onClick:()=>x(null)}),(0,$.jsx)(L,{small:!0,intent:H.DANGER,text:n(`common.confirm`,`确认删除`),onClick:()=>void E(e.id)})]})]}),children:(0,$.jsx)(L,{icon:(0,$.jsx)(T,{size:14}),minimal:!0,intent:H.DANGER,small:!0})}):(0,$.jsxs)(J,{intent:H.NONE,minimal:!0,round:!0,className:`text-xs text-gray-400`,children:[(0,$.jsx)(c,{size:10,className:`inline mr-1`}),n(`account.userFilterLists.systemManaged`,`统一维护`)]})})]},e.id))})]})})]})]})};function It({user:e,onRefresh:t,toasterRef:n,setProcessing:r}){let{t:i}=y(),[a,o]=(0,Q.useState)(null),[s,c]=(0,Q.useState)(!0),[l,u]=(0,Q.useState)(!1),[d,f]=(0,Q.useState)(!1),p=(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)(()=>{p()},[p]);let m=e.passkeys_count&&e.passkeys_count>0||(a?.userPasskeyCount||0)>0,h=!!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:h,hasPasskey:m,loadStatus:p,isDisableAlertOpen:d,setIsDisableAlertOpen:f,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 p(),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 f(!0)},handleConfirmDisable:async()=>{r(!0);try{await Z.disableUserE2ee(),n.current?.show({message:i(`account.e2ee.disableSuccess`),intent:H.WARNING,icon:`unlock`}),await p(),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),f(!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}=y(),[o,s]=(0,Q.useState)(!1),[c,l]=(0,Q.useState)(``),[u,d]=(0,Q.useState)(``),[f,p]=(0,Q.useState)(!1),[m,h]=(0,Q.useState)(``),[g,_]=(0,Q.useState)(``),[v,b]=(0,Q.useState)(null),[x,S]=(0,Q.useState)(!1);return{isRecoveryDialogOpen:o,setIsRecoveryDialogOpen:s,recoveryKeyInput:c,setRecoveryKeyInput:l,recoveryUnlockError:u,setRecoveryUnlockError:d,initRecoveryDialogOpen:f,setInitRecoveryDialogOpen:p,initRecoveryKeyInput:m,setInitRecoveryKeyInput:h,initRecoveryError:g,setInitRecoveryError:_,rotatedKey:v,setRotatedKey:b,copiedKey:x,handleUnlockWithRecoveryKey:async o=>{o.preventDefault();let u=c.trim();if(u){i(!0),d(``);try{await Z.unlockWithRecoveryKey(u);try{let e=await pe({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),d(e.message||a(`account.e2ee.recoveryUnlockFailed`))}finally{i(!1)}}},handleInitWithRecoveryKey:async o=>{o.preventDefault();let s=m.trim();if(s){i(!0),_(``);try{await Z.initUserE2eeWithRecoveryKey(s);try{let e=await pe({recoveryKey:s});await Z.wrapCurrentKeyForRecovery(e.recovery_key),b(e.recovery_key)}catch(e){console.warn(`[useE2eeRecoveryDialogs] Recovery key auto-rotation failed:`,e)}p(!1),h(``),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),_(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}=y(),[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 et(),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:n}=y();return(0,$.jsxs)(`div`,{className:`flex flex-col sm:flex-row sm:items-center justify-between gap-2 mb-3`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[(0,$.jsx)(t,{size:20,className:e?`text-emerald-500`:`text-gray-400`}),(0,$.jsx)(K,{style:{margin:0},children:n(`account.e2ee.title`,`E2EE`)}),(0,$.jsx)(J,{intent:e?H.SUCCESS:H.NONE,minimal:!0,round:!0,className:`whitespace-nowrap`,children:n(e?`account.e2ee.enabled`:`account.e2ee.disabled`)})]}),(0,$.jsx)(`div`,{className:`shrink-0 self-end sm:self-auto`,children:(0,$.jsx)(re,{placement:`bottom-end`,usePortal:!0,content:(0,$.jsxs)(`div`,{className:`p-4 max-w-sm`,children:[(0,$.jsx)(ne,{children:n(`account.e2ee.trustBoundaryTitle`)}),(0,$.jsx)(`p`,{className:`text-sm text-gray-700 dark:text-gray-300 m-0`,children:n(`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:t,onGenerateKeyWithPasskey:n,onOpenInitRecoveryDialog:r})=>{let{t:i}=y();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:i(`account.e2ee.noKeypairTitle`)}),(0,$.jsx)(`p`,{className:`text-xs text-blue-800 dark:text-blue-200 m-0`,children:i(`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)(b,{size:14}),text:i(`account.e2ee.initPasskeyBtn`),loading:t,onClick:n}):(0,$.jsx)(L,{intent:H.PRIMARY,small:!0,icon:(0,$.jsx)(w,{size:14}),text:i(`account.e2ee.addPasskeyBtn`),onClick:()=>{document.getElementById(`passkeys-section`)?.scrollIntoView({behavior:`smooth`})}}),(0,$.jsx)(L,{intent:H.NONE,small:!0,icon:(0,$.jsx)(w,{size:14}),text:i(`account.e2ee.initRecoveryBtn`),onClick:r})]})]})})},Ht=({status:e,isLogsE2eeEnabled:t,isUnlocked:n,isPqc:r,hasPasskey:a,processing:o,loading:c,onToggleLogs:l,onUpgradeToPqc:u,onLockDevice:d,onUnlockPasskey:f,onOpenRecoveryUnlockDialog:p,onEnrollPasskey:m,onOpenResetAlert:h})=>{let{t:g}=y();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:g(`account.e2ee.enableSwitch`)}),(0,$.jsx)(J,{intent:t?H.SUCCESS:H.NONE,minimal:!0,round:!0,children:g(t?`account.e2ee.enabled`:`account.e2ee.disabled`)})]}),(0,$.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-gray-400 m-0`,children:g(`account.e2ee.enableSwitchDesc`)})]}),(0,$.jsx)(`div`,{className:`shrink-0 flex items-center`,children:(0,$.jsx)(G,{checked:t,disabled:o||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-3 text-xs`,children:[(0,$.jsxs)(`div`,{className:`flex flex-col sm:flex-row sm:items-center justify-between gap-1.5`,children:[(0,$.jsxs)(`span`,{className:`opacity-70 flex items-center gap-1.5 shrink-0`,children:[(0,$.jsx)(b,{size:13}),g(`account.e2ee.keyType`),`:`]}),(0,$.jsxs)(`div`,{className:`flex items-center gap-1.5 flex-wrap`,children:[(0,$.jsx)(`span`,{className:`font-mono break-all sm:break-normal`,children:r?`P256-MLKEM768 + AES-256-GCM`:`ECDH P-256 + AES-256-GCM`}),r?(0,$.jsx)(J,{minimal:!0,intent:H.PRIMARY,className:`text-[10px] whitespace-nowrap`,children:g(`account.e2ee.pqcTag`,`PQC / NIST FIPS 203`)}):(0,$.jsx)(L,{small:!0,intent:H.PRIMARY,minimal:!0,icon:(0,$.jsx)(i,{size:12}),text:g(`account.e2ee.upgradePqcBtn`,`升级到后量子 (PQC)`),loading:o,onClick:u,className:`whitespace-nowrap`})]})]}),(0,$.jsxs)(`div`,{className:`flex flex-col sm:flex-row sm:items-center justify-between gap-1.5`,children:[(0,$.jsxs)(`span`,{className:`opacity-70 flex items-center gap-1.5 shrink-0`,children:[(0,$.jsx)(s,{size:13}),g(`account.e2ee.deviceState`),`:`]}),n?(0,$.jsxs)(`div`,{className:`flex items-center gap-2 flex-wrap sm:justify-end`,children:[(0,$.jsx)(J,{minimal:!0,intent:H.SUCCESS,className:`text-[10px] whitespace-nowrap`,children:g(`account.e2ee.unlocked`)}),a&&(e?.wrappedPasskeys?.length||0)===0&&m&&(0,$.jsx)(L,{small:!0,intent:H.PRIMARY,icon:(0,$.jsx)(b,{size:12}),text:g(`account.e2ee.enrollPasskeyBtn`,`关联当前通行密钥`),loading:o,onClick:m,className:`whitespace-nowrap`}),(0,$.jsx)(L,{small:!0,minimal:!0,intent:H.NONE,icon:`lock`,text:g(`account.e2ee.lockDevice`,`锁定此设备`),onClick:d,className:`whitespace-nowrap`})]}):(0,$.jsxs)(`div`,{className:`flex items-center gap-2 flex-wrap sm:justify-end`,children:[a&&(e?.wrappedPasskeys?.length||0)>0&&(0,$.jsx)(L,{small:!0,minimal:!0,intent:H.PRIMARY,icon:(0,$.jsx)(i,{size:12}),text:g(`account.e2ee.unlockButton`),loading:o,onClick:f,className:`whitespace-nowrap`}),(0,$.jsx)(L,{small:!0,minimal:!0,intent:H.NONE,icon:(0,$.jsx)(b,{size:12}),text:g(`account.e2ee.unlockRecoveryButton`),onClick:p,className:`whitespace-nowrap`}),h&&(0,$.jsx)(L,{small:!0,minimal:!0,intent:H.DANGER,icon:`reset`,text:g(`account.e2ee.resetKeypairBtn`,`重置密钥对`),onClick:h,className:`whitespace-nowrap`})]})]}),(0,$.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,$.jsxs)(`span`,{className:`opacity-70`,children:[g(`account.e2ee.protectedPasskeys`),`:`]}),(0,$.jsxs)(`span`,{className:`font-mono`,children:[e?.wrappedPasskeys?.length||0,` `,g(`account.e2ee.devicesUnit`)]})]})]})]})},Ut=({isOpen:e,processing:t,onConfirm:n,onCancel:r})=>{let{t:i}=y();return(0,$.jsx)(te,{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}=y();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)(q,{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:X,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}=y();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)(q,{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:X,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}=y();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:null,className:`mb-4 text-xs`,children:(0,$.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,$.jsx)(v,{className:`w-4 h-4 shrink-0 mt-0.5`}),(0,$.jsx)(`span`,{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)(m,{size:14,className:`text-green-400`}):(0,$.jsx)(g,{size:14}),text:i(n?`common.copied`:`common.copyKey`),onClick:()=>r(e)})})]})]}),(0,$.jsx)(`div`,{className:B,children:(0,$.jsx)(`div`,{className:X,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}=y();return(0,$.jsx)(te,{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}=y(),r=(0,Q.useRef)(null),{status:i,loading:a,processing:o,isUnlocked:s,isPqc:c,isLogsE2eeEnabled:l,hasPasskey:u,isDisableAlertOpen:d,setIsDisableAlertOpen:f,isRecoveryDialogOpen:p,setIsRecoveryDialogOpen:m,recoveryKeyInput:h,setRecoveryKeyInput:g,recoveryUnlockError:_,initRecoveryDialogOpen:v,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:te,handleCopyRotatedKey:P,isResetAlertOpen:I,setIsResetAlertOpen:ne,handleResetAndReinit:L,handleEnrollPasskey:R}=zt({user:e,onRefresh:t,toasterRef:r});return(0,$.jsxs)(Y,{elevation:F.ONE,className:`space-y-6`,children:[(0,$.jsx)(ae,{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:te,onUnlockPasskey:A,onOpenRecoveryUnlockDialog:()=>{g(``),m(!0)},onEnrollPasskey:R,onOpenResetAlert:()=>ne(!0)}):(0,$.jsx)(Vt,{hasPasskey:u,processing:o,onGenerateKeyWithPasskey:ee,onOpenInitRecoveryDialog:()=>{w(``),S(``),b(!0)}})]}),(0,$.jsx)(Ut,{isOpen:d,processing:o,onConfirm:k,onCancel:()=>f(!1)}),(0,$.jsx)(qt,{isOpen:I,processing:o,hasPasskey:u,onConfirm:L,onCancel:()=>ne(!1)}),(0,$.jsx)(Wt,{isOpen:p,onClose:()=>m(!1),recoveryKeyInput:h,setRecoveryKeyInput:g,recoveryUnlockError:_,processing:o,onSubmit:j}),(0,$.jsx)(Gt,{isOpen:v,onClose:()=>b(!1),initRecoveryKeyInput:x,setInitRecoveryKeyInput:S,initRecoveryError:C,processing:o,onSubmit:N}),(0,$.jsx)(Kt,{rotatedKey:T,onClose:()=>E(null),copiedKey:D,onCopyKey:P})]})},Yt=({onSavingChange:e,toasterRef:t})=>{let[n,r]=(0,Q.useState)(null),[i,a]=(0,Q.useState)(!0),[o,c]=(0,Q.useState)(null),{t:l,i18n:u}=y(),d=Ie(),[f,p]=(0,Q.useState)(!1),[m,h]=(0,Q.useState)(``),[g,_]=(0,Q.useState)(!1),[v,b]=(0,Q.useState)(!1),x=(0,Q.useCallback)(async()=>{try{let e=await he();if(r(e),h(e.username),window.dispatchEvent(new Event(`user_updated`)),e.timezone){let{setSystemTimeZone:t}=await j(async()=>{let{setSystemTimeZone:e}=await import(`./date-BFCCct66.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-BFCCct66.js`);return{setSystemLocale:e}},__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10]));t(e.locale),u.changeLanguage(e.locale)}}catch(e){console.error(e)}finally{a(!1)}},[u]);return(0,Q.useEffect)(()=>{x()},[x]),i?(0,$.jsx)(`div`,{className:`p-8 text-center`,children:l(`common.loading`)}):(0,$.jsxs)(`div`,{className:ce(`max-w-5xl mx-auto space-y-8`,d?`p-0`:`px-8`),children:[(0,$.jsxs)(`div`,{className:`flex justify-between items-start sm:items-end gap-3 flex-wrap sm:flex-nowrap`,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`)})]}),n&&(0,$.jsx)(J,{large:!0,round:!0,intent:n.role===`admin`?H.DANGER:H.PRIMARY,icon:(0,$.jsx)(s,{size:16}),className:`shrink-0 whitespace-nowrap`,children:n.role===`admin`?l(`account.roleAdmin`):l(`account.roleUser`)})]}),(0,$.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-6`,children:[(0,$.jsx)(At,{me:n,isEditingUsername:f,setIsEditingUsername:p,editUsername:m,setEditUsername:h,usernameLoading:g,usernameFocused:v,setUsernameFocused:b,onUpdateUsername:async()=>{if(m===n?.username){p(!1);return}if(!Be.test(m)){t?.current?.show({message:l(`account.formatTipUsername`),intent:H.WARNING,icon:`warning-sign`});return}let i=n?.username||``,a=m;_(!0),e?.(!0);try{await tt(De({username:a}),1e4),r(e=>e?{...e,username:a}:null),p(!1),t?.current?.show({message:l(`common.saveSuccess`,`保存成功`),intent:H.SUCCESS,icon:`tick`})}catch(e){console.error(e),h(i),r(e=>e?{...e,username:i}:null),p(!1),t?.current?.show({message:e.message||l(`common.saveFailed`,`保存失败`),intent:H.DANGER,icon:`error`})}finally{_(!1),e?.(!1)}},onUpdateTimezone:async i=>{let a=n?.timezone??null;r(e=>e?{...e,timezone:i}:null),e?.(!0);try{await tt(De({timezone:i||``}),1e4);let{setSystemTimeZone:e}=await j(async()=>{let{setSystemTimeZone:e}=await import(`./date-BFCCct66.js`);return{setSystemTimeZone:e}},__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10]));e(i||``),t?.current?.show({message:l(`common.saveSuccess`,`保存成功`),intent:H.SUCCESS,icon:`tick`})}catch(e){console.error(e),r(e=>e?{...e,timezone:a}:null);let{setSystemTimeZone:n}=await j(async()=>{let{setSystemTimeZone:e}=await import(`./date-BFCCct66.js`);return{setSystemTimeZone:e}},__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10]));n(a||``),t?.current?.show({message:e.message||l(`common.saveFailed`,`保存失败`),intent:H.DANGER,icon:`error`})}finally{e?.(!1)}}}),(0,$.jsx)(jt,{me:n,onRefresh:x})]}),n&&(0,$.jsx)(xt,{user:n,onRefresh:x}),n&&(0,$.jsx)(Jt,{user:n,onRefresh:x}),n&&(0,$.jsx)(Pt,{user:n,onRefresh:x,onSavingChange:e,toasterRef:t}),n&&(0,$.jsx)(Ft,{onSavingChange:e,toasterRef:t}),n&&(0,$.jsx)(Dt,{hoveredSessionId:o,setHoveredSessionId:c}),n&&(0,$.jsx)(Et,{hoveredSessionId:o,setHoveredSessionId:c}),(0,$.jsx)(U,{}),(0,$.jsx)(`div`,{className:`space-y-4`,children:(0,$.jsx)(Ot,{isAdmin:n?.role===`admin`,user:n})})]})};export{Yt as AccountView};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{i as e}from"./rolldown-runtime-C4Xdq4VV.js";import{_ as t,d as n,f as r,g as i,i as a,m as o,nn as s,p as c,r as l,u,y as d,z as f}from"./vendor-react-DYK5a2J9.js";import{S as p,b as m}from"./vendor-icons-other-BTYC6Wvz.js";import"./vendor-i18next-DlmslyBB.js";import"./vendor-utils-Bab4qB3W.js";import{W as h,ft as g,w as _}from"./index-DEIEgGUw.js";import{n as v,t as y}from"./formatCountryName-C6cFVUu2.js";import{t as b}from"./getFlagEmoji-Cd2A891A.js";var x=e(p(),1);function S(e){let[t,n]=(0,x.useState)(null);(0,x.useEffect)(()=>{h().then(e=>{if(e&&e.objects){let t={};e.objects.countries&&(t.countries=e.objects.countries),e.objects.land&&(t.land=e.objects.land),e.objects=t}e&&e.objects&&e.objects.countries&&Array.isArray(e.objects.countries.geometries)&&e.objects.countries.geometries.forEach(e=>{e.id!==void 0&&e.id!==null&&(e.id=String(e.id).padStart(3,`0`))}),n(e)}).catch(e=>console.error(`Failed to load map topology`,e))},[]);let r=(0,x.useMemo)(()=>e.reduce((e,t)=>e+(Number(t.count)||0),0),[e]),i=(0,x.useMemo)(()=>{if(r<=0)return{maxThreshold:10,step:1};if(r<=1e3)return{maxThreshold:100,step:10};let e=10**Math.floor(Math.log10(r));return{maxThreshold:e,step:e/10}},[r]);return{geographyData:t,destinationMap:(0,x.useMemo)(()=>{let t={};return e.forEach(e=>{if(e.country_code){let n=e.country_code.toUpperCase(),r=Number(e.count)||0;t[n]?(t[n].count+=r,(!t[n].name||t[n].name===`Unknown`)&&e.country&&e.country!==`Unknown`&&(t[n].name=e.country)):t[n]={count:r,name:e.country,countryCode:n}}}),t},[e]),scaleConfig:i,getLevel:e=>!e||e<=0?0:Math.min(10,Math.floor(e/i.step)+1),formatNumber:e=>{if(e>=1e6){let t=e/1e6;return Number.isInteger(t)?`${t}M`:`${t.toFixed(1)}M`}if(e>=1e3){let t=e/1e3;return Number.isInteger(t)?`${t}K`:`${t.toFixed(1)}K`}return e.toString()}}}var C=e(m(),1);const w=({onZoomIn:e,onZoomOut:n,onReset:r})=>(0,C.jsxs)(`div`,{className:`absolute top-3 right-3 flex flex-col gap-1.5 bg-white/80 dark:bg-slate-950/80 backdrop-blur-md p-1.5 rounded-lg border border-gray-200/50 dark:border-slate-800/50 shadow-sm z-10`,children:[(0,C.jsx)(`button`,{type:`button`,onClick:e,className:`p-1.5 hover:bg-gray-100 dark:hover:bg-slate-800 rounded text-gray-600 dark:text-gray-300 transition-colors cursor-pointer`,title:`Zoom In`,children:(0,C.jsx)(t,{size:16})}),(0,C.jsx)(`button`,{type:`button`,onClick:n,className:`p-1.5 hover:bg-gray-100 dark:hover:bg-slate-800 rounded text-gray-600 dark:text-gray-300 transition-colors cursor-pointer`,title:`Zoom Out`,children:(0,C.jsx)(i,{size:16})}),(0,C.jsx)(`button`,{type:`button`,onClick:r,className:`p-1.5 hover:bg-gray-100 dark:hover:bg-slate-800 rounded text-gray-600 dark:text-gray-300 transition-colors cursor-pointer`,title:`Reset Zoom`,children:(0,C.jsx)(f,{size:16})})]}),T=({maxThreshold:e,formatNumber:t})=>{let{t:n}=s();return(0,C.jsxs)(`div`,{className:`sm:absolute sm:bottom-3 sm:left-3 relative m-3 sm:m-0 flex flex-col shrink-0 gap-1.5 bg-white/80 dark:bg-slate-950/80 backdrop-blur-md p-2 rounded-lg border border-gray-200/50 dark:border-slate-800/50 shadow-sm z-10 max-w-70`,children:[(0,C.jsx)(`span`,{className:`text-[9px] font-bold text-gray-500 dark:text-gray-400 uppercase tracking-wider`,children:n(`analytics.queries`)}),(0,C.jsx)(`div`,{className:`flex items-center gap-0.5`,children:Array.from({length:11}).map((e,t)=>(0,C.jsx)(`div`,{className:`w-4 h-2.5 rounded-sm border border-black/5 dark:border-white/5`,style:{backgroundColor:`var(--map-color-${t})`}},t))}),(0,C.jsxs)(`div`,{className:`flex justify-between text-[9px] text-gray-500 dark:text-gray-400 font-semibold px-0.5`,children:[(0,C.jsx)(`span`,{children:`0`}),(0,C.jsx)(`span`,{children:t(e/2)}),(0,C.jsxs)(`span`,{children:[t(e),`+`]})]})]})},E=({name:e,count:t,flag:n,x:r,y:i,countryCode:a,profileId:o,range:c,customRange:l,accessPointId:u,ispCache:f,onCacheIsp:p,isPinned:m,onClose:h})=>{let{t:v}=s(),y=(0,x.useRef)(null),[b,S]=(0,x.useState)({left:r,top:i-10,alignBottom:!1}),[w,T]=(0,x.useState)([]),[E,D]=(0,x.useState)(!1),O=(0,x.useRef)(f);O.current=f;let k=(0,x.useRef)(p);return k.current=p,(0,x.useEffect)(()=>{if(!a||!o)return;if(t<=0){T([]),D(!1);return}let e=O.current[a];if(e){T(e),D(!1);return}D(!0);let n=Math.floor(Date.now()/1e3),r,i=n,s=`?country_code=${a}&range=${c}`;if(c===`custom`&&l.start&&l.end)r=Math.floor(new Date(l.start).getTime()/1e3),i=Math.floor(new Date(l.end).getTime()/1e3),s+=`&start=${r}&end=${i}`;else switch(c){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-3600;break}u&&(s+=`&access_point_id=${u}`);let d=!0,f=setTimeout(async()=>{try{let e=await g(o,`isps`,s),t=Array.isArray(e)?e:[];if(t.length>0){k.current(a,t),d&&(T(t),D(!1));return}}catch(e){console.debug(`[MapTooltip] Server ISP fetch failed, trying local DB fallback:`,e)}try{let e=await _.queryISPs({profileId:o,countryCode:a,since:r,until:i,accessPointId:u||void 0});e&&e.length>0&&(k.current(a,e),d&&T(e))}catch(e){console.warn(`[MapTooltip] Local SQLite ISP query failed:`,e)}finally{d&&D(!1)}},150);return()=>{d=!1,clearTimeout(f)}},[a,o,c,l,u,t]),(0,x.useEffect)(()=>{if(!m)return;let e=e=>{if(y.current&&!y.current.contains(e.target)){let t=e.target,n=t.classList.contains(`rsm-geography`)||t.closest(`.rsm-geography`),r=t.classList.contains(`map-marker-circle`)||t.closest(`.map-marker-circle`);!n&&!r&&h()}},t=setTimeout(()=>{document.addEventListener(`click`,e,!0)},0);return()=>{clearTimeout(t),document.removeEventListener(`click`,e,!0)}},[m,h]),(0,x.useLayoutEffect)(()=>{if(!y.current)return;let e=y.current.getBoundingClientRect(),t=y.current.parentElement;if(!t)return;let n=t.getBoundingClientRect(),a=r,o=e.width/2;r-o<4?a=o+4:r+o>n.width-4&&(a=n.width-o-4);let s=i-10,c=!1;i-e.height-15<4&&(s=i+15,c=!0),S({left:a,top:s,alignBottom:c})},[r,i,w]),(0,C.jsxs)(`div`,{ref:y,onMouseLeave:m?h:void 0,className:`absolute bg-white/95 dark:bg-slate-900/95 backdrop-blur-sm px-3 py-2 rounded-lg shadow-xl border border-gray-200/50 dark:border-slate-800/50 text-xs z-50 flex flex-col gap-1 transition-all duration-75 text-gray-900 dark:text-gray-100 ${m?`pointer-events-auto cursor-default`:`pointer-events-none`}`,style:{left:`${b.left}px`,top:`${b.top}px`,transform:b.alignBottom?`translate(-50%, 0)`:`translate(-50%, -100%)`},children:[(0,C.jsxs)(`div`,{className:`flex items-center justify-between gap-4`,children:[(0,C.jsxs)(`div`,{className:`flex flex-col gap-0.5`,children:[(0,C.jsxs)(`div`,{className:`flex items-center gap-1.5 font-semibold whitespace-nowrap`,children:[(0,C.jsx)(`span`,{className:`text-sm`,children:n}),(0,C.jsx)(`span`,{children:e})]}),(0,C.jsxs)(`div`,{className:`text-gray-500 dark:text-gray-400 whitespace-nowrap`,children:[t.toLocaleString(),` `,v(`analytics.queries`)]})]}),m&&(0,C.jsx)(`button`,{onClick:e=>{e.stopPropagation(),h()},className:`flex items-center justify-center p-2 rounded-lg border border-gray-200 dark:border-slate-800 text-gray-500 hover:text-red-500 hover:bg-red-50 dark:hover:bg-red-950/20 hover:border-red-200 dark:hover:border-red-900/50 transition-colors cursor-pointer self-stretch aspect-square`,title:v(`common.close`,`Close`),children:(0,C.jsx)(d,{size:18})})]}),E?(0,C.jsxs)(`div`,{className:`mt-1.5 pt-1.5 border-t border-gray-150 dark:border-slate-850 flex flex-col gap-1 min-w-36`,children:[(0,C.jsx)(`div`,{className:`text-[10px] uppercase font-bold text-gray-400 dark:text-gray-500 tracking-wider`,children:v(`analytics.topIsps`,`Top ISPs`)}),(0,C.jsx)(`div`,{className:`text-[11px] text-gray-400 dark:text-gray-500 italic`,children:v(`analytics.loading`,`Loading...`)})]}):w.length>0&&(0,C.jsxs)(`div`,{className:`mt-1.5 pt-1.5 border-t border-gray-150 dark:border-slate-800 flex flex-col gap-1`,children:[(0,C.jsx)(`div`,{className:`text-[10px] uppercase font-bold text-gray-400 dark:text-gray-500 tracking-wider`,children:v(`analytics.topIsps`,`Top ISPs`)}),(0,C.jsxs)(`div`,{className:`flex flex-col gap-0.5 min-w-36 max-w-48 ${m?`max-h-36 overflow-y-auto pr-1`:``}`,children:[(m?w:w.slice(0,5)).map(e=>(0,C.jsxs)(`div`,{className:`flex justify-between gap-3 text-[11px] text-gray-600 dark:text-gray-300`,children:[(0,C.jsx)(`span`,{className:`truncate`,title:e.name,children:e.name}),(0,C.jsx)(`span`,{className:`font-mono text-gray-400 dark:text-gray-500`,children:e.count.toLocaleString()})]},e.name)),!m&&w.length>5&&(0,C.jsxs)(C.Fragment,{children:[(0,C.jsx)(`div`,{className:`text-center text-gray-400 dark:text-gray-500 leading-none py-0.5 font-bold`,children:`...`}),(0,C.jsx)(`div`,{className:`text-[10px] text-center text-blue-500 dark:text-blue-400 font-medium whitespace-nowrap mt-0.5`,children:v(`analytics.pressToShowMore`,`Click to show more`)})]})]})]})]})},D=({geographyData:e,destinationMap:t,getLevel:r,containerRef:i,hoveredCountry:a,setHoveredCountry:o})=>{let{i18n:c}=s();return e?(0,C.jsx)(n,{geography:e,children:({geographies:e})=>e.map(e=>{let n=e.id==null?void 0:v[String(e.id)],s=n?t[n]:null,l=s?.count||0,d=r(l);return(0,C.jsx)(u,{geography:e,onMouseEnter:e=>{if(!n||a?.isPinned)return;let t=y(n,c.language)||s?.name||n,r=b(n),u=i.current?.getBoundingClientRect();o({name:t,code:n,count:l,flag:r,x:e.clientX-(u?.left||0),y:e.clientY-(u?.top||0)-15})},onMouseMove:e=>{o(t=>{if(t?.isPinned)return t;let n=i.current?.getBoundingClientRect(),r=e.clientX-(n?.left||0),a=e.clientY-(n?.top||0)-15;return t?{...t,x:r,y:a}:null})},onMouseLeave:()=>{o(e=>e?.isPinned?e:null)},onClick:e=>{if(e.stopPropagation(),!n)return;let t=y(n,c.language)||s?.name||n,r=b(n),a=i.current?.getBoundingClientRect(),u=e.clientX-(a?.left||0),d=e.clientY-(a?.top||0)-15;o(e=>e?.code===n&&e?.isPinned?null:{name:t,code:n,count:l,flag:r,x:u,y:d,isPinned:!0})},style:{default:{fill:`var(--map-color-${d})`,stroke:`var(--map-stroke)`,strokeWidth:.5,outline:`none`,transition:`fill 250ms, stroke 250ms`},hover:{fill:`var(--map-hover)`,stroke:`var(--map-stroke)`,strokeWidth:.5,outline:`none`,cursor:`pointer`},pressed:{fill:`var(--map-hover)`,stroke:`var(--map-stroke)`,strokeWidth:.5,outline:`none`}}},e.rsmKey)})}):null},O={SG:{name:`Singapore`,coordinates:[103.8198,1.3521]},HK:{name:`Hong Kong`,coordinates:[114.1694,22.3193]},MO:{name:`Macau`,coordinates:[113.5439,22.1987]},VA:{name:`Vatican City`,coordinates:[12.4534,41.9029]},MC:{name:`Monaco`,coordinates:[7.4246,43.7384]},SM:{name:`San Marino`,coordinates:[12.4578,43.9424]},LI:{name:`Liechtenstein`,coordinates:[9.5209,47.141]},AD:{name:`Andorra`,coordinates:[1.5218,42.5063]},MT:{name:`Malta`,coordinates:[14.3754,35.9375]},GI:{name:`Gibraltar`,coordinates:[-5.3536,36.1408]},BM:{name:`Bermuda`,coordinates:[-64.7505,32.3078]},MV:{name:`Maldives`,coordinates:[73.5089,4.1755]},MU:{name:`Mauritius`,coordinates:[57.5522,-20.3484]}},k=({destinationMap:e,getLevel:t,containerRef:n,hoveredCountry:r,setHoveredCountry:i})=>{let{i18n:a}=s();return(0,C.jsx)(C.Fragment,{children:Object.entries(O).map(([s,c])=>{let u=e[s],d=u?.count||0,f=t(d),p=d>0,m=p?4:1.5;return(0,C.jsx)(l,{coordinates:o(c.coordinates[0],c.coordinates[1]),onMouseEnter:e=>{if(r?.isPinned)return;let t=y(s,a.language)||u?.name||s,o=b(s),c=n.current?.getBoundingClientRect();i({name:t,code:s,count:d,flag:o,x:e.clientX-(c?.left||0),y:e.clientY-(c?.top||0)-15})},onMouseMove:e=>{i(t=>{if(t?.isPinned)return t;let r=n.current?.getBoundingClientRect(),i=e.clientX-(r?.left||0),a=e.clientY-(r?.top||0)-15;return t?{...t,x:i,y:a}:null})},onMouseLeave:()=>{i(e=>e?.isPinned?e:null)},onClick:e=>{e.stopPropagation();let t=y(s,a.language)||u?.name||s,r=b(s),o=n.current?.getBoundingClientRect(),c=e.clientX-(o?.left||0),l=e.clientY-(o?.top||0)-15;i(e=>e?.code===s&&e?.isPinned?null:{name:t,code:s,count:d,flag:r,x:c,y:l,isPinned:!0})},children:p?(0,C.jsxs)(C.Fragment,{children:[(0,C.jsx)(`circle`,{r:m+3,fill:`var(--map-color-${f})`,opacity:.4,className:`animate-ping map-marker-circle`}),(0,C.jsx)(`circle`,{r:m,fill:`var(--map-color-${f})`,stroke:`var(--map-stroke)`,strokeWidth:.75,style:{cursor:`pointer`},className:`map-marker-circle`})]}):(0,C.jsx)(`circle`,{r:m,fill:`var(--text-color)`,opacity:.25,style:{pointerEvents:`none`}})},s)})})},A=({destinations:e,profileId:t,range:n,customRange:i,accessPointId:s})=>{let{geographyData:l,destinationMap:u,scaleConfig:d,getLevel:f,formatNumber:p}=S(e),[m,h]=(0,x.useState)({coordinates:o(0,0),zoom:1.2}),[g,_]=(0,x.useState)(null),[v,y]=(0,x.useState)(null),[b,O]=(0,x.useState)({}),A=(0,x.useRef)(null);A.current=g,(0,x.useEffect)(()=>{if(!g){y(null);return}if(g.isPinned){y(g);return}if(v&&v.code===g.code)return;let e=setTimeout(()=>{A.current&&A.current.code===g.code&&y(A.current)},100);return()=>clearTimeout(e)},[g?.code,g?.isPinned,v?.code]),(0,x.useEffect)(()=>{g&&v&&g.code===v.code&&(g.x!==v.x||g.y!==v.y||g.isPinned!==v.isPinned)&&y(g)},[g?.x,g?.y,g?.isPinned,v]);let j=(0,x.useRef)(null);x.useEffect(()=>{O({})},[t,n,i,s]);let M=x.useCallback((e,t)=>{O(n=>({...n,[e]:t}))},[]),N=x.useMemo(()=>c(o(-100,-50),o(900,600)),[]);return(0,C.jsxs)(`div`,{className:`relative w-full min-h-85 max-h-120 aspect-800/566 bg-gray-50 dark:bg-slate-950 rounded-xl overflow-hidden border border-gray-100 dark:border-slate-800 flex flex-col justify-between shadow-sm`,children:[(0,C.jsxs)(`div`,{ref:j,className:`relative w-full flex-1 min-h-0 overflow-hidden select-none cursor-grab active:cursor-grabbing`,onClick:e=>{(e.target===e.currentTarget||e.target.tagName===`svg`)&&_(null)},children:[(0,C.jsx)(r,{projection:`geoEqualEarth`,width:800,height:566,style:{width:`100%`,height:`100%`},children:(0,C.jsxs)(a,{zoom:m.zoom,center:m.coordinates,onMoveEnd:e=>h({coordinates:o(e.coordinates[0],e.coordinates[1]),zoom:e.zoom}),maxZoom:8,minZoom:1,enablePan:!0,translateExtent:N,children:[(0,C.jsx)(D,{geographyData:l,destinationMap:u,getLevel:f,containerRef:j,hoveredCountry:g,setHoveredCountry:_}),(0,C.jsx)(k,{destinationMap:u,getLevel:f,containerRef:j,hoveredCountry:g,setHoveredCountry:_})]})}),v&&(0,C.jsx)(E,{name:v.name,count:v.count,flag:v.flag,x:v.x,y:v.y,countryCode:v.code,profileId:t,range:n,customRange:i,accessPointId:s,ispCache:b,onCacheIsp:M,isPinned:v.isPinned||!1,onClose:()=>_(null)})]}),(0,C.jsx)(w,{onZoomIn:()=>{m.zoom>=8||h(e=>({...e,zoom:e.zoom*1.5}))},onZoomOut:()=>{m.zoom<=1||h(e=>({...e,zoom:e.zoom/1.5}))},onReset:()=>{h({coordinates:o(0,0),zoom:1.2})}}),(0,C.jsx)(T,{maxThreshold:d.maxThreshold,formatNumber:p})]})};export{A as DestinationMap};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{i as e}from"./rolldown-runtime-C4Xdq4VV.js";import{A as t,B as n,It as r,L as i,ct as a,ft as o,nn as s,w as c}from"./vendor-react-DYK5a2J9.js";import{S as l,b as u}from"./vendor-icons-other-BTYC6Wvz.js";import"./vendor-i18next-DlmslyBB.js";import{C as d,E as f,H as p,N as m,O as h,P as g,S as _,T as v,V as y,f as b,h as x,r as S,u as C,w,x as T}from"./vendor-ui-core-C4974KNo.js";import{_t as E}from"./vendor-utils-Bab4qB3W.js";import{$ as D,Ct as O,Et as k,K as A,h as j,hn as M,it as N,mt as P,nt as F,ot as I,wt as L}from"./index-DEIEgGUw.js";var R=e(l(),1);const z=()=>{let{t:e}=s(),[t,n]=(0,R.useState)([]);return(0,R.useEffect)(()=>{A().then(t=>{t&&Array.isArray(t)&&n(t.map(t=>({label:e(t.label),url:t.url})))}).catch(e=>console.warn(`Failed to fetch preset filters from API`,e))},[e]),t};var B=e(u(),1);const V=({newUrl:e,setNewUrl:t,onAddList:n,syncing:r,loading:i,lists:a})=>{let{t:o}=s(),c=(0,B.jsx)(f,{className:`min-w-96`,children:z().map((e,t)=>(0,B.jsx)(w,{text:e.label,onClick:()=>n(e.url),disabled:a.some(t=>t.url===e.url),labelElement:(0,B.jsx)(`div`,{className:`flex flex-col items-end text-right`,children:(0,B.jsx)(`span`,{className:`text-[9px] opacity-85 max-w-xl truncate`,title:e.url,children:e.url})})},t))});return(0,B.jsx)(T,{elevation:p.ONE,className:`mb-6`,children:(0,B.jsxs)(`div`,{className:`flex gap-2 flex-col sm:flex-row`,children:[(0,B.jsx)(b,{fill:!0,size:`large`,placeholder:o(`filtering.urlPlaceholder`),value:e,onChange:e=>t(e.target.value),leftIcon:`globe`,rightElement:(0,B.jsx)(v,{content:c,placement:`bottom-end`,animation:`minimal`,arrow:!1,usePortal:!0,children:(0,B.jsx)(m,{variant:`minimal`,icon:`chevron-down`})})}),(0,B.jsx)(m,{intent:y.PRIMARY,size:`large`,icon:`plus`,onClick:()=>n(),className:`shrink-0`,loading:r||i,disabled:r||i,children:o(`filtering.addSubscription`)})]})})},H=({lists:e,onSelect:t,loading:n=!1,emptyTitle:r,emptyDesc:i})=>{let{t:a}=s(),o=[{key:`url`,header:a(`filtering.tableUrl`),cellClassName:`font-mono text-sm max-w-md truncate`,render:e=>(0,B.jsxs)(`div`,{className:`flex items-center space-x-2 truncate`,children:[(0,B.jsx)(`span`,{className:`truncate`,children:e.url}),e.scope===`system`&&(0,B.jsx)(S,{intent:y.PRIMARY,minimal:!0,className:`shrink-0 text-xs font-sans`,children:a(`filtering.tagSystem`,`系统`)}),e.scope===`user`&&(0,B.jsx)(S,{intent:y.SUCCESS,minimal:!0,className:`shrink-0 text-xs font-sans`,children:a(`filtering.tagUser`,`用户`)})]})},{key:`lastSync`,header:a(`filtering.tableLastSync`),cellClassName:`text-xs opacity-60`,render:e=>e.last_synced_at?j(new Date(e.last_synced_at*1e3)):a(`filtering.neverSynced`)},{key:`status`,header:a(`filtering.tableStatus`),render:e=>{if(!e.enabled)return(0,B.jsx)(S,{intent:y.NONE,minimal:!0,children:a(`filtering.statusDisabled`,`Disabled`)});let t=!!e.sync_error,n=!!e.last_synced_at,r=a(`filtering.statusNormal`,`Active`),i=y.SUCCESS;return t&&(n?(r=a(`filtering.statusOutdated`,`Outdated`),i=y.WARNING):(r=a(`filtering.statusMissing`,`Missing`),i=y.DANGER)),(0,B.jsx)(S,{intent:i,minimal:!0,children:r})}}];return(0,B.jsx)(`div`,{className:`w-full max-w-full overflow-x-auto pb-4`,children:(0,B.jsxs)(C,{interactive:!0,striped:!0,className:`w-full min-w-max whitespace-nowrap`,children:[(0,B.jsx)(`thead`,{children:(0,B.jsx)(`tr`,{children:o.map(e=>(0,B.jsx)(`th`,{className:e.headerClassName,children:e.header},e.key))})}),(0,B.jsxs)(`tbody`,{children:[e.map(e=>(0,B.jsx)(`tr`,{onClick:()=>t(e),className:`cursor-pointer`,children:o.map(t=>(0,B.jsx)(`td`,{className:t.cellClassName,children:t.render(e)},t.key))},e.id)),e.length===0&&(0,B.jsx)(`tr`,{children:(0,B.jsx)(`td`,{colSpan:o.length,className:`text-center py-10 opacity-60`,children:n?(0,B.jsxs)(`div`,{className:`flex items-center justify-center space-x-2 py-4`,children:[(0,B.jsx)(g,{size:16}),(0,B.jsx)(`span`,{children:a(`common.loading`,`加载中...`)})]}):(0,B.jsxs)(`div`,{className:`flex flex-col items-center justify-center space-y-1 py-4 select-none`,children:[(0,B.jsx)(`span`,{className:`text-sm font-medium`,children:r||a(`filtering.noListsTitle`,`尚未添加列表`)}),(0,B.jsx)(`span`,{className:`text-xs opacity-75`,children:i||a(`filtering.noListsDesc`,`您还没有订阅任何外部拦截列表。`)})]})})})]})]})})},U=({profileId:e,selectedList:r,onClose:l,onCopy:u,onDelete:d,onToggleEnabled:f,onAllowDomain:p,onSyncSingle:g})=>{let{t:C}=s(),[w,T]=(0,R.useState)(``),[E,D]=(0,R.useState)(!1),[O,k]=(0,R.useState)(null),[A,M]=(0,R.useState)(null),[P,F]=(0,R.useState)(!1),[I,L]=(0,R.useState)(!1),[z,V]=(0,R.useState)(!1),[H,U]=(0,R.useState)(!1),[W,G]=(0,R.useState)(!1),K=(0,R.useRef)(0),q=()=>{K.current++,D(!1),T(``),k(null),M(null),L(!1),G(!1)},J=async()=>{let t=w.trim().toLowerCase();if(!t||!r||(t=t.replace(/^https?:\/\//,``).split(`/`)[0].split(`:`)[0].replace(/\.+$/,``),!t))return;T(t);let n=++K.current,i=r.id;D(!0),M(null),k(null),L(!1);try{let r=await N(e,i,t);K.current===n&&k(r)}catch(e){K.current===n&&M(e instanceof Error?e.message:String(e))}finally{K.current===n&&D(!1)}},Y=async e=>{if(r){V(!0);try{await f(r.id,e)}finally{V(!1)}}},X=async()=>{if(O?.matchedEntry){F(!0);try{await p(O.domain),L(!0)}catch(e){M(e instanceof Error?e.message:String(e))}finally{F(!1)}}},Z=async()=>{if(!(!r||!g)){U(!0);try{await g(r.id)}finally{U(!1)}}};return(0,B.jsxs)(h,{isOpen:r!==null,onClose:()=>{q(),l()},title:C(`filtering.listDetails`,`List Details`),icon:`info-sign`,children:[(0,B.jsxs)(`div`,{className:`p-6 space-y-4`,children:[r?.sync_error&&(0,B.jsx)(_,{intent:y.WARNING,title:C(`filtering.syncError`),icon:`warning-sign`,children:r.sync_error}),(0,B.jsxs)(`div`,{className:`bg-gray-50 dark:bg-gray-800 p-4 rounded-lg border border-gray-200 dark:border-gray-700 break-all font-mono text-sm flex items-center justify-between gap-2`,children:[(0,B.jsx)(`span`,{children:r?.url}),r?.scope===`system`&&(0,B.jsx)(S,{intent:y.PRIMARY,minimal:!0,className:`shrink-0 font-sans`,children:C(`filtering.tagSystem`,`系统`)}),r?.scope===`user`&&(0,B.jsx)(S,{intent:y.SUCCESS,minimal:!0,className:`shrink-0 font-sans`,children:C(`filtering.tagUser`,`用户`)})]}),r?.scope===`system`&&(0,B.jsx)(_,{intent:y.PRIMARY,icon:`info-sign`,className:`text-xs`,children:C(`filtering.systemListNotice`,`此列表由系统下发并应用于所有配置。可在当前配置中停用,但不可在配置中删除。`)}),r?.scope===`user`&&(0,B.jsx)(_,{intent:y.SUCCESS,icon:`info-sign`,className:`text-xs`,children:C(`filtering.userListNotice`,`此列表为账号级用户规则并应用于所有配置。可在当前配置中停用;如需删除,请前往「账号」管理页面。`)}),(0,B.jsxs)(`div`,{className:`flex items-center justify-between border border-gray-200 dark:border-gray-700 rounded-lg p-3`,children:[(0,B.jsxs)(`div`,{children:[(0,B.jsx)(`div`,{className:`text-sm font-bold`,children:C(`filtering.listEnabled`,`List active`)}),(0,B.jsx)(`div`,{className:`text-xs opacity-60`,children:C(`filtering.listEnabledHint`,`Disable to stop filtering with this list without deleting it. Its subscription and sync history are kept.`)})]}),(0,B.jsx)(x,{large:!0,checked:!!r?.enabled,disabled:z,onChange:e=>Y(e.target.checked)})]}),(0,B.jsxs)(`div`,{className:`border border-gray-200 dark:border-gray-700 rounded-lg p-3 space-y-3`,children:[(0,B.jsxs)(`div`,{children:[(0,B.jsx)(`div`,{className:`text-sm font-bold`,children:C(`filtering.checkDomain`,`Check a domain`)}),(0,B.jsx)(`div`,{className:`text-xs opacity-60`,children:C(`filtering.checkDomainHint`,`Lists are stored as compact filters, so their entries cannot be browsed. You can test any domain against this list instantly.`)})]}),(0,B.jsxs)(`div`,{className:`flex gap-2 items-center`,children:[(0,B.jsx)(b,{fill:!0,className:`flex-1 min-w-0`,placeholder:`example.com`,value:w,disabled:E,leftIcon:`globe-network`,onChange:e=>{T(e.target.value),k(null)},onKeyDown:e=>{e.key===`Enter`&&J()}}),(0,B.jsx)(m,{className:`shrink-0 whitespace-nowrap min-w-fit w-auto`,icon:(0,B.jsx)(i,{size:14}),text:C(`filtering.check`,`Check`),loading:E,disabled:!w.trim(),onClick:()=>void J()})]}),A&&(0,B.jsx)(_,{intent:y.DANGER,className:`text-xs`,children:A}),O&&!O.synced&&(0,B.jsx)(_,{intent:y.WARNING,className:`text-xs`,children:C(`filtering.checkNotSynced`,`This list has not finished syncing yet, so there is nothing to check against.`)}),O?.synced&&O.enabled===!1&&(0,B.jsx)(_,{intent:y.NONE,className:`text-xs`,children:C(`filtering.checkListDisabled`,`This list is currently disabled, so it is not filtering anything right now.`)}),O?.synced&&(0,B.jsx)(_,{intent:O.blocked?y.WARNING:y.SUCCESS,className:`text-xs`,icon:O.blocked?`ban-circle`:`tick-circle`,children:O.blocked?(0,B.jsxs)(`div`,{className:`space-y-2`,children:[(0,B.jsxs)(`div`,{children:[C(`filtering.checkBlocked`,`Blocked by this list`),O.matchedEntry&&O.matchedEntry!==O.domain&&(0,B.jsxs)(B.Fragment,{children:[` `,(0,B.jsx)(S,{minimal:!0,className:`font-mono`,children:O.matchedEntry}),` `,O.matchedEntry.includes(`*`)||O.matchedEntry.startsWith(`/`)?C(`filtering.checkViaPattern`,`(匹配到通配规则)`):C(`filtering.checkViaParent`,`(matched a parent domain)`)]})]}),I?(0,B.jsx)(S,{intent:y.SUCCESS,minimal:!0,children:C(`filtering.checkAllowed`,`Exception added - this domain now resolves`)}):(0,B.jsx)(m,{small:!0,icon:(0,B.jsx)(t,{size:12}),intent:y.PRIMARY,loading:P,text:C(`filtering.checkAllowAction`,`Allow anyway`),onClick:()=>void X()})]}):O.whitelisted?(0,B.jsxs)(`div`,{className:`space-y-1`,children:[(0,B.jsxs)(`div`,{className:`font-medium text-emerald-700 dark:text-emerald-400`,children:[C(`filtering.checkWhitelisted`,`被该列表放行`),O.matchedEntry&&(0,B.jsxs)(B.Fragment,{children:[` `,(0,B.jsx)(S,{minimal:!0,intent:y.SUCCESS,className:`font-mono`,children:O.matchedEntry})]})]}),(0,B.jsx)(`div`,{className:`opacity-75`,children:C(`filtering.checkWhitelistedDesc`,`命中该订阅列表中的白名单/例外规则 (@@),即使被其他黑名单规则命中也会优先放行。`)})]}):C(`filtering.checkNotBlocked`,`Not blocked by this list`)})]}),(0,B.jsxs)(`div`,{className:`flex justify-between items-center gap-3`,children:[(0,B.jsxs)(`span`,{className:`text-xs opacity-50 truncate min-w-0`,children:[C(`filtering.tableLastSync`),`:`,` `,r?.last_synced_at?j(new Date(r.last_synced_at*1e3)):`-`]}),(0,B.jsxs)(`div`,{className:`flex gap-2 shrink-0`,children:[(0,B.jsx)(m,{className:`shrink-0 whitespace-nowrap min-w-fit w-auto`,icon:(0,B.jsx)(o,{size:14}),text:C(`setup.copyUrl`,`Copy link`),onClick:()=>{r&&u(r.url)}}),(0,B.jsx)(m,{className:`shrink-0 whitespace-nowrap min-w-fit w-auto`,icon:(0,B.jsx)(a,{size:14}),text:C(`setup.learnMore`,`Open link`),onClick:()=>{r&&window.open(r.url,`_blank`)}})]})]})]}),(0,B.jsxs)(`div`,{className:`p-4 border-t border-gray-100 dark:border-gray-800 flex justify-between items-center`,children:[r?.scope===`profile`?(0,B.jsx)(v,{isOpen:W,onInteraction:G,placement:`top-start`,portalClassName:`z-20000`,content:(0,B.jsxs)(`div`,{className:`p-3 space-y-3 max-w-xs`,children:[(0,B.jsx)(`p`,{className:`text-xs font-semibold leading-relaxed m-0 text-gray-800 dark:text-gray-200`,children:C(`filtering.deleteConfirm`,`Are you sure you want to delete this list? This action cannot be undone.`)}),(0,B.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,B.jsx)(m,{small:!0,variant:`minimal`,text:C(`common.cancel`,`Cancel`),onClick:()=>G(!1)}),(0,B.jsx)(m,{small:!0,intent:y.DANGER,text:C(`common.confirm`,`Confirm`),onClick:()=>{if(!r)return;let e=r.id;G(!1),q(),d(e)}})]})]}),children:(0,B.jsx)(m,{icon:(0,B.jsx)(c,{size:14}),intent:y.DANGER,text:C(`rules.delete`,`Delete`),onClick:()=>G(!0)})}):(0,B.jsx)(`span`,{className:`text-xs text-gray-400 italic`,children:C(`filtering.cannotDeleteUserListDesc`,`用户级与系统级列表不可在配置中删除`)}),(0,B.jsxs)(`div`,{className:`flex gap-2`,children:[g&&(0,B.jsx)(m,{icon:(0,B.jsx)(n,{size:14,className:H?`animate-spin`:``}),intent:y.PRIMARY,loading:H,disabled:H,text:C(`filtering.syncSingle`,`同步此列表`),onClick:()=>void Z()}),(0,B.jsx)(m,{onClick:()=>{q(),l()},text:C(`rules.close`,`Close`)})]})]})]})},W=({profileId:e,toasterRef:t})=>{let i=r(),a=M(),[o,c]=(0,R.useState)([]),[l,u]=(0,R.useState)(``),[f,p]=(0,R.useState)(!0),[h,g]=(0,R.useState)(!1),{t:v}=s(),[b,x]=(0,R.useState)(null),S=async()=>{p(!0);try{c(await P(e))}catch(e){console.error(`Failed to fetch filters`,e)}finally{p(!1)}},C=e=>{navigator.clipboard.writeText(e),t?.current?.show({message:v(`setup.copied`,`已复制到剪贴板`),intent:y.SUCCESS,icon:`duplicate`})},w=async t=>{let n=new Map(t.map(e=>[e.id,e.last_synced_at])),r=0;for(;r<15;){await new Promise(e=>setTimeout(e,2e3));try{let t=await P(e),r=!0;for(let e of t){if(n.has(e.id)&&e.last_synced_at===n.get(e.id)){r=!1;break}if(!n.has(e.id)&&!e.last_synced_at){r=!1;break}}if(r&&t.length>0)return c(t),!0}catch{}r++}return await S(),!1},T=async(t,n)=>{let r=0;for(;r<15;){await new Promise(e=>setTimeout(e,2e3));try{let r=await P(e),i=r.find(e=>e.id===t);if(i&&(i.last_synced_at??0)!==(n??0))return c(r),x(i),!0}catch{}r++}return await S(),!1};return(0,R.useEffect)(()=>{S()},[e]),(0,B.jsxs)(`div`,{className:E(`md:px-8 w-full min-w-0 max-w-5xl mx-auto`,a?`p-1`:`px-8`),children:[(0,B.jsxs)(`div`,{className:`mb-8 flex flex-col md:flex-row justify-between items-start md:items-end gap-4`,children:[(0,B.jsxs)(`div`,{className:`w-full md:w-auto flex-1`,children:[a?(0,B.jsxs)(d,{minimal:!0,fill:a,children:[(0,B.jsx)(m,{active:!1,onClick:()=>i(`/dash/${e}/rules`),text:v(`rules.title`),large:!0}),(0,B.jsx)(m,{active:!0,onClick:()=>i(`/dash/${e}/filter`),text:v(`filtering.title`),large:!0})]}):(0,B.jsx)(`h1`,{className:`bp6-heading`,children:v(`filtering.title`)}),(0,B.jsx)(`p`,{className:`bp6-text-muted mt-2!`,children:v(`filtering.subtitle`)})]}),(0,B.jsx)(m,{icon:(0,B.jsx)(n,{size:16}),text:v(`filtering.syncAll`),onClick:async()=>{g(!0);try{await O(e),t?.current?.show({message:v(`filtering.syncTaskStarted`),intent:y.PRIMARY,icon:`cloud-download`}),await w(o)&&t?.current?.show({message:v(`filtering.syncCheckComplete`),intent:y.SUCCESS,icon:`tick`})}catch(e){console.error(e)}finally{g(!1)}},loading:h||f,disabled:h||f||o.length===0,className:a?`w-full`:``})]}),(0,B.jsx)(_,{intent:y.WARNING,icon:`info-sign`,className:`mb-6`,children:(0,B.jsx)(`p`,{children:v(`filtering.formatDisclaimer`)})}),(0,B.jsx)(V,{newUrl:l,setNewUrl:u,onAddList:async n=>{let r=n||l;if(r){g(!0);try{let n=await D(e,r);t?.current?.show({message:v(`filtering.addSuccess`),intent:y.SUCCESS,icon:`tick`}),u(``),t?.current?.show({message:v(`filtering.singleSyncStarted`,`列表同步任务已开始`),intent:y.PRIMARY,icon:`cloud-download`});let i=n?.id;if(!i){let t=await P(e);i=t.find(e=>e.url.trim().toLowerCase()===r.trim().toLowerCase())?.id,c(t)}i?await T(i,0)&&t?.current?.show({message:v(`filtering.syncCheckComplete`),intent:y.SUCCESS,icon:`tick`}):await S()}catch(e){console.error(e),t?.current?.show({message:e instanceof Error?e.message:String(e),intent:y.DANGER,icon:`error`})}finally{g(!1)}}},syncing:h,loading:f,lists:o}),(0,B.jsx)(`div`,{className:`mb-6`,children:(0,B.jsx)(H,{lists:o.filter(e=>e.scope===`profile`),onSelect:x,loading:f,emptyTitle:v(`filtering.noProfileListsTitle`,`尚未添加配置级列表`),emptyDesc:v(`filtering.noProfileListsDesc`,`您可在此为当前配置添加专属的拦截列表。`)})}),(0,B.jsxs)(`div`,{className:`border-t border-gray-200 dark:border-gray-800 my-8 pt-6`,children:[(0,B.jsxs)(`div`,{className:`mb-4`,children:[(0,B.jsxs)(`h3`,{className:`text-base font-semibold text-gray-900 dark:text-gray-100 flex items-center gap-2`,children:[(0,B.jsx)(`span`,{children:v(`filtering.userAndSystemListsTitle`,`用户级与系统级列表`)}),(0,B.jsxs)(`span`,{className:`text-xs font-normal text-gray-400`,children:[`(`,o.filter(e=>e.scope!==`profile`).length,`)`]})]}),(0,B.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-gray-400 mt-1`,children:v(`filtering.userAndSystemListsSubtitle`,`继承自账号设置或由系统下发的全局规则列表,自动应用于所有配置。可在此处针对当前配置停用,但不可在此删除。`)})]}),(0,B.jsx)(H,{lists:o.filter(e=>e.scope!==`profile`),onSelect:x,loading:f,emptyTitle:v(`filtering.noUserSystemListsTitle`,`暂无用户级与系统级列表`),emptyDesc:v(`filtering.noUserSystemListsDesc`,`可在账号设置页面中添加应用于所有配置的用户级规则。`)})]}),(0,B.jsx)(U,{profileId:e,selectedList:b,onClose:()=>x(null),onCopy:C,onDelete:async n=>{try{await I(e,n),t?.current?.show({message:v(`filtering.deleteSuccess`),intent:y.PRIMARY,icon:`trash`}),x(null),await S()}catch(e){console.error(e)}},onToggleEnabled:async(n,r)=>{try{await k(e,n,r),t?.current?.show({message:r?v(`filtering.listEnabledToast`,`List enabled - rebuilding filter`):v(`filtering.listDisabledToast`,`List disabled - rebuilding filter`),intent:y.PRIMARY,icon:r?`tick`:`disable`});let i=await P(e);if(c(i),b){let e=i.find(e=>e.id===n||e.url===b.url);e&&x(e)}}catch(e){console.error(e),t?.current?.show({message:e instanceof Error?e.message:String(e),intent:y.DANGER,icon:`error`})}},onAllowDomain:async n=>{await F(e,{type:`ALLOW`,pattern:n}),t?.current?.show({message:v(`filtering.allowRuleAdded`,`Exception added for {{domain}}`,{domain:n}),intent:y.SUCCESS,icon:`tick`})},onSyncSingle:async n=>{try{let r=o.find(e=>e.id===n)?.last_synced_at;await L(e,n),t?.current?.show({message:v(`filtering.singleSyncStarted`,`列表同步任务已开始`),intent:y.PRIMARY,icon:`cloud-download`}),await T(n,r)&&t?.current?.show({message:v(`filtering.syncCheckComplete`),intent:y.SUCCESS,icon:`tick`})}catch(e){console.error(e),t?.current?.show({message:e instanceof Error?e.message:String(e),intent:y.DANGER,icon:`error`})}}})]})};export{W as FilteringView};
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/services-BF0oUgkb.js","assets/index-DEIEgGUw.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-DYK5a2J9.js","assets/vendor-i18next-DlmslyBB.js","assets/vendor-ui-core-C4974KNo.js","assets/vendor-utils-Bab4qB3W.js","assets/index-DzxNVvDJ.css"])))=>i.map(i=>d[i]);
|
|
2
|
-
import{i as e}from"./rolldown-runtime-C4Xdq4VV.js";import{$ as t,At as n,Ct as r,G as i,J as a,M as o,St as s,Tt as c,W as l,X as u,at as d,b as f,it as p,j as m,nn as h}from"./vendor-react-DYK5a2J9.js";import{S as g,b as _,x as v}from"./vendor-icons-other-BTYC6Wvz.js";import"./vendor-i18next-DlmslyBB.js";import{C as y,E as b,M as x,N as S,P as C,S as w,T,V as E,a as D,f as O,h as k,l as A,o as j,p as M,r as N,u as P,w as F,x as I}from"./vendor-ui-core-C4974KNo.js";import{_t as L}from"./vendor-utils-Bab4qB3W.js";import{A as R,S as z,dt as ee,ft as B,gt as V,h as H,hn as te,ht as U,pt as W,w as G}from"./index-DEIEgGUw.js";import{n as K,t as q}from"./formatCountryName-C6cFVUu2.js";import{t as J}from"./getFlagEmoji-Cd2A891A.js";import{i as ne,n as re,r as ie,t as ae}from"./useLogsE2ee-CARmudiz.js";import{t as Y}from"./SwipeableDrawer-BuCjl9Vd.js";var X=e(g(),1),Z=e(_(),1);const oe=({range:e,setRange:t,customRange:n,setCustomRange:r,nowStr:i,fetchLogs:a,isMobile:o,logRetentionDays:c})=>{let{t:l}=h(),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)(y,{minimal:o,variant:o?void 0:`minimal`,children:[u.map(n=>(0,Z.jsx)(S,{active:e===n,onClick:()=>t(n),text:n.toUpperCase(),small:o},n)),(0,Z.jsx)(T,{content:(0,Z.jsxs)(`div`,{className:`p-4 space-y-2 w-64`,children:[(0,Z.jsx)(x,{children:l(`analytics.customRange`)}),(0,Z.jsx)(M,{label:l(`analytics.startTime`),children:(0,Z.jsx)(O,{type:`datetime-local`,max:n.end||i,value:n.start,onChange:e=>r({...n,start:e.target.value})})}),(0,Z.jsx)(M,{label:l(`analytics.endTime`),children:(0,Z.jsx)(O,{type:`datetime-local`,min:n.start,max:i,value:n.end,onChange:e=>r({...n,end:e.target.value})})}),(0,Z.jsx)(S,{fill:!0,intent:E.PRIMARY,text:l(`analytics.apply`),onClick:()=>{t(`custom`),a(`custom`,!0)}})]}),children:(0,Z.jsx)(S,{active:e===`custom`,icon:(0,Z.jsx)(s,{size:14}),text:o?``:l(`analytics.custom`),small:o})})]})})},se=({statusFilter:e,setStatusFilter:t,isMobile:n})=>{let{t:r}=h(),i=(0,Z.jsxs)(b,{children:[(0,Z.jsx)(F,{icon:e===null?`tick`:void 0,text:r(`logs.allStatus`),onClick:()=>t(null)}),(0,Z.jsx)(A,{}),(0,Z.jsx)(F,{icon:e===`PASS`?`tick`:void 0,intent:E.SUCCESS,text:r(`logs.onlyPass`),onClick:()=>t(`PASS`)}),(0,Z.jsx)(F,{icon:e===`BLOCK`?`tick`:void 0,intent:E.DANGER,text:r(`logs.onlyBlock`),onClick:()=>t(`BLOCK`)}),(0,Z.jsx)(F,{icon:e===`REDIRECT`?`tick`:void 0,intent:E.WARNING,text:r(`logs.onlyRedirect`),onClick:()=>t(`REDIRECT`)})]}),a=(()=>{switch(e){case`PASS`:return{text:r(`logs.statusPass`),intent:E.SUCCESS};case`BLOCK`:return{text:r(`logs.statusBlock`),intent:E.DANGER};case`REDIRECT`:return{text:r(`logs.statusRedirect`),intent:E.WARNING};default:return{text:r(`logs.allStatus`),intent:E.NONE}}})();return(0,Z.jsx)(T,{content:i,placement:`bottom-start`,children:(0,Z.jsx)(S,{icon:(0,Z.jsx)(d,{size:14}),rightIcon:`caret-down`,intent:a.intent,text:a.text,variant:`outlined`,fill:n})})},ce=({accessPointIdFilter:e,setAccessPointIdFilter:t,accessPoints:n,isMobile:r})=>{let{t:i}=h(),o=(0,Z.jsxs)(b,{children:[(0,Z.jsx)(F,{icon:e===null?`tick`:void 0,text:i(`logs.allAccessPoint`),onClick:()=>t(null)}),(0,Z.jsx)(A,{}),n.map(n=>(0,Z.jsx)(F,{icon:e===n.id?`tick`:void 0,text:n.name,onClick:()=>t(n.id)},n.id))]}),s=e&&n.find(t=>t.id===e)?.name||i(`logs.allAccessPoint`);return(0,Z.jsx)(T,{content:o,placement:`bottom-start`,children:(0,Z.jsx)(S,{icon:(0,Z.jsx)(a,{size:14}),rightIcon:`caret-down`,intent:e?E.PRIMARY:E.NONE,text:s,variant:`outlined`,fill:r})})},le=Array.from(new Set(Object.values(K))).sort((e,t)=>e.localeCompare(t)),ue=({destCountryFilter:e,setDestCountryFilter:t,isMobile:n})=>{let{t:r,i18n:i}=h(),[a,o]=(0,X.useState)(!1),[s,c]=(0,X.useState)(``),l=(0,X.useMemo)(()=>{let e=i.language;return le.map(t=>{let n=q(t,e),r=q(t,`en`);return{code:t,name:n||r||t,searchStr:`${t} ${n} ${r}`.toLowerCase()}})},[i.language]),u=(0,X.useMemo)(()=>{let e=s.trim().toLowerCase();return e?l.filter(t=>t.searchStr.includes(e)):l},[l,s]),d=(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)(O,{leftIcon:`search`,placeholder:r(`logs.searchCountry`,`Search country...`),value:s,onChange:e=>c(e.target.value),small:!0,autoFocus:!0,rightElement:s?(0,Z.jsx)(S,{icon:`cross`,variant:`minimal`,small:!0,onClick:()=>c(``)}):void 0})}),(0,Z.jsxs)(b,{className:`max-h-64 overflow-y-auto`,children:[!s&&(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(F,{icon:e===null?`tick`:void 0,text:r(`logs.allCountry`),onClick:()=>{t(null),o(!1)}}),(0,Z.jsx)(A,{})]}),u.length===0?(0,Z.jsx)(F,{disabled:!0,text:r(`logs.noMatchingCountries`,`No matching countries found`)}):u.map(n=>(0,Z.jsx)(F,{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:[J(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),o(!1)}},n.code))]})]}),f=e?`${J(e)} ${q(e,i.language)||e} (${e})`:r(`logs.allCountry`);return(0,Z.jsx)(T,{content:d,placement:`bottom-start`,isOpen:a,onInteraction:e=>{o(e),e||c(``)},children:(0,Z.jsx)(S,{icon:(0,Z.jsx)(p,{size:14}),rightIcon:`caret-down`,intent:e?E.PRIMARY:E.NONE,text:f,variant:`outlined`,fill:n})})},de=({profileId:e,range:t,customRange:n,destCountryFilter:r,accessPointIdFilter:a,ispFilter:o,setIspFilter:s,isMobile:c})=>{let{t:l}=h(),[u,d]=(0,X.useState)(!1),[f,p]=(0,X.useState)([]),[m,g]=(0,X.useState)(!1),[_,v]=(0,X.useState)(``),y=(0,X.useRef)(``),x=`${e}:${t}:${n.start?Math.floor(new Date(n.start).getTime()/1e3):``}:${n.end?Math.floor(new Date(n.end).getTime()/1e3):``}:${r||``}:${a||``}`,w=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-3600;break}c.set(`range`,t)}r&&c.set(`country_code`,r),a&&c.set(`access_point_id`,a);try{let t=await B(e,`isps`,c.toString());if(Array.isArray(t)&&t.length>0){p(t),y.current=x,g(!1);return}}catch(e){console.debug(`[IspFilter] Server ISP fetch failed, falling back to local DB:`,e)}try{let t=await G.queryISPs({profileId:e,countryCode:r||void 0,since:o,until:s,accessPointId:a||void 0});t&&t.length>0?p(t):p([])}catch(e){console.warn(`[IspFilter] Local SQLite query failed:`,e),p([])}y.current=x}catch(e){console.error(`Failed to fetch ISPs for filter`,e)}finally{g(!1)}},D=e=>{d(e),e?y.current!==x&&w():v(``)},k=(0,X.useMemo)(()=>{let e=_.trim().toLowerCase();return e?f.filter(t=>t.name.toLowerCase().includes(e)):f},[f,_]),j=(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)(O,{leftIcon:`search`,placeholder:l(`logs.searchIsp`,`Search ISP...`),value:_,onChange:e=>v(e.target.value),small:!0,autoFocus:!0,rightElement:_?(0,Z.jsx)(S,{icon:`cross`,variant:`minimal`,small:!0,onClick:()=>v(``)}):void 0})}),(0,Z.jsx)(b,{className:`max-h-64 overflow-y-auto`,children:m?(0,Z.jsxs)(`div`,{className:`flex items-center justify-center p-6 text-gray-500 gap-2`,children:[(0,Z.jsx)(C,{size:16}),(0,Z.jsx)(`span`,{className:`text-xs`,children:l(`logs.loadingIsps`,`Loading ISPs...`)})]}):(0,Z.jsxs)(Z.Fragment,{children:[!_&&(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(F,{icon:o===null?`tick`:void 0,text:l(`logs.allIsp`),onClick:()=>{s(null),d(!1)}}),(0,Z.jsx)(A,{})]}),k.length===0?(0,Z.jsx)(F,{disabled:!0,text:l(`logs.noMatchingIsps`,`No matching ISPs found`)}):k.map(e=>(0,Z.jsx)(F,{icon:o===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:()=>{s(e.name),d(!1)}},e.name))]})})]}),M=o||l(`logs.allIsp`);return(0,Z.jsx)(T,{content:j,placement:`bottom-start`,isOpen:u,onInteraction:D,children:(0,Z.jsx)(S,{icon:(0,Z.jsx)(i,{size:14}),rightIcon:`caret-down`,intent:o?E.PRIMARY:E.NONE,text:M,variant:`outlined`,fill:c})})},fe=({profileId:e,range:t,setRange:n,customRange:r,setCustomRange:i,nowStr:a,fetchLogs:o,isMobile:s,realtimeRefresh:c,setRealtimeRefresh:l,statusFilter:u,setStatusFilter:d,accessPointIdFilter:f,setAccessPointIdFilter:p,accessPoints:m,destCountryFilter:g,setDestCountryFilter:_,ispFilter:v,setIspFilter:y,searchQuery:b,setSearchQuery:x,stats:C,logRetentionDays:w,onExport:T,exporting:D,loading:A=!1,syncing:j=!1})=>{let{t:M}=h(),[P,F]=(0,X.useState)(!0),I=u!==null||f!==null||g!==null||v!==null;return(0,Z.jsxs)(`div`,{className:`p-4 ${s&&P?`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:[M(`logs.title`),` `,(!s||!P)&&(0,Z.jsx)(N,{minimal:!0,round:!0,children:t===`custom`?M(`analytics.custom`):t.toUpperCase()}),C&&(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(N,{minimal:!0,round:!0,children:C.total.toLocaleString()}),(0,Z.jsx)(N,{minimal:!0,round:!0,intent:E.SUCCESS,children:C.pass.toLocaleString()}),(0,Z.jsx)(N,{minimal:!0,round:!0,intent:E.DANGER,children:C.block.toLocaleString()}),(0,Z.jsx)(N,{minimal:!0,round:!0,intent:E.WARNING,children:C.redirect.toLocaleString()})]})]}),!s&&(0,Z.jsx)(`p`,{className:`bp6-text-muted mt-1`,children:M(`logs.subtitle`)})]}),s&&(0,Z.jsx)(S,{icon:P?`chevron-down`:`chevron-up`,variant:`minimal`,onClick:()=>F(!P)})]}),(!s||!P)&&(0,Z.jsxs)(`div`,{className:`flex flex-col items-stretch md:items-end gap-2`,children:[(0,Z.jsx)(oe,{range:t,setRange:n,customRange:r,setCustomRange:i,nowStr:a,fetchLogs:o,isMobile:s,logRetentionDays:w}),(0,Z.jsxs)(`div`,{className:`flex items-center justify-end gap-4`,children:[(0,Z.jsx)(S,{icon:`download`,onClick:T,loading:D,title:M(`logs.export`,`Export Logs`),text:s?void 0:M(`logs.export`,`Export Logs`)}),(0,Z.jsx)(k,{label:M(`logs.realtime`),checked:c,onChange:e=>l(e.target.checked),className:`mb-0!`}),(0,Z.jsx)(S,{icon:`refresh`,onClick:()=>o(t,!0,!1,!0),loading:A||j,variant:`minimal`,small:s})]})]})]}),(!s||!P)&&(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:[I&&(0,Z.jsx)(`div`,{className:`col-span-2 md:contents`,children:(0,Z.jsx)(S,{icon:`filter-remove`,onClick:()=>{d(null),p(null),_(null),y(null)},variant:`minimal`,title:M(`logs.clearFilters`),text:s?M(`logs.clearFilters`):void 0,fill:s})}),(0,Z.jsx)(se,{statusFilter:u,setStatusFilter:d,isMobile:s}),m.length>0&&(0,Z.jsx)(ce,{accessPointIdFilter:f,setAccessPointIdFilter:p,accessPoints:m,isMobile:s}),(0,Z.jsx)(ue,{destCountryFilter:g,setDestCountryFilter:_,isMobile:s}),(0,Z.jsx)(de,{profileId:e,range:t,customRange:r,destCountryFilter:g,accessPointIdFilter:f,ispFilter:v,setIspFilter:y,isMobile:s})]}),(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)(O,{leftIcon:`search`,placeholder:M(`logs.searchPlaceholder`),value:b,onChange:e=>x(e.target.value),rightElement:b?(0,Z.jsx)(S,{icon:`cross`,minimal:!0,onClick:()=>x(``)}):void 0,fill:!0})})})]})]})},pe=({logs:e,setSelectedLog:n,setIsDrawerOpen:r,lastLogElementRef:i,prevLatestTimestamp:a,realtimeRefresh:o})=>{let{t:s}=h();return(0,Z.jsx)(`div`,{className:`space-y-3 py-4`,children:e.map((c,l)=>{let u=o&&a!==null&&c.timestamp>a,d=(c.encrypt_version??0)>0||!!(c.kem_key_id||c.encrypted_payload),f=d&&(!c.domain||c.domain===`[Encrypted]`),p=d&&!!(c.domain&&c.domain!==`[Encrypted]`);return(0,Z.jsxs)(I,{interactive:!0,onClick:()=>{n(c),r(!0)},className:L(`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?i: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)(t,{size:14,className:`text-amber-500 shrink-0`}):(0,Z.jsx)(`img`,{src:`/api/icon/${c.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:L(`font-bold text-sm truncate`,{"italic text-gray-400 dark:text-gray-500":f}),children:f?s(`logs.encryptedRecord`,`[加密记录]`):c.domain}),p&&(0,Z.jsx)(t,{size:12,className:`text-emerald-500 shrink-0 opacity-80`})]}),(0,Z.jsx)(N,{minimal:!0,round:!0,intent:c.action===`PASS`?E.SUCCESS:c.action===`BLOCK`?E.DANGER:E.WARNING,className:`text-[10px] shrink-0`,children:c.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(c.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:c.record_type}),c.access_point_name&&(0,Z.jsx)(`span`,{className:`text-[10px] opacity-50 truncate max-w-25`,children:c.access_point_name})]}),(0,Z.jsx)(`div`,{className:`text-[10px] opacity-40 font-mono italic`,children:c.latency?`${c.latency}ms`:``})]})]},c.id)})})},me=({logs:e,setSelectedLog:n,setIsDrawerOpen:r,lastLogElementRef:i,prevLatestTimestamp:a,realtimeRefresh:o})=>{let{t:s}=h(),c=[{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 n=(e.encrypt_version??0)>0||!!(e.kem_key_id||e.encrypted_payload),r=n&&(!e.domain||e.domain===`[Encrypted]`),i=n&&!!(e.domain&&e.domain!==`[Encrypted]`);return(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 truncate`,children:[r?(0,Z.jsx)(t,{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:L(`font-bold text-sm truncate`,{"italic text-gray-400 dark:text-gray-500":r}),children:r?s(`logs.encryptedRecord`,`[加密记录]`):e.domain}),i&&(0,Z.jsx)(`span`,{title:s(`settings.e2eeEnabled`,`已加密`),className:`inline-flex items-center`,children:(0,Z.jsx)(t,{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)(N,{minimal:!0,className:`font-mono text-[10px]`,title:e.geo_country||`Unknown`,children:J(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:L(`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)(P,{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:c.map(e=>(0,Z.jsx)(`th`,{className:L(`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((t,s)=>{let l=o&&a!==null&&t.timestamp>a;return(0,Z.jsx)(`tr`,{onClick:()=>{n(t),r(!0)},className:L(`cursor-pointer`,{"animate-row-glow":l}),ref:s===e.length-1?i:null,children:c.map(e=>(0,Z.jsx)(`td`,{className:L(`px-4 py-3`,e.cellClassName),children:e.render(t,s)},e.key))},t.id)})})]})})})},he=({logs:e,loading:t,loadingMore:n,hasMore:i,realtimeRefresh:a,isMobile:o,searchQuery:s,scrollContainerRef:c,lastLogElementRef:l,prevLatestTimestamp:u,setSelectedLog:d,setIsDrawerOpen:f,logRetentionDays:p})=>{let{t:m}=h(),[g,_]=(0,X.useState)(!1),v=(0,X.useCallback)(()=>{c.current&&_(c.current.scrollTop>300)},[c]);return(0,X.useEffect)(()=>{let e=c.current;if(e)return e.addEventListener(`scroll`,v,{passive:!0}),v(),()=>{e.removeEventListener(`scroll`,v)}},[c,v,e]),(0,Z.jsxs)(`div`,{className:`flex-1 relative overflow-hidden flex flex-col min-h-0`,children:[(0,Z.jsxs)(`div`,{ref:c,onScroll:v,className:L(`flex-1 overflow-y-auto`,o?`px-1`:`px-0`),children:[e.length===0&&!t?(0,Z.jsx)(`div`,{className:`py-20`,children:(0,Z.jsx)(w,{title:p===0?m(`logs.loggingDisabledTitle`,`日志记录已关闭`):m(s?`logs.noResults`:`logs.noRecords`),icon:p===0?`disable`:s?`search`:`outdated`,intent:p===0?E.WARNING:E.NONE,children:p===0?m(`logs.loggingDisabledDesc`,`当前配置的日志留存已设置为“关闭”,系统不记录任何查询日志。如需查看,请在设置中启用日志留存。`):s?m(`logs.noResultsDesc`,{query:s}):m(`logs.noRecordsDesc`)})}):o?(0,Z.jsx)(pe,{logs:e,setSelectedLog:d,setIsDrawerOpen:f,lastLogElementRef:l,prevLatestTimestamp:u,realtimeRefresh:a}):(0,Z.jsx)(me,{logs:e,setSelectedLog:d,setIsDrawerOpen:f,lastLogElementRef:l,prevLatestTimestamp:u,realtimeRefresh:a}),(0,Z.jsx)(`div`,{className:`p-6 flex flex-col items-center`,children:n?(0,Z.jsx)(C,{size:16}):a?e.length>0&&(0,Z.jsx)(`span`,{className:`text-[10px] opacity-30 italic`,children:m(`logs.realtimeLoadMoreTip`)}):!i&&e.length>0&&(0,Z.jsx)(`span`,{className:`text-[10px] opacity-30 italic`,children:m(`logs.loadedAll`,{count:e.length})})})]}),(0,Z.jsx)(`div`,{className:L(`absolute z-30 pointer-events-none transition-all duration-300 ease-out`,o?`bottom-20 right-3`:`bottom-6 right-6`,g?`opacity-100 translate-y-0`:`opacity-0 translate-y-3`),children:(0,Z.jsx)(`button`,{type:`button`,onClick:()=>{c.current?.scrollTo({top:0,behavior:`smooth`})},"aria-label":m(`logs.scrollToTop`),title:m(`logs.scrollToTop`),className:L(`pointer-events-auto group inline-flex items-center gap-1.5 rounded-full select-none`,`backdrop-blur-md bg-white/70 dark:bg-gray-900/70 hover:bg-white/90 dark:hover:bg-gray-800/90`,`border border-gray-200/80 dark:border-gray-700/80 hover:border-gray-300 dark:hover:border-gray-600`,`text-gray-700 dark:text-gray-200 hover:text-gray-950 dark:hover:text-white`,`shadow-sm hover:shadow active:scale-95 transition-all duration-200 cursor-pointer`,o?`px-2.5 py-1.5 text-[11px]`:`px-3.5 py-2 text-xs`),children:(0,Z.jsx)(r,{size:o?13:15,strokeWidth:2.4,className:`transition-transform duration-200 group-hover:scale-105`})})})]})};function ge(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 U(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 R.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:L(`text-sm text-right`,n&&`font-bold`,r&&`italic`),children:t})]}),_e=({selectedLog:e,detailedLog:r,loading:i})=>{let{t:a}=h(),o=r?.encrypt_version??e.encrypt_version??(r?.kem_key_id||e.kem_key_id?2:0),s=o>0||!!(e.kem_key_id||e.encrypted_payload||r?.kem_key_id||r?.encrypted_payload),c=o===2||!!(e.kem_key_id||r?.kem_key_id),l=s&&(!e.domain||e.domain===`[Encrypted]`);return(0,Z.jsx)(j,{title:a(`logs.basicInfo`),icon:(0,Z.jsx)(n,{size:16}),className:`shadow-none! rounded-lg!`,children:(0,Z.jsx)(D,{children:(0,Z.jsxs)(`div`,{className:`space-y-3`,children:[(0,Z.jsx)(Q,{label:a(`logs.detailDomain`),value:(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 justify-end font-bold`,children:[l?(0,Z.jsx)(t,{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:L({"italic text-gray-400 dark:text-gray-500":l}),children:l?a(`logs.encryptedRecord`,`[加密记录]`):e.domain})]}),bold:!0}),(0,Z.jsx)(Q,{label:a(`logs.detailType`),value:e.record_type}),(0,Z.jsx)(Q,{label:a(`logs.detailLatency`),value:e.latency?`${e.latency} ms`:`-`}),(0,Z.jsx)(Q,{label:a(`logs.detailAccessPoint`),value:(()=>{let t=r?.access_point_name||e.access_point_name,n=r?.access_point_id||e.access_point_id;return t?n&&n!==t?(0,Z.jsx)(`span`,{title:n,className:`cursor-help`,children:t}):t:n?(0,Z.jsx)(`span`,{className:`font-mono text-xs`,children:n}):i?(0,Z.jsx)(C,{size:12}):`-`})()}),(0,Z.jsx)(Q,{label:a(`logs.detailProfile`),value:r?.profile_name||r?.client_ip||e.client_ip||(i?(0,Z.jsx)(C,{size:12}):`-`)}),(0,Z.jsx)(Q,{label:a(`logs.detailTime`),value:H(new Date(e.timestamp*1e3))}),(0,Z.jsx)(Q,{label:a(`logs.detailStatus`),value:(0,Z.jsx)(N,{minimal:!0,intent:e.action===`PASS`?E.SUCCESS:e.action===`BLOCK`?E.DANGER:E.WARNING,children:e.action})}),(0,Z.jsx)(Q,{label:a(`logs.detailUpstream`),value:r?.upstream||e.upstream||(i?(0,Z.jsx)(C,{size:12}):`-`)}),(0,Z.jsx)(Q,{label:a(`logs.detailReason`),value:e.reason||a(`logs.detailNoReason`),italic:!0}),(0,Z.jsx)(Q,{label:a(`logs.detailECS`),value:r?.ecs||e.ecs||(i?(0,Z.jsx)(C,{size:12}):`-`),italic:!0}),(0,Z.jsx)(Q,{label:a(`logs.detailIsClientEncrypted`,`是否用户端加密`),value:s?(0,Z.jsxs)(`div`,{className:`flex items-center gap-1.5 justify-end`,children:[(0,Z.jsx)(t,{size:13,className:l?`text-amber-500`:`text-emerald-500`}),(0,Z.jsxs)(`span`,{className:L(`text-xs font-medium`,l?`text-amber-600 dark:text-amber-400`:`text-emerald-600 dark:text-emerald-400`),children:[l?a(`logs.encryptedLocked`,`是 (未解锁)`):a(`logs.encryptedYes`,`是`),c?` (PQC)`:``]})]}):(0,Z.jsx)(`span`,{className:`text-xs text-gray-400 dark:text-gray-500`,children:a(`logs.notEncrypted`,`否`)})})]})})})},ve=({selectedLog:e})=>{let{t}=h(),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)(j,{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)(N,{minimal:!0,intent:E.PRIMARY,className:`text-xs`,children:t(`logs.rewritten`,`已重写`)})]}),icon:(0,Z.jsx)(p,{size:16}),className:`shadow-none! rounded-lg!`,children:(0,Z.jsx)(D,{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)(N,{minimal:!0,intent:E.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)(N,{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)(N,{minimal:!0,intent:E.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)(N,{minimal:!0,intent:E.WARNING,className:`font-mono`,children:[(0,Z.jsx)(`span`,{className:`font-bold`,children:`alpn:`}),` `,i]},t):(0,Z.jsxs)(N,{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)})})})()})})})},ye=({selectedLog:e,detailedLog:t,loading:n})=>{let{t:r,i18n:i}=h(),a=t?.client_ip||e.client_ip,o=t?.geo_country||e.geo_country,s=`Unknown`;if(o){let e=o.toUpperCase().trim();s=e===`LAN`||e===`LOCAL`||e===`PRIVATE`||e===`PRIVATE NETWORK`?r(`setup.privateNetwork`,`Private Network`):e===`UN`||e===`UNKNOWN`||e===`XX`?r(`common.unknown`,`Unknown`):q(o,i.language)||o}let c=t?.dest_country_code||e.dest_country_code,l=t?.dest_country||e.dest_country,d=t?.dest_isp||e.dest_isp,p=null,m=t?.dest_geoip||e.dest_geoip;if(m)try{let e=JSON.parse(m);!c&&e.country_code&&(c=e.country_code);let t=[e.city,e.region,e.country].filter(Boolean),n=l||c||void 0;p={locationTitle:t.length>0?t.join(`, `):n,isp:e.isp||d||void 0,as:e.as||void 0}}catch{}return!p&&(l||c||d)&&(p={locationTitle:l||c||void 0,isp:d||void 0}),(0,Z.jsx)(j,{title:r(`logs.networkDetails`),icon:(0,Z.jsx)(f,{size:16}),className:`shadow-none! rounded-lg!`,children:(0,Z.jsx)(D,{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)(C,{size:12}):`-`)}),(o||n)&&(0,Z.jsx)(N,{minimal:!0,title:s,children:o?J(o):`-`})]})]}),(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`)}),(c||n)&&(0,Z.jsx)(N,{minimal:!0,title:l||c||`Unknown`,children:c?J(c):`-`})]}),n&&!p?(0,Z.jsx)(`div`,{className:`flex items-center justify-center py-2`,children:(0,Z.jsx)(C,{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)(u,{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:`-`})]})]})})})},be=({selectedLog:e,onQuickAction:t})=>{let{t:n}=h(),r=(e.encrypt_version??0)>0&&(!e.domain||e.domain===`[Encrypted]`);return(0,Z.jsx)(j,{title:n(`logs.quickActions`),icon:(0,Z.jsx)(l,{size:16}),className:`shadow-none! rounded-lg!`,children:(0,Z.jsx)(D,{children:r?(0,Z.jsx)(`p`,{className:`text-xs text-center text-gray-500 italic py-2 m-0`,children:n(`settings.e2eeUnlockPrompt`,`此记录已加密,请先解锁私钥后再进行操作。`)}):(0,Z.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,Z.jsx)(S,{fill:!0,intent:E.SUCCESS,icon:(0,Z.jsx)(o,{size:16}),text:n(`logs.actionAllow`),onClick:()=>t?.(e.domain,`ALLOW`)}),(0,Z.jsx)(S,{fill:!0,intent:E.DANGER,icon:(0,Z.jsx)(m,{size:16}),text:n(`logs.actionBlock`),onClick:()=>t?.(e.domain,`BLOCK`)}),(0,Z.jsx)(S,{fill:!0,icon:(0,Z.jsx)(c,{size:16}),text:n(`logs.actionRedirect`),onClick:()=>t?.(e.domain,`REDIRECT`,e.record_type)})]})})})},xe=({isDrawerOpen:e,setIsDrawerOpen:t,selectedLog:r,profileId:i,isMobile:a,onQuickAction:o})=>{let{t:s}=h(),{detailedLog:c,loading:l}=ge(e,r,i);return(0,Z.jsx)(Y,{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:s(`logs.logDetails`)})]}),icon:`info-sign`,size:a?`100%`:`450px`,children:r&&(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(_e,{selectedLog:r,detailedLog:c,loading:l}),(0,Z.jsx)(ve,{selectedLog:r}),(0,Z.jsx)(ye,{selectedLog:r,detailedLog:c,loading:l}),(0,Z.jsx)(be,{selectedLog:r,onQuickAction:o})]})})};function Se(e){let[t,n]=(0,X.useState)(`1h`),[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)(()=>{ee(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 Ce(e){let[t,n]=(0,X.useState)(30);return(0,X.useEffect)(()=>{W(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 we(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-3600;break}return{since:r,until:n}}function Te(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 Ee(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=V(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),c&&e.set(`status`,c),l&&e.set(`access_point_id`,l),u&&e.set(`dest_country`,u),d&&e.set(`isp`,d),_=B(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 De(e,t,n,r){if(!await G.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 G.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 G.syncProfileLogs(i,void 0,u,t,n);if(!t.aborted&&(e>0||p.rows.length===0)&&(p=await G.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 Oe(e,t,n){if(!await G.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 G.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 G.backfillLogs(r,t,l,d,n);if(n.aborted)return{success:!1};if(e.length>0){let f=await G.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 ke({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}=we(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 l=new URLSearchParams({range:t});t===`custom`&&n.start&&n.end&&(l.set(`start`,String(y)),l.set(`end`,String(x))),s&&l.set(`search`,s),r&&l.set(`status`,r),i&&l.set(`access_point_id`,i),a&&l.set(`dest_country`,a),o&&l.set(`isp`,o),B(e,`summary`,l.toString(),{signal:h.signal}).then(e=>{if(h.signal.aborted||!e)return;let t={total:0,pass:0,block:0,redirect:0};e.forEach(e=>{let n=Number(e.count)||0;t.total+=n,e.action===`PASS`?t.pass=n:e.action===`BLOCK`?t.block=n:e.action===`REDIRECT`&&(t.redirect=n)}),b(t)}).catch(()=>{});let m=await De(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&&z.updateCursor(e.rows[0].timestamp,e.rows[0].id),e.stats&&b(e.stats),f(!1)});if(h.signal.aborted)return;m.success&&m.result&&(D=!0,S(d&&C.current.length>0?C.current[0].timestamp:null),u(m.result.rows),v(c?!1:m.result.hasMore),c&&m.result.rows.length>0&&z.updateCursor(m.result.rows[0].timestamp,m.result.rows[0].id),m.result.stats&&b(m.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 Oe(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){Te(C.current),w.current===h&&(f(!1),m(!1),g(!1),T.current=!1);return}let O=await Ee({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&&z.updateCursor(O.logs[0].timestamp,O.logs[0].id),Te(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 Ae({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 z.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 je({profileId:e,range:t,customRange:n,statusFilter:r,accessPointIdFilter:i,destCountryFilter:a,ispFilter:o,searchQuery:s,realtimeRefresh:c}){let l=Ce(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}=ke({profileId:e,range:t,customRange:n,statusFilter:r,accessPointIdFilter:i,destCountryFilter:a,ispFilter:o,searchQuery:s,realtimeRefresh:c});Ae({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 Me({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){z.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=z.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;z.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&&z.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(),z.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 Ne(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=``;if(e===`time`)t=$(r.timestamp);else{let n=r[e];t=n==null?e===`dest_geoip`&&(r.dest_country_code||r.dest_country||r.dest_isp)?JSON.stringify({country_code:r.dest_country_code||``,country:r.dest_country||``,isp:r.dest_isp||``}):``:typeof n==`object`?JSON.stringify(n):String(n)}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 Pe(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 Fe(e,t,n,r){let i=e=>e.replace(/[:*?"<>|]/g,`-`),a=i($(t)),o=i($(n)),s=i(r.toString());return`query_logs_${e}_${a}_${o}${s?`_${s}`:``}.csv`}function Ie({profileId:e,range:t,customRange:n,statusFilter:r,accessPointIdFilter:i,destCountryFilter:a,ispFilter:o,searchQuery:s,toasterRef:c}){let{t:l}=h(),[u,d]=(0,X.useState)(!1);return{exporting:u,handleExportLogs:async()=>{d(!0);try{let{since:u,until:d}=we(t,n),f=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);f.set(`start`,String(e)),f.set(`end`,String(t))}r&&f.set(`status`,r),i&&f.set(`access_point_id`,i),a&&f.set(`dest_country`,a),o&&f.set(`isp`,o),s&&f.set(`search`,s);let p=[],m=!1;try{if(await G.init()){let t=await G.queryLogs({profileId:e,search:s.trim()||void 0,action:r||void 0,accessPointId:i||void 0,destCountry:a||void 0,isp:o||void 0,since:u,until:d,limit:1e5});t&&Array.isArray(t.rows)&&t.rows.length>0&&(p=t.rows)}}catch(e){console.warn(`[LogExport] Local SQLite query failed or unavailable, falling back to server:`,e)}if(!p||p.length===0){m=!0;let{exportProfileLogs:t}=await v(async()=>{let{exportProfileLogs:e}=await import(`./services-BF0oUgkb.js`);return{exportProfileLogs:e}},__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10])),n=await t(e,f.toString());n&&Array.isArray(n)&&(p=n)}if(!p||p.length===0){c?.current?.show({message:l(`logs.noResults`,`No logs found to export`),intent:E.WARNING});return}if(p.some(e=>(e.encrypt_version??(e.encrypted_payload?1:0))>0)){if(!R.isProfileUnlocked(e))try{await R.unlockProfile(e)}catch(e){console.warn(`[LogExport] Auto-unlock attempt failed or was cancelled:`,e)}p=await R.decryptLogsBatch(e,p),p.some(e=>(e.encrypt_version??(e.encrypted_payload?1:0))>0||e.domain===`[Encrypted]`)&&c?.current?.show({message:l(`logs.e2eeLockedExportWarning`,`部分日志处于加密状态且未解锁,导出的数据可能包含未解密内容。`),intent:E.WARNING,icon:`lock`})}m&&p.length>0&&G.batchInsertLogs(e,p).catch(e=>{console.warn(`[LogExport] Failed to cache exported logs into local SQLite:`,e)}),Pe(Ne(p),Fe(e,p[0].timestamp,p[p.length-1].timestamp,f)),c?.current?.show({message:l(`logs.exportSuccess`,`Logs exported successfully`),intent:E.SUCCESS})}catch(e){console.error(`Failed to export logs`,e),c?.current?.show({message:l(`logs.exportError`,`Failed to export logs`),intent:E.DANGER})}finally{d(!1)}}}}function Le({profileId:e,toasterRef:t}){let[n,r]=(0,X.useState)(!1),i=Se(e),a=je({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});Me({profileId:e,realtimeRefresh:n,range:i.range,searchQuery:i.searchQuery,scrollContainerRef:a.scrollContainerRef,isFetchingRef:a.isFetchingRef,fetchLogs:a.fetchLogs,logsRef:a.logsRef});let o=Ie({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}}const Re=({profileId:e,onQuickAction:t,toasterRef:n})=>{let r=te(),[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:w,setSearchQuery:T,logs:E,loading:D,loadingMore:O,syncing:k,hasMore:A,stats:j,logRetentionDays:M,prevLatestTimestamp:N,scrollContainerRef:P,lastLogElementRef:F,fetchLogs:I,exporting:L,handleExportLogs:R}=Le({profileId:e,toasterRef:n}),{isE2eeEnabled:z,isE2eeUnlocked:ee,unlocking:B,recoveryDialogOpen:V,setRecoveryDialogOpen:H,recoveryKeyInput:U,setRecoveryKeyInput:W,recoveryError:G,setRecoveryError:K,rotatedKey:q,setRotatedKey:J,copiedKey:Y,handleCopyRotatedKey:oe,handleUnlockPasskey:se,handleUnlockRecoveryKey:ce}=ae({profileId:e,range:u,fetchLogs:I,toasterRef:n}),le=new Date().toLocaleString(`sv-SE`).replace(` `,`T`).slice(0,16);return D&&E.length===0?(0,Z.jsx)(`div`,{className:`h-full flex items-center justify-center`,children:(0,Z.jsx)(C,{})}):(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)(fe,{profileId:e,range:u,setRange:d,customRange:f,setCustomRange:p,nowStr:le,fetchLogs:I,isMobile:r,realtimeRefresh:c,setRealtimeRefresh:l,statusFilter:m,setStatusFilter:h,accessPointIdFilter:g,setAccessPointIdFilter:_,accessPoints:v,destCountryFilter:y,setDestCountryFilter:b,ispFilter:x,setIspFilter:S,searchQuery:w,setSearchQuery:T,stats:j,logRetentionDays:M,onExport:R,exporting:L,loading:D,syncing:k}),z&&!ee&&(0,Z.jsx)(ne,{isMobile:r,unlocking:B,onUnlockPasskey:se,onOpenRecoveryDialog:()=>{K(``),W(``),H(!0)}}),(0,Z.jsx)(he,{logs:E,loading:D,loadingMore:O,hasMore:A,realtimeRefresh:c,isMobile:r,searchQuery:w,scrollContainerRef:P,lastLogElementRef:F,prevLatestTimestamp:N,setSelectedLog:a,setIsDrawerOpen:s,logRetentionDays:M}),(0,Z.jsx)(xe,{isDrawerOpen:o,setIsDrawerOpen:s,selectedLog:i,profileId:e,isMobile:r,onQuickAction:t}),(0,Z.jsx)(ie,{isOpen:V,onClose:()=>H(!1),recoveryKeyInput:U,setRecoveryKeyInput:W,recoveryError:G,unlocking:B,onSubmit:ce}),(0,Z.jsx)(re,{rotatedKey:q,onClose:()=>J(null),copiedKey:Y,onCopyKey:oe})]})};export{Re as LogsView};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{i as e}from"./rolldown-runtime-C4Xdq4VV.js";import{$ as t,At as n,O as r,P as i,U as a,X as o,bt as s,ct as c,it as l,lt as u,mt as d,nn as f,rt as p,ut as m,v as h,w as g,y as _}from"./vendor-react-DYK5a2J9.js";import{S as v,b as y}from"./vendor-icons-other-BTYC6Wvz.js";import"./vendor-i18next-DlmslyBB.js";import{B as b,D as x,E as S,H as C,M as w,N as T,P as E,S as D,T as O,V as k,_ as A,d as j,f as M,h as N,p as P,r as F,v as I,w as L,x as R}from"./vendor-ui-core-C4974KNo.js";import"./vendor-utils-Bab4qB3W.js";import{G as z,Ot as B,Tt as ee,_t as V,bt as H,c as U,mt as W,pt as G,q as K,w as q}from"./index-DEIEgGUw.js";import{t as J}from"./async-R_IFRE5c.js";var Y=e(v(),1),X=e(y(),1);const Z=({profile:e,isEditingName:t,setIsEditingName:n,editName:r,setEditName:i,updateProfileName:o,exportProfile:c})=>{let{t:l}=f(),[d,p]=(0,Y.useState)(!1);return(0,X.jsxs)(`div`,{className:`mb-6 flex flex-col md:flex-row justify-between items-start md:items-center gap-4`,children:[(0,X.jsxs)(`div`,{className:`flex flex-col justify-start`,children:[t?(0,X.jsxs)(`div`,{className:`flex items-center gap-2 mb-1`,children:[(0,X.jsx)(I,{content:l(`common.profileNameFormatTip`,`Profile Name tip: 1-30 characters, duplicates not allowed`),isOpen:d,position:b.TOP,intent:k.PRIMARY,className:`flex-1`,children:(0,X.jsx)(`div`,{className:`w-full block`,children:(0,X.jsx)(M,{value:r,onChange:e=>i(e.target.value),onFocus:()=>p(!0),onBlur:()=>p(!1),autoFocus:!0,onKeyDown:t=>{t.key===`Enter`&&o(),t.key===`Escape`&&(n(!1),i(e?.name||``))}})})}),(0,X.jsx)(T,{icon:(0,X.jsx)(s,{size:16}),intent:k.SUCCESS,minimal:!0,onClick:o,disabled:!U.test(r)}),(0,X.jsx)(T,{icon:(0,X.jsx)(_,{size:16}),minimal:!0,onClick:()=>{n(!1),i(e?.name||``)}})]}):(0,X.jsxs)(`div`,{className:`group flex items-center gap-2 mb-1 cursor-pointer`,onClick:()=>n(!0),children:[(0,X.jsx)(`h2`,{className:`bp6-heading mb-0`,children:e?.name}),(0,X.jsx)(T,{icon:(0,X.jsx)(a,{size:14}),minimal:!0,className:`opacity-30 group-hover:opacity-100 transition-opacity`})]}),(0,X.jsx)(`p`,{className:`bp6-text-muted`,children:l(`settings.subtitle`)})]}),(0,X.jsx)(`div`,{className:`flex gap-2 items-center`,children:(0,X.jsx)(T,{size:`large`,icon:(0,X.jsx)(u,{size:18}),text:l(`settings.export`,`导出配置`),onClick:c})})]})},Q=()=>{let{t:e}=f(),[t,n]=(0,Y.useState)([]);return(0,Y.useEffect)(()=>{K().then(t=>{t&&Array.isArray(t)&&n(t.map(t=>({label:e(t.label),url:t.url})))}).catch(e=>console.warn(`Failed to fetch preset upstreams from API`,e))},[e]),t},te=(e,t)=>{let{t:n}=f();return(0,Y.useMemo)(()=>{let e=t>0?t:30,r=n(`settings.retentionMaxSuffix`,`(最长)`),i=[{label:n(`settings.retentionDisabled`,`关闭 (隐私需要)`),value:0},{label:n(`settings.retention10m`,`10 分钟`),value:.007},{label:n(`settings.retention1h`,`1 小时`),value:.0416},{label:n(`settings.retention24h`,`24 小时`),value:1},{label:n(`settings.retention7d`,`7 天`),value:7},{label:n(`settings.retention30d`,`30 天`),value:30},{label:n(`settings.retention90d`,`90 天`),value:90},{label:n(`settings.retention180d`,`180 天`),value:180},{label:n(`settings.retention360d`,`360 天`),value:360}],a=i.filter(t=>t.value<=e);return e>0&&!a.some(t=>t.value===e)&&(a.push({label:`${e} ${n(`settings.daysUnit`,`天`)}`,value:e}),a.sort((e,t)=>e.value-t.value)),a.length===0?[i[0]]:a.map(t=>t.value===e&&t.value>0?{...t,label:`${t.label} ${r}`}:t)},[n,t])},ne=({settings:e,setSettings:t})=>{let{t:n}=f(),r=(0,X.jsx)(S,{className:`min-w-96`,children:Q().map((n,r)=>(0,X.jsx)(L,{text:n.label,onClick:()=>t({...e,upstream:[n.url]}),labelElement:(0,X.jsx)(`div`,{className:`flex flex-col items-end text-right`,children:(0,X.jsx)(`span`,{className:`text-[9px] opacity-85 max-w-64 truncate`,title:n.url,children:n.url})})},r))});return(0,X.jsxs)(R,{elevation:C.ONE,className:`dark:bg-gray-900 dark:border-gray-800`,children:[(0,X.jsxs)(w,{className:`flex items-center gap-2 mb-4 font-bold`,children:[(0,X.jsx)(i,{size:18,className:`text-blue-500`}),` `,n(`settings.upstreamTitle`)]}),(0,X.jsx)(P,{label:`DoH (https://) / DoT (tls://) / DNS Stamp (sdns://) / ${n(`settings.classicDns`)}`,children:(0,X.jsx)(M,{fill:!0,placeholder:`https://... | tls://... | sdns://... | 1.1.1.1`,value:e.upstream?.[0]||``,onChange:n=>t({...e,upstream:[n.target.value]}),onFocus:e=>e.target.select(),rightElement:(0,X.jsx)(O,{content:r,placement:`bottom-end`,animation:`minimal`,arrow:!1,children:(0,X.jsx)(T,{variant:`minimal`,icon:`chevron-down`})})})}),(0,X.jsx)(`p`,{className:`text-xs opacity-60`,children:n(`settings.upstreamDesc`)})]})},re=({settings:e,setSettings:t})=>{let{t:n}=f();return(0,X.jsxs)(R,{elevation:C.ONE,className:`dark:bg-gray-900 dark:border-gray-800`,children:[(0,X.jsxs)(w,{className:`flex items-center gap-2 mb-4 font-bold`,children:[(0,X.jsx)(r,{size:18,className:`text-green-500`}),` `,n(`settings.defaultPolicyTitle`)]}),(0,X.jsxs)(`div`,{className:`space-y-4`,children:[(0,X.jsx)(P,{label:n(`settings.onNoMatch`),children:(0,X.jsxs)(j,{fill:!0,value:e.default_policy,onChange:n=>t({...e,default_policy:n.target.value}),children:[(0,X.jsx)(`option`,{value:`ALLOW`,children:n(`settings.allowAll`)}),(0,X.jsx)(`option`,{value:`BLOCK`,children:n(`settings.blockAll`)})]})}),(0,X.jsx)(A,{}),(0,X.jsx)(P,{label:n(`settings.blockModeTitle`),helperText:n(`settings.blockModeDesc`),children:(0,X.jsxs)(j,{fill:!0,value:e.block_mode||`NULL_IP`,onChange:n=>t({...e,block_mode:n.target.value}),children:[(0,X.jsxs)(`option`,{value:`NULL_IP`,children:[`0.0.0.0 / :: (`,n(`settings.default`),`)`]}),(0,X.jsxs)(`option`,{value:`NXDOMAIN`,children:[`NXDOMAIN (`,n(`settings.NXDOMAIN`),`)`]}),(0,X.jsxs)(`option`,{value:`NODATA`,children:[`NODATA (`,n(`settings.NODATA`),`)`]}),(0,X.jsx)(`option`,{value:`CUSTOM_IP`,children:n(`settings.customIP`)})]})}),e.block_mode===`CUSTOM_IP`&&(0,X.jsxs)(`div`,{className:`space-y-2 animate-in fade-in slide-in-from-top-1`,children:[(0,X.jsx)(M,{placeholder:`IPv4: 127.0.0.1`,value:e.custom_block_ipv4||``,onChange:n=>t({...e,custom_block_ipv4:n.target.value})}),(0,X.jsx)(M,{placeholder:`IPv6: ::1`,value:e.custom_block_ipv6||``,onChange:n=>t({...e,custom_block_ipv6:n.target.value})})]})]})]})},ie=({settings:e,setSettings:t,isAdmin:n,maxRetentionDays:r})=>{let{t:i}=f(),a=te(n,r);Y.useEffect(()=>{if(r>0&&e.log_retention_days>r&&a.length>0){let n=a[a.length-1];n&&e.log_retention_days!==n.value&&t({...e,log_retention_days:n.value})}},[r,e.log_retention_days,a,t]);let o=e.log_retention_days===0;return(0,X.jsxs)(R,{elevation:C.ONE,className:`dark:bg-gray-900 dark:border-gray-800`,children:[(0,X.jsxs)(w,{className:`flex items-center gap-2 mb-4 font-bold`,children:[(0,X.jsx)(d,{size:18,className:`text-purple-500`}),` `,i(`settings.logRetentionTitle`)]}),(0,X.jsxs)(`div`,{className:`space-y-4`,children:[(0,X.jsx)(P,{label:i(`settings.retentionDuration`),children:(0,X.jsx)(j,{fill:!0,value:e.log_retention_days,onChange:n=>t({...e,log_retention_days:parseFloat(n.target.value)}),children:a.map(e=>(0,X.jsx)(`option`,{value:e.value,children:e.label},e.value))})}),(0,X.jsx)(`p`,{className:`text-xs opacity-60`,children:o?i(`settings.retentionDisabledDesc`,`已关闭日志记录。系统将不会记录任何 DNS 查询日志并立即清空历史日志。`):i(`settings.retentionDesc`)}),(0,X.jsxs)(`div`,{className:`pt-3 border-t border-gray-100 dark:border-gray-800/80`,children:[(0,X.jsx)(N,{label:i(`settings.skipLogOnPass`,`不记录放行记录`),checked:!o&&!!e.skip_log_on_pass,disabled:o,onChange:n=>t({...e,skip_log_on_pass:n.currentTarget.checked})}),(0,X.jsx)(`p`,{className:`text-xs opacity-60 mt-1`,children:i(`settings.skipLogOnPassDesc`,`启用后不记录正常放行的 DNS 查询,仅记录被拦截、重定向或解析失败的记录。可大幅减少存储占用与写操作。`)})]})]})]})},ae=({profileId:e,toasterRef:t})=>{let{t:n}=f(),[r,i]=(0,Y.useState)(()=>q.getLocalRetentionDays()),[a,o]=(0,Y.useState)(!1),[s,c]=(0,Y.useState)(null),[l,u]=(0,Y.useState)(!1),[d,h]=(0,Y.useState)(!1),_=(0,Y.useCallback)(async()=>{try{await q.init();let t=await q.getStorageInfo();o(t?.isOpfs??q.getIsOpfs());let n=t.profileStats.find(t=>t.profile_id===e);c(n?n.count:0)}catch(e){console.error(`[LocalRetentionCard] Failed to load storage info:`,e),o(q.getIsOpfs()),c(0)}},[e]);(0,Y.useEffect)(()=>{_()},[_]);let v=e=>{i(e),q.setLocalRetentionDays(e),_()};return(0,X.jsxs)(R,{elevation:C.ONE,className:`dark:bg-gray-900 dark:border-gray-800`,children:[(0,X.jsxs)(w,{className:`flex items-center gap-2 mb-4 font-bold`,children:[(0,X.jsx)(m,{size:18,className:`text-cyan-500`}),` `,n(`settings.localRetentionTitle`,`本地存储与留存`)]}),(0,X.jsxs)(`div`,{className:`space-y-4`,children:[(0,X.jsx)(P,{label:n(`settings.localRetentionDuration`,`本地保留时长`),children:(0,X.jsxs)(j,{fill:!0,value:r,onChange:e=>v(parseInt(e.target.value,10)),children:[(0,X.jsx)(`option`,{value:30,children:n(`settings.localRetention30d`,`30 天`)}),(0,X.jsx)(`option`,{value:90,children:n(`settings.localRetention90d`,`90 天 (推荐)`)}),(0,X.jsx)(`option`,{value:180,children:n(`settings.localRetention180d`,`180 天`)}),(0,X.jsx)(`option`,{value:365,children:n(`settings.localRetention365d`,`365 天 (1 年)`)}),(0,X.jsx)(`option`,{value:0,children:n(`settings.localRetentionUnlimited`,`永久保留 (直到手动清除)`)})]})}),(0,X.jsx)(`p`,{className:`text-xs opacity-60`,children:n(`settings.localRetentionDesc`,`日志将持久化保存在当前浏览器本地的 SQLite 数据库 (OPFS) 中,提供秒级本地搜索并节省云端存储费用。超出此时长的本地日志将自动清除。`)}),(0,X.jsxs)(`div`,{className:`pt-3 border-t border-gray-100 dark:border-gray-800/80 space-y-3`,children:[(0,X.jsxs)(`div`,{className:`flex items-center justify-between text-xs`,children:[(0,X.jsxs)(`span`,{className:`flex items-center gap-1.5 opacity-70`,children:[(0,X.jsx)(p,{size:14}),n(`settings.localEngineStorage`,`存储引擎`),`:`]}),(0,X.jsx)(F,{minimal:!0,intent:a?k.SUCCESS:k.WARNING,className:`text-[11px]`,children:a?n(`settings.localEngineOpfs`,`OPFS 本地持久化`):n(`settings.localEngineMemory`,`内存临时存储 (无痕/私密模式)`)})]}),(0,X.jsxs)(`div`,{className:`flex items-center justify-between text-xs`,children:[(0,X.jsxs)(`span`,{className:`opacity-70`,children:[n(`settings.localCachedCount`,`本地已缓存日志`),`:`]}),(0,X.jsx)(`span`,{className:`font-mono font-medium`,children:s===null?`...`:n(`settings.localCachedCountUnit`,`{{count}} 条记录`,{count:s})})]}),(0,X.jsx)(`div`,{className:`pt-1 flex justify-end`,children:(0,X.jsx)(T,{minimal:!0,small:!0,intent:k.DANGER,icon:(0,X.jsx)(g,{size:13}),text:n(`settings.clearLocalData`,`清空本地日志`),disabled:s===0||s===null||d,onClick:()=>u(!0)})})]})]}),(0,X.jsx)(x,{isOpen:l,confirmButtonText:n(`common.confirm`,`确认清空`),cancelButtonText:n(`common.cancel`,`取消`),intent:k.DANGER,icon:`trash`,onConfirm:async()=>{h(!0);try{await q.clearProfile(e),c(0),t?.current?.show({message:n(`settings.clearLocalDataSuccess`,`本地日志已成功清空`),intent:k.SUCCESS,icon:`tick`})}catch(e){console.error(`[LocalRetentionCard] Failed to clear local profile logs:`,e),t?.current?.show({message:n(`settings.clearLocalDataError`,`清空本地日志失败`),intent:k.DANGER,icon:`error`})}finally{h(!1),u(!1)}},onCancel:()=>u(!1),loading:d,children:(0,X.jsx)(`p`,{children:n(`settings.clearLocalDataConfirm`,`确定要清空此配置在本地保存的所有日志吗?(云端日志不受影响)`)})})]})},oe=({settings:e,setSettings:t})=>{let{t:n}=f();return(0,X.jsxs)(R,{elevation:C.ONE,className:`dark:bg-gray-900 dark:border-gray-800`,children:[(0,X.jsxs)(w,{className:`flex items-center gap-2 mb-3 font-bold`,children:[(0,X.jsx)(l,{size:18,className:`text-orange-500`}),` `,n(`settings.ecsTitle`)]}),(0,X.jsxs)(`div`,{className:`space-y-4`,children:[(0,X.jsx)(N,{label:n(`settings.sendEcs`),checked:e.ecs.enabled,onChange:n=>t({...e,ecs:{...e.ecs,enabled:n.currentTarget.checked}})}),(0,X.jsx)(N,{label:n(`settings.customSubnet`),disabled:!e.ecs.enabled,checked:!e.ecs.use_client_ip,onChange:n=>t({...e,ecs:{...e.ecs,use_client_ip:!n.currentTarget.checked}})}),(0,X.jsxs)(`div`,{className:`space-y-3 pt-2 border-t border-gray-100 dark:border-gray-800`,children:[(0,X.jsx)(P,{label:n(`settings.customIpv4`),labelInfo:n(`settings.ipv4Hint`),disabled:!(e.ecs.enabled&&!e.ecs.use_client_ip),children:(0,X.jsx)(M,{placeholder:`0.0.0.0/0`,value:e.ecs.ipv4_cidr||``,disabled:!(e.ecs.enabled&&!e.ecs.use_client_ip),onChange:n=>t({...e,ecs:{...e.ecs,ipv4_cidr:n.target.value}})})}),(0,X.jsx)(P,{label:n(`settings.customIpv6`),labelInfo:n(`settings.ipv6Hint`),disabled:!(e.ecs.enabled&&!e.ecs.use_client_ip),children:(0,X.jsx)(M,{placeholder:`::/0`,value:e.ecs.ipv6_cidr||``,disabled:!(e.ecs.enabled&&!e.ecs.use_client_ip),onChange:n=>t({...e,ecs:{...e.ecs,ipv6_cidr:n.target.value}})})})]}),(0,X.jsx)(`p`,{className:`text-xs opacity-60`,children:n(`settings.ecsUpstreamHint`)})]})]})};var $=[{domain:`cloudflare-ech.com`,isPreferred:!0},{domain:`crypto.cloudflare.com`,isPreferred:!1},{domain:`one.one.one.one`,isPreferred:!1},{domain:`www.cloudflare.com`,isPreferred:!1},{domain:`encryptedsni.com`,isPreferred:!1},{domain:`cdnjs.com`,isPreferred:!1}];const se=({settings:e,setSettings:n})=>{let{t:r}=f(),[i,a]=Y.useState($);Y.useEffect(()=>{z().then(e=>{Array.isArray(e)&&e.length>0&&a(e.map(e=>typeof e==`string`?{domain:e,isPreferred:e===`cloudflare-ech.com`}:{domain:e.domain,isPreferred:!!e.isPreferred}))}).catch(e=>console.warn(`Failed to fetch preset ECH fronting domains from API`,e))},[]);let o=typeof e.best_effort_ech==`boolean`?e.best_effort_ech:!!e.best_effort_ech?.enabled,s=typeof e.best_effort_ech==`object`&&e.best_effort_ech?.fronting_domain?e.best_effort_ech.fronting_domain:`cloudflare-ech.com`,l=t=>{n({...e,best_effort_ech:{enabled:t,fronting_domain:s||`cloudflare-ech.com`}})},u=t=>{n({...e,best_effort_ech:{enabled:o,fronting_domain:t}})},d=(0,X.jsx)(S,{className:`min-w-72`,children:i.map(e=>(0,X.jsx)(L,{text:e.domain,onClick:()=>u(e.domain),labelElement:e.isPreferred?(0,X.jsx)(F,{minimal:!0,intent:k.PRIMARY,className:`text-[10px]`,children:r(`settings.echPreferred`,`首选`)}):void 0},e.domain))});return(0,X.jsxs)(R,{elevation:C.ONE,className:`dark:bg-gray-900 dark:border-gray-800`,children:[(0,X.jsxs)(`div`,{className:`flex items-center justify-between mb-3`,children:[(0,X.jsxs)(w,{className:`flex items-center gap-2 m-0 font-bold text-purple-600 dark:text-purple-400`,children:[(0,X.jsx)(t,{size:18}),` `,r(`settings.echTitle`)]}),(0,X.jsx)(O,{placement:`bottom-end`,usePortal:!0,content:(0,X.jsxs)(`div`,{className:`p-4 max-w-sm`,children:[(0,X.jsx)(w,{children:r(`settings.whatIsEch`,`何为 ECH (Encrypted Client Hello)?`)}),(0,X.jsx)(`p`,{className:`text-sm mb-2`,children:r(`settings.echHelpDesc`)}),(0,X.jsxs)(`ul`,{className:`list-disc list-inside text-sm opacity-80 mb-3 space-y-1`,children:[(0,X.jsx)(`li`,{children:r(`settings.echHelpBenefit1`)}),(0,X.jsx)(`li`,{children:r(`settings.echHelpBenefit2`)})]}),(0,X.jsx)(`div`,{className:`text-xs border-t border-gray-100 dark:border-gray-700 pt-2`,children:(0,X.jsxs)(`a`,{href:`https://en.wikipedia.org/wiki/Encrypted_Client_Hello`,target:`_blank`,rel:`noreferrer`,className:`flex items-center gap-1 text-blue-500 hover:underline`,children:[(0,X.jsx)(c,{size:10}),` `,r(`setup.learnMore`,`了解更多`)]})})]}),children:(0,X.jsx)(T,{icon:`help`,variant:`minimal`,intent:k.NONE})})]}),(0,X.jsxs)(`div`,{className:`space-y-4`,children:[(0,X.jsx)(N,{label:r(`settings.enableEch`,`启用重写 ECH`),checked:o,onChange:e=>l(e.currentTarget.checked)}),(0,X.jsx)(`p`,{className:`text-xs opacity-60 leading-relaxed`,children:r(`settings.echDesc`,`针对由 Cloudflare 代理的域名,当查询 HTTPS (Type 65) 或 SVCB (Type 64) 记录且上游未配置 ECH 时,自动重写注入 ECH 参数以保护 SNI 隐私。`)}),o&&(0,X.jsx)(`div`,{className:`space-y-3 pt-3 border-t border-gray-100 dark:border-gray-800`,children:(0,X.jsx)(P,{label:r(`settings.echFrontingTitle`,`表层 SNI (ECH Fronting)`),labelInfo:(0,X.jsx)(`span`,{className:`text-xs opacity-60`,children:r(`settings.echFrontingDesc`,`TLS 握手外层可见的伪装域名`)}),children:(0,X.jsx)(M,{fill:!0,placeholder:r(`settings.echFrontingCustomPlaceholder`,`输入自定义表层域名,例如 crypto.cloudflare.com`),value:s,onChange:e=>u(e.target.value),onFocus:e=>e.target.select(),className:`font-mono text-sm`,rightElement:(0,X.jsx)(O,{content:d,placement:`bottom-end`,animation:`minimal`,arrow:!1,children:(0,X.jsx)(T,{variant:`minimal`,icon:`chevron-down`})})})})})]})]})},ce=({testInput:e,setTestInput:t,handleDnsTest:r,testing:i,testResult:a})=>{let{t:s}=f();return(0,X.jsxs)(R,{elevation:C.TWO,className:`dark:bg-gray-900 border-t-2 border-blue-500`,children:[(0,X.jsxs)(w,{className:`flex items-center gap-2 mb-6 font-bold`,children:[(0,X.jsx)(h,{size:20,className:`text-yellow-500 fill-yellow-500`}),` `,s(`settings.testToolTitle`)]}),(0,X.jsxs)(`div`,{className:`flex flex-col space-y-6`,children:[(0,X.jsx)(P,{label:s(`settings.testDomain`),className:`mb-0`,children:(0,X.jsx)(M,{fill:!0,large:!0,placeholder:s(`settings.domainPlaceholder`),value:e.domain,onChange:n=>t({...e,domain:n.target.value}),onKeyDown:e=>e.key===`Enter`&&r()})}),(0,X.jsxs)(`div`,{className:`flex justify-end gap-4 items-end`,children:[(0,X.jsx)(P,{label:s(`settings.recordType`),className:`w-32 mb-0`,children:(0,X.jsxs)(j,{fill:!0,large:!0,value:e.type,onChange:n=>t({...e,type:n.target.value}),children:[(0,X.jsx)(`option`,{value:`A`,children:`A`}),(0,X.jsx)(`option`,{value:`AAAA`,children:`AAAA`}),(0,X.jsx)(`option`,{value:`CNAME`,children:`CNAME`}),(0,X.jsx)(`option`,{value:`TXT`,children:`TXT`})]})}),(0,X.jsx)(P,{label:`\xA0`,className:`mb-0`,children:(0,X.jsx)(T,{size:`large`,intent:k.PRIMARY,icon:`search`,text:s(`settings.runTest`),onClick:r,loading:i})})]}),a&&(0,X.jsxs)(`div`,{className:`bg-gray-50 dark:bg-gray-800/50 p-6 rounded-xl border border-gray-100 dark:border-gray-800 space-y-6 animate-in fade-in slide-in-from-top-4`,children:[(0,X.jsxs)(`div`,{className:`flex flex-wrap gap-4 items-center`,children:[(0,X.jsx)(F,{large:!0,round:!0,intent:a.action===`PASS`?k.SUCCESS:a.action===`BLOCK`?k.DANGER:k.WARNING,className:`px-4 font-bold`,children:a.action}),(0,X.jsxs)(`div`,{className:`flex flex-col`,children:[(0,X.jsx)(`span`,{className:`text-[10px] uppercase font-bold opacity-40`,children:s(`settings.hitRule`)}),(0,X.jsx)(`span`,{className:`text-sm font-bold`,children:a.reason||s(`settings.defaultAllow`)})]}),(0,X.jsxs)(`div`,{className:`flex flex-col border-l border-gray-200 dark:border-gray-700 pl-4`,children:[(0,X.jsx)(`span`,{className:`text-[10px] uppercase font-bold opacity-40`,children:s(`settings.parseLatency`)}),(0,X.jsx)(`span`,{className:`text-sm font-mono font-bold`,children:a.latency?`${a.latency}ms`:`-`})]}),a.timings&&(0,X.jsx)(`div`,{className:`flex flex-wrap gap-x-4 gap-y-1 border-l border-gray-200 dark:border-gray-700 pl-4 max-w-md`,children:Object.entries(a.timings).map(([e,t])=>(0,X.jsxs)(`div`,{className:`flex gap-1 items-baseline`,children:[(0,X.jsxs)(`span`,{className:`text-[9px] opacity-40 uppercase font-mono`,children:[e,`:`]}),(0,X.jsxs)(`span`,{className:`text-[10px] font-mono font-bold`,children:[t,`ms`]})]},e))}),(0,X.jsx)(A,{}),(0,X.jsxs)(`div`,{className:`flex items-center gap-2 bg-white dark:bg-gray-900 px-3 py-1.5 rounded-lg shadow-sm border border-gray-100 dark:border-gray-800`,children:[(0,X.jsx)(o,{size:14,className:`text-red-500`}),(0,X.jsxs)(`div`,{className:`flex flex-col`,children:[(0,X.jsx)(`span`,{className:`text-[10px] uppercase font-bold opacity-40 leading-none`,children:s(`settings.sourceIp`)}),(0,X.jsxs)(`span`,{className:`text-xs font-mono`,children:[a.client_ip,` (`,a.geo_country,`)`]})]})]})]}),(0,X.jsxs)(`div`,{className:`space-y-3`,children:[(0,X.jsxs)(`div`,{className:`text-[10px] uppercase font-bold opacity-40 flex items-center gap-1`,children:[(0,X.jsx)(n,{size:10}),` `,s(`settings.answerSection`)]}),(0,X.jsx)(`div`,{className:`font-mono text-sm leading-relaxed bg-white dark:bg-gray-900 p-4 rounded-xl border border-gray-100 dark:border-gray-800 shadow-inner`,children:a.answers&&a.answers.length>0?a.answers.map((e,t)=>(0,X.jsxs)(`div`,{className:`flex gap-4 py-1 border-b border-gray-50 dark:border-gray-800 last:border-0 hover:bg-blue-50/50 dark:hover:bg-blue-900/10 transition-colors px-2`,children:[(0,X.jsx)(`span`,{className:`w-16 font-bold text-blue-500`,children:e.type}),(0,X.jsx)(`span`,{className:`flex-1 dark:text-gray-300`,children:e.data}),(0,X.jsxs)(`span`,{className:`text-[10px] opacity-30 italic`,children:[`TTL: `,e.ttl,`s`]})]},t)):(0,X.jsx)(`div`,{className:`p-4 opacity-40 italic text-center`,children:s(`settings.noRecordsReturned`)})})]}),a.diagnostics&&(0,X.jsx)(D,{minimal:!0,intent:a.action===`FAIL`?k.DANGER:k.NONE,className:`text-xs font-mono`,children:(0,X.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,X.jsxs)(`div`,{className:`flex justify-between items-center`,children:[(0,X.jsx)(`span`,{className:`font-bold uppercase tracking-wider`,children:s(`settings.diagnostics`)}),(0,X.jsx)(`span`,{className:`font-bold`,children:a.action===`FAIL`?a.diagnostics.status>0?`HTTP ${a.diagnostics.status}${a.diagnostics.status_text?` (${a.diagnostics.status_text})`:``}`:`Network / Connection Error`:a.diagnostics.method===`POST`||a.diagnostics.method===`GET`?`HTTP ${a.diagnostics.status}${a.diagnostics.status_text?` (${a.diagnostics.status_text})`:``}`:`Connected (OK)`})]}),(0,X.jsxs)(`div`,{className:`flex items-center gap-2 text-xs opacity-80`,children:[(0,X.jsx)(`span`,{className:`px-1.5 py-0.5 bg-gray-200 dark:bg-gray-700 rounded text-[10px] font-bold`,children:a.diagnostics.method}),(0,X.jsx)(`span`,{className:`break-all`,children:a.diagnostics.upstream_url})]}),a.diagnostics.cf_ray&&(0,X.jsxs)(`div`,{className:`text-[11px] opacity-75`,children:[`CF-Ray: `,(0,X.jsx)(`span`,{className:`font-bold`,children:a.diagnostics.cf_ray})]}),a.diagnostics.error_detail&&a.action===`FAIL`&&(0,X.jsxs)(`div`,{className:`p-2 bg-red-50 dark:bg-red-950/40 rounded border border-red-200 dark:border-red-900/50 text-red-700 dark:text-red-300 break-words`,children:[(0,X.jsxs)(`div`,{className:`font-bold mb-0.5`,children:[s(`settings.errorDetail`),`:`]}),(0,X.jsx)(`div`,{children:a.diagnostics.error_detail})]}),a.diagnostics.response_body&&(0,X.jsxs)(`div`,{className:`p-2 bg-gray-100 dark:bg-gray-900 rounded border border-gray-200 dark:border-gray-700 text-gray-700 dark:text-gray-300 break-words text-[11px]`,children:[(0,X.jsxs)(`div`,{className:`font-bold mb-0.5 opacity-60`,children:[s(`settings.upstreamResponse`),`:`]}),(0,X.jsx)(`div`,{className:`line-clamp-3`,children:a.diagnostics.response_body})]})]})})]})]})]})},le=({profileId:e,toasterRef:t,currentUser:n,onSavingChange:r})=>{let[i,a]=(0,Y.useState)(null),[o,s]=(0,Y.useState)(null),[c,l]=(0,Y.useState)(!0),[u,d]=(0,Y.useState)(!1),{t:p}=f();(0,Y.useEffect)(()=>(r?.(u),()=>{r?.(!1)}),[u,r]);let m=(0,Y.useRef)(!0),h=(0,Y.useRef)(null),g=(0,Y.useRef)(null),_=(0,Y.useRef)(0),v=e=>typeof structuredClone==`function`?structuredClone(e):JSON.parse(JSON.stringify(e)),[y,b]=(0,Y.useState)(!1),[x,S]=(0,Y.useState)(``),[C,w]=(0,Y.useState)({domain:`o-o.myaddr.l.google.com`,type:`TXT`}),[T,D]=(0,Y.useState)(null),[O,A]=(0,Y.useState)(!1);(0,Y.useEffect)(()=>{m.current=!0,h.current&&=(clearTimeout(h.current),null),(async()=>{l(!0);try{let t=await G(e);a(t),S(t.name);let n=JSON.parse(t.settings);return g.current=v(n),s(n),i}catch(e){console.error(e)}finally{l(!1)}})()},[e]),(0,Y.useEffect)(()=>{if(!c&&o&&m.current){let e=setTimeout(()=>{m.current=!1,o&&(g.current=v(o))},500);return()=>clearTimeout(e)}},[c,o]),(0,Y.useEffect)(()=>()=>{h.current&&clearTimeout(h.current)},[]);let j=async()=>{if(!x||x===i?.name){b(!1);return}let n=i?.name||``;d(!0);try{await J(H(e,x),1e4),a(e=>e?{...e,name:x}:null),b(!1),t?.current?.show({message:p(`common.saveSuccess`,`保存成功`),intent:k.SUCCESS,icon:`tick`})}catch(e){console.error(e),S(n),b(!1);let r=e.message,i=r;r===`The profile name already exists`?i=p(`common.profileNameExists`,`The profile name already exists`):r===`Invalid Profile Name format`&&(i=p(`common.profileNameFormatError`,`Invalid Profile Name format`)),t?.current?.show({message:i||p(`common.saveFailed`,`保存失败`),intent:k.DANGER,icon:`error`})}finally{d(!1)}},M=(0,Y.useCallback)(async n=>{if(!n)return;let r=++_.current;d(!0);try{await J(B(e,n),1e4),r===_.current&&(g.current=v(n),t?.current?.show({message:p(`common.saveSuccess`,`保存成功`),intent:k.SUCCESS,icon:`tick`}))}catch(e){console.error(e),r===_.current&&(h.current&&=(clearTimeout(h.current),null),g.current&&s(v(g.current)),t?.current?.show({message:p(`common.saveFailed`,`保存失败`),intent:k.DANGER,icon:`error`}))}finally{r===_.current&&d(!1)}},[e,t,p]),N=(0,Y.useCallback)(e=>{h.current&&clearTimeout(h.current),h.current=setTimeout(()=>{M(e)},600)},[M]),P=(0,Y.useCallback)(e=>{s(e),m.current||N(e)},[N]);return c||!o?(0,X.jsx)(`div`,{className:`p-20 flex justify-center`,children:(0,X.jsx)(E,{})}):(0,X.jsxs)(`div`,{className:`p-0 sm:px-4 lg:px-8 max-w-5xl mx-auto space-y-8 pb-20`,children:[(0,X.jsx)(Z,{profile:i,isEditingName:y,setIsEditingName:b,editName:x,setEditName:S,updateProfileName:j,exportProfile:async()=>{if(!(!i||!o))try{let[n,r]=await Promise.all([V(e).catch(()=>[]),W(e).catch(()=>[])]),a=new Set,s=(n||[]).filter(e=>{let t=(e.pattern||``).trim().toLowerCase();return!t||a.has(t)?!1:(a.add(t),!0)}),c=new Set,l=(r||[]).filter(e=>{let t=(e.url||``).trim().toLowerCase();return!t||c.has(t)?!1:(c.add(t),!0)}).map(e=>({url:e.url,enabled:!!e.enabled})),u={version:2,name:i.name,settings:o,rules:s,filters:l,exported_at:Math.floor(Date.now()/1e3)},d=new Blob([JSON.stringify(u,null,2)],{type:`application/json`}),f=URL.createObjectURL(d),m=document.createElement(`a`);m.href=f,m.download=`dns-worker-${i.name||e}.json`,document.body.appendChild(m),m.click(),document.body.removeChild(m),URL.revokeObjectURL(f),t?.current?.show({message:p(`settings.exportSuccess`,`配置成功导出`),intent:k.SUCCESS,icon:`download`})}catch(e){console.error(e),t?.current?.show({message:p(`settings.exportError`,`导出失败`),intent:k.DANGER,icon:`error`})}}}),(0,X.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-6`,children:[(0,X.jsx)(ne,{settings:o,setSettings:P}),(0,X.jsx)(re,{settings:o,setSettings:P}),(0,X.jsx)(ie,{settings:o,setSettings:P,isAdmin:n?.role===`admin`,maxRetentionDays:n?.max_log_retention_days??(n?.role===`admin`?30:7)}),(0,X.jsx)(ae,{profileId:e,toasterRef:t}),(0,X.jsx)(oe,{settings:o,setSettings:P}),(0,X.jsx)(se,{settings:o,setSettings:P})]}),(0,X.jsx)(ce,{testInput:C,setTestInput:w,handleDnsTest:async()=>{if(C.domain){A(!0),D(null);try{D(await ee(e,C))}catch(e){console.error(e)}finally{A(!1)}}},testing:O,testResult:T})]})};export{le as SettingsView};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{i as e}from"./rolldown-runtime-C4Xdq4VV.js";import{B as t,C as n,H as r,I as i,M as a,N as o,S as s,at as c,et as l,gt as u,ht as d,nn as f,ut as p,w as m,x as h}from"./vendor-react-DYK5a2J9.js";import{S as g,b as _}from"./vendor-icons-other-BTYC6Wvz.js";import"./vendor-i18next-DlmslyBB.js";import{H as v,M as y,N as b,O as x,S,T as C,V as w,_ as T,d as E,f as D,h as O,j as k,p as A,r as j,u as M,x as N}from"./vendor-ui-core-C4974KNo.js";import{_t as P}from"./vendor-utils-Bab4qB3W.js";import{B as F,F as I,I as L,It as R,K as z,L as B,M as V,N as H,P as U,R as W,V as G,d as K,h as q,hn as J,l as ee,o as te,u as ne,z as Y}from"./index-DEIEgGUw.js";import{t as X}from"./async-R_IFRE5c.js";var Z=e(g(),1),Q=e(_(),1);const $=({users:e,currentUserId:t,onRefresh:n,registrationEnabled:r=!0,maxUsers:i,onRefreshSettings:o,onSavingChange:s,toasterRef:c})=>{let{t:l}=f(),[u,d]=(0,Z.useState)(!1),[p,g]=(0,Z.useState)(``),[_,y]=(0,Z.useState)(``),[S,C]=(0,Z.useState)(`user`),[T,P]=(0,Z.useState)(!1),[F,I]=(0,Z.useState)(!1),[L,R]=(0,Z.useState)(r),[z,B]=(0,Z.useState)(!1),U=i!=null&&i!==``?parseInt(String(i),10):0,W=U>0&&e.length>=U;(0,Z.useEffect)(()=>{R(r)},[r]);let J=async e=>{let t=L;R(e),B(!0),s?.(!0);try{await X(G({registration_enabled:String(e)}),1e4),c?.current?.show({message:l(`common.saveSuccess`,`保存成功`),intent:w.SUCCESS,icon:`tick`}),o?.()}catch(e){console.error(e),R(t),c?.current?.show({message:e.message||l(`common.saveFailed`,`保存失败`),intent:w.DANGER,icon:`error`})}finally{B(!1),s?.(!1)}},Y=async()=>{if(!ee.test(p)){alert(l(`account.formatTipUsername`));return}if(!te.test(_)){alert(l(`account.formatTipPassword`));return}P(!0);try{await V({username:p,password:await K(_,p),role:S}),d(!1),g(``),y(``),I(!1),n()}catch(e){console.error(e),alert(ne(e,l))}finally{P(!1)}},$=async e=>{if(confirm(l(`account.confirmDeleteUser`)))try{await H(e),n()}catch(e){console.error(e)}};return(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsxs)(`div`,{className:`flex flex-col sm:flex-row sm:items-center justify-between gap-3`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Q.jsx)(a,{size:20,className:`text-red-500`}),(0,Q.jsx)(k,{style:{margin:0},children:l(`account.userManagement`)}),U>0?(0,Q.jsxs)(j,{minimal:!0,intent:W?w.DANGER:w.PRIMARY,round:!0,children:[e.length,` / `,U]}):(0,Q.jsx)(j,{minimal:!0,round:!0,children:e.length})]}),(0,Q.jsxs)(`div`,{className:`flex items-center gap-4 flex-wrap`,children:[(0,Q.jsx)(O,{label:l(`account.enableRegistration`,`开放新用户注册`),checked:L,disabled:z,onChange:e=>J(e.currentTarget.checked),className:`mb-0`}),(0,Q.jsx)(b,{className:`whitespace-nowrap`,icon:(0,Q.jsx)(h,{size:16}),intent:w.SUCCESS,text:l(`account.createUser`),disabled:W,title:W?l(`auth.maxUsersReached`,`当前系统已达到用户数量上限,无法创建新用户。`):void 0,onClick:()=>d(!0)})]})]}),(0,Q.jsx)(N,{elevation:v.ONE,className:`p-0 overflow-hidden overflow-x-auto`,children:(0,Q.jsxs)(M,{interactive:!0,striped:!0,className:`w-full whitespace-nowrap`,children:[(0,Q.jsx)(`thead`,{children:(0,Q.jsxs)(`tr`,{children:[(0,Q.jsx)(`th`,{className:`whitespace-nowrap`,children:l(`account.username`)}),(0,Q.jsx)(`th`,{className:`whitespace-nowrap`,children:l(`account.role`)}),(0,Q.jsx)(`th`,{className:`whitespace-nowrap`,children:`MFA`}),(0,Q.jsx)(`th`,{className:`whitespace-nowrap`,children:`ID`}),(0,Q.jsx)(`th`,{className:`whitespace-nowrap`,children:l(`account.createdAt`)}),(0,Q.jsx)(`th`,{className:`whitespace-nowrap`,children:l(`account.lastActive`)}),(0,Q.jsx)(`th`,{className:`whitespace-nowrap`,children:l(`account.lastResolve`)}),(0,Q.jsx)(`th`,{className:`text-right whitespace-nowrap`,children:l(`account.actions`)})]})}),(0,Q.jsx)(`tbody`,{children:e.map(e=>(0,Q.jsxs)(`tr`,{children:[(0,Q.jsx)(`td`,{className:`font-bold whitespace-nowrap`,children:e.username}),(0,Q.jsx)(`td`,{className:`whitespace-nowrap`,children:(0,Q.jsx)(j,{minimal:!0,intent:e.role===`admin`?w.DANGER:w.NONE,className:`whitespace-nowrap`,children:e.role===`admin`?l(`account.roleAdmin`):l(`account.roleUser`)})}),(0,Q.jsx)(`td`,{className:`whitespace-nowrap`,children:(0,Q.jsxs)(`div`,{className:`flex flex-wrap gap-1`,children:[!!e.totp_enabled&&(0,Q.jsx)(j,{minimal:!0,intent:w.SUCCESS,className:`whitespace-nowrap`,children:`TOTP`}),!!(e.passkeys_count&&e.passkeys_count>0)&&(0,Q.jsx)(j,{minimal:!0,intent:w.PRIMARY,className:`whitespace-nowrap`,children:`Passkey`}),!e.totp_enabled&&!(e.passkeys_count&&e.passkeys_count>0)&&(0,Q.jsx)(j,{minimal:!0,intent:w.NONE,style:{color:`#8a9ba8`},className:`whitespace-nowrap`,children:l(`account.mfaNone`,`无`)})]})}),(0,Q.jsx)(`td`,{className:`whitespace-nowrap`,children:(0,Q.jsx)(`code`,{className:`text-xs`,children:e.id})}),(0,Q.jsx)(`td`,{className:`text-xs text-gray-500 whitespace-nowrap`,children:e.created_at?q(new Date(e.created_at*1e3)):`-`}),(0,Q.jsx)(`td`,{className:`text-xs text-gray-500 whitespace-nowrap`,children:e.last_active_at?q(new Date(e.last_active_at*1e3)):`-`}),(0,Q.jsx)(`td`,{className:`text-xs text-gray-500 whitespace-nowrap`,children:e.last_resolve_at?q(new Date(e.last_resolve_at*1e3)):`-`}),(0,Q.jsx)(`td`,{className:`text-right whitespace-nowrap`,children:(0,Q.jsx)(`div`,{className:`inline-flex items-center gap-1`,children:(0,Q.jsx)(b,{minimal:!0,intent:w.DANGER,icon:(0,Q.jsx)(m,{size:14}),disabled:e.id===t,onClick:()=>$(e.id)})})})]},e.id))})]})}),(0,Q.jsx)(x,{isOpen:u,onClose:()=>{d(!1),I(!1)},title:l(`account.createNewUser`),icon:`user`,children:(0,Q.jsxs)(`div`,{className:`p-6 space-y-4`,children:[(0,Q.jsx)(A,{label:l(`account.username`),children:(0,Q.jsx)(D,{value:p,onChange:e=>g(e.target.value),placeholder:l(`auth.usernamePlaceholder`)})}),(0,Q.jsx)(A,{label:l(`account.initialPassword`),children:(0,Q.jsx)(D,{type:F?`text`:`password`,value:_,onChange:e=>y(e.target.value),placeholder:l(`auth.passwordPlaceholder`),rightElement:(0,Q.jsx)(b,{minimal:!0,icon:F?`eye-open`:`eye-off`,onClick:()=>I(!F),title:F?l(`auth.hidePassword`,`Hide password`):l(`auth.showPassword`,`Show password`)})})}),(0,Q.jsx)(A,{label:l(`account.userRole`),children:(0,Q.jsx)(E,{fill:!0,value:S,onChange:e=>C(e.target.value),options:[{label:l(`account.roleUser`),value:`user`},{label:l(`account.roleAdmin`),value:`admin`}]})}),(0,Q.jsxs)(`div`,{className:`flex justify-end gap-2 mt-6`,children:[(0,Q.jsx)(b,{text:l(`account.cancel`),onClick:()=>d(!1)}),(0,Q.jsx)(b,{intent:w.PRIMARY,text:l(`account.createNow`),loading:T,onClick:Y})]})]})})]})},re=({toasterRef:e,onSavingChange:t})=>{let{t:n}=f(),[r,a]=(0,Z.useState)(``),[o,p]=(0,Z.useState)(!1),[m,h]=(0,Z.useState)([]),[g,_]=(0,Z.useState)(null),[x,E]=(0,Z.useState)(null),[O,M]=(0,Z.useState)([]),[P,F]=(0,Z.useState)(!1),[I,R]=(0,Z.useState)(null),[B,V]=(0,Z.useState)(null),H=(0,Z.useCallback)(async()=>{F(!0);try{M(await L())}catch(e){console.warn(`Failed to fetch distributed filter lists`,e)}finally{F(!1)}},[]);(0,Z.useEffect)(()=>{z().then(e=>{e&&Array.isArray(e)&&h(e.map(e=>({label:String(n(e.label,{defaultValue:e.label})),url:String(e.url||``)})))}).catch(e=>console.warn(`Failed to fetch preset filters`,e)),H()},[n,H]);let W=async()=>{let i=r.trim();if(i){p(!0),E(null),_(null),t?.(!0);try{let t=await U(i);_(t),a(``);let r=t.failedCount>0?n(`admin.distributeFilter.toastPartialSuccess`,`系统过滤列表已下发至 {{added}} 位用户,{{failed}} 位用户下发失败`,{added:t.addedCount,failed:t.failedCount}):n(`admin.distributeFilter.toastSuccess`,`系统过滤列表已成功下发至 {{count}} 位用户`,{count:t.addedCount});e?.current?.show({message:r,intent:t.failedCount>0&&t.addedCount===0?w.DANGER:t.failedCount>0?w.WARNING:w.SUCCESS,icon:t.failedCount>0&&t.addedCount===0?`error`:`tick`}),await H()}catch(t){let n=t instanceof Error?t.message:String(t);E(n),e?.current?.show({message:n,intent:w.DANGER,icon:`error`})}finally{p(!1),t?.(!1)}}},G=async r=>{R(r),V(null),t?.(!0);try{let t=await Y(r);e?.current?.show({message:n(`admin.distributeFilter.toastRevokeSuccess`,`已成功撤回系统过滤列表,移除了 {{count}} 位用户的系统规则`,{count:t.revokedCount}),intent:w.SUCCESS,icon:`tick`}),await H()}catch(t){let n=t instanceof Error?t.message:String(t);e?.current?.show({message:n,intent:w.DANGER,icon:`error`})}finally{R(null),t?.(!1)}};return(0,Q.jsxs)(N,{elevation:v.ZERO,className:`p-6 border border-gray-200 dark:border-gray-800 rounded-xl space-y-6`,children:[(0,Q.jsx)(`div`,{className:`flex items-start justify-between`,children:(0,Q.jsxs)(`div`,{children:[(0,Q.jsxs)(k,{className:`flex items-center space-x-2 text-base font-semibold`,children:[(0,Q.jsx)(i,{className:`w-5 h-5 text-indigo-500`}),(0,Q.jsx)(`span`,{children:n(`admin.distributeFilter.title`,`系统过滤列表 (管理员)`)})]}),(0,Q.jsx)(`p`,{className:`text-sm text-gray-500 dark:text-gray-400 mt-1`,children:n(`admin.distributeFilter.description`,`向系统中所有用户账号下发制定系统级过滤列表。规则自动应用于用户的全部配置,带有“系统”标签。如果用户已存在相同规则则自动跳过。`)})]})}),m.length>0&&(0,Q.jsxs)(`div`,{className:`space-y-2`,children:[(0,Q.jsxs)(`div`,{className:`text-xs font-medium text-gray-500 dark:text-gray-400 flex items-center space-x-1`,children:[(0,Q.jsx)(c,{className:`w-3.5 h-3.5`}),(0,Q.jsx)(`span`,{children:n(`admin.distributeFilter.quickPresets`,`快捷预设`)})]}),(0,Q.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:m.map(e=>(0,Q.jsx)(b,{minimal:!0,small:!0,className:`text-xs`,intent:r===e.url?w.PRIMARY:w.NONE,onClick:()=>a(e.url),children:e.label},e.url))})]}),(0,Q.jsxs)(`div`,{className:`space-y-4`,children:[(0,Q.jsx)(A,{label:n(`admin.distributeFilter.urlLabel`,`规则列表 URL`),labelFor:`distribute-filter-url`,helperText:n(`admin.distributeFilter.urlHelper`,`支持 AdGuard、Hosts、EasyList 等标准格式 URL`),children:(0,Q.jsxs)(`div`,{className:`flex flex-col sm:flex-row gap-3`,children:[(0,Q.jsx)(D,{id:`distribute-filter-url`,fill:!0,placeholder:`https://example.com/filter.txt`,value:r,onChange:e=>a(e.target.value),disabled:o,className:`font-mono text-sm`,onKeyDown:e=>{e.key===`Enter`&&r.trim()&&!o&&W()}}),(0,Q.jsx)(b,{intent:w.PRIMARY,icon:(0,Q.jsx)(i,{className:`w-4 h-4 mr-1`}),text:n(`admin.distributeFilter.submitBtn`,`立即下发`),loading:o,disabled:!r.trim(),onClick:W,className:`shrink-0`})]})}),x&&(0,Q.jsxs)(S,{intent:w.DANGER,icon:null,children:[(0,Q.jsxs)(y,{className:`flex items-center gap-2 mb-2 font-semibold`,children:[(0,Q.jsx)(d,{className:`w-4 h-4 shrink-0`}),(0,Q.jsx)(`span`,{children:n(`common.error`,`错误`)})]}),(0,Q.jsx)(`div`,{className:`text-sm`,children:x})]}),g&&(0,Q.jsxs)(S,{intent:g.failedCount>0?g.addedCount>0?w.WARNING:w.DANGER:w.SUCCESS,icon:null,children:[(0,Q.jsxs)(y,{className:`flex items-center gap-2 mb-2 font-semibold`,children:[g.failedCount>0&&g.addedCount===0?(0,Q.jsx)(d,{className:`w-4 h-4 shrink-0 text-red-500`}):(0,Q.jsx)(u,{className:`w-4 h-4 shrink-0 text-green-500`}),(0,Q.jsx)(`span`,{children:n(`admin.distributeFilter.resultTitle`,`下发执行完成`)})]}),(0,Q.jsxs)(`div`,{className:`space-y-2 text-sm`,children:[(0,Q.jsx)(`p`,{children:g.failedCount>0?n(`admin.distributeFilter.resultSummaryWithFailed`,`系统共 {{total}} 位用户:成功下发至 {{added}} 位用户,跳过 {{skipped}} 位已存在该规则的用户,{{failed}} 位用户下发失败。`,{total:g.totalUsers,added:g.addedCount,skipped:g.skippedCount,failed:g.failedCount}):n(`admin.distributeFilter.resultSummary`,`系统共 {{total}} 位用户:成功下发至 {{added}} 位用户,跳过 {{skipped}} 位已存在该规则的用户。`,{total:g.totalUsers,added:g.addedCount,skipped:g.skippedCount})}),g.addedUsernames.length>0&&(0,Q.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1.5 pt-1`,children:[(0,Q.jsxs)(`span`,{className:`text-xs font-medium text-gray-500`,children:[n(`admin.distributeFilter.addedUsers`,`下发成功用户`),`:`]}),g.addedUsernames.map(e=>(0,Q.jsx)(j,{intent:w.SUCCESS,minimal:!0,round:!0,children:e},e))]}),g.skippedUsernames.length>0&&(0,Q.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1.5 pt-1`,children:[(0,Q.jsxs)(`span`,{className:`text-xs font-medium text-gray-500`,children:[n(`admin.distributeFilter.skippedUsers`,`已存在规则用户`),`:`]}),g.skippedUsernames.map(e=>(0,Q.jsx)(j,{intent:w.NONE,minimal:!0,round:!0,children:e},e))]}),g.failedUsernames.length>0&&(0,Q.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1.5 pt-1`,children:[(0,Q.jsxs)(`span`,{className:`text-xs font-medium text-red-500 dark:text-red-400`,children:[n(`admin.distributeFilter.failedUsers`,`下发失败用户`),`:`]}),g.failedUsernames.map(e=>(0,Q.jsx)(j,{intent:w.DANGER,minimal:!0,round:!0,children:e},e))]})]})]})]}),(0,Q.jsx)(T,{}),(0,Q.jsxs)(`div`,{className:`space-y-3`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Q.jsxs)(`div`,{className:`text-sm font-semibold flex items-center space-x-2`,children:[(0,Q.jsx)(l,{className:`w-4 h-4 text-indigo-500`}),(0,Q.jsx)(`span`,{children:n(`admin.distributeFilter.activeDistributedTitle`,`已下发系统规则`)})]}),O.length>0&&(0,Q.jsx)(j,{minimal:!0,round:!0,intent:w.PRIMARY,children:O.length})]}),(0,Q.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-gray-400`,children:n(`admin.distributeFilter.activeDistributedDesc`,`当前处于系统下发状态且带有“系统”标签的规则列表。撤回后将从所有用户账号中移除此系统规则,用户自建的同名规则不受影响。`)}),P?(0,Q.jsx)(`div`,{className:`text-xs text-gray-400 py-3 text-center`,children:n(`common.loading`,`加载中...`)}):O.length===0?(0,Q.jsx)(`div`,{className:`text-xs text-gray-400 dark:text-gray-500 py-4 px-3 bg-gray-50 dark:bg-gray-800/50 rounded-lg text-center border border-dashed border-gray-200 dark:border-gray-700`,children:n(`admin.distributeFilter.noDistributedFilters`,`当前系统中无已下发的系统过滤列表`)}):(0,Q.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:O.map(e=>(0,Q.jsxs)(`div`,{className:`p-3 bg-white dark:bg-gray-900 flex flex-col sm:flex-row sm:items-center justify-between gap-3 text-sm`,children:[(0,Q.jsxs)(`div`,{className:`min-w-0 flex-1 space-y-1`,children:[(0,Q.jsx)(`div`,{className:`font-mono text-xs text-gray-800 dark:text-gray-200 truncate select-all`,title:e.url,children:e.url}),(0,Q.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1.5 text-xs text-gray-500`,children:[(0,Q.jsx)(j,{minimal:!0,round:!0,intent:w.PRIMARY,children:n(`admin.distributeFilter.usersCount`,`{{count}} 位用户`,{count:e.userCount})}),e.usernames.length>0&&(0,Q.jsxs)(`span`,{className:`text-xs text-gray-400 truncate max-w-xs`,children:[`(`,e.usernames.join(`, `),`)`]})]})]}),(0,Q.jsx)(`div`,{className:`shrink-0`,children:(0,Q.jsx)(C,{isOpen:B===e.url,onInteraction:t=>V(t?e.url:null),placement:`top-end`,portalClassName:`z-20000`,content:(0,Q.jsxs)(`div`,{className:`p-3 space-y-3 max-w-xs`,children:[(0,Q.jsx)(`p`,{className:`text-xs font-semibold leading-relaxed m-0 text-gray-800 dark:text-gray-200`,children:n(`admin.distributeFilter.revokeConfirm`,`确定撤回此系统过滤列表?系统将从所有用户账号中移除此系统规则,用户自建的同名规则不受影响。`)}),(0,Q.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,Q.jsx)(b,{small:!0,variant:`minimal`,text:n(`common.cancel`,`取消`),onClick:()=>V(null)}),(0,Q.jsx)(b,{small:!0,intent:w.DANGER,loading:I===e.url,text:n(`admin.distributeFilter.confirmRevoke`,`确认撤回`),onClick:()=>G(e.url)})]})]}),children:(0,Q.jsx)(b,{small:!0,intent:w.DANGER,minimal:!0,icon:(0,Q.jsx)(s,{className:`w-3.5 h-3.5`}),text:n(`admin.distributeFilter.revokeBtn`,`撤回`),loading:I===e.url,onClick:()=>V(e.url)})})})]},e.url))})]})]})},ie=({initialSettings:e,onRefresh:t,onSavingChange:n,toasterRef:r})=>{let{t:i}=f(),[a,s]=(0,Z.useState)(e),[c,l]=(0,Z.useState)(!1),[u,d]=(0,Z.useState)(!1);return(0,Z.useEffect)(()=>{s(e)},[e]),(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Q.jsx)(o,{size:20,className:`text-gray-500`}),(0,Q.jsx)(k,{style:{margin:0},children:i(`account.systemSettings`,`System Settings`)})]}),(0,Q.jsxs)(N,{elevation:v.ONE,children:[(0,Q.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-x-8 gap-y-4`,children:[(0,Q.jsxs)(`div`,{className:`space-y-4`,children:[(0,Q.jsx)(k,{className:`text-sm font-bold opacity-70 text-blue-500`,children:`Cloudflare Turnstile`}),(0,Q.jsx)(A,{label:`Site Key`,children:(0,Q.jsx)(D,{value:a.turnstile_site_key||``,onChange:e=>s({...a,turnstile_site_key:e.target.value}),placeholder:`0x000...`})}),(0,Q.jsx)(A,{label:`Secret Key`,children:(0,Q.jsx)(D,{type:u?`text`:`password`,value:a.turnstile_secret_key||``,onChange:e=>s({...a,turnstile_secret_key:e.target.value}),placeholder:`0x000...`,rightElement:(0,Q.jsx)(b,{minimal:!0,icon:u?`eye-open`:`eye-off`,onClick:()=>d(!u),title:u?i(`auth.hidePassword`,`Hide password`):i(`auth.showPassword`,`Show password`)})})})]}),(0,Q.jsxs)(`div`,{className:`space-y-4`,children:[(0,Q.jsx)(k,{className:`text-sm font-bold opacity-70 text-green-500`,children:i(`account.featureToggle`,`Feature Toggle`)}),(0,Q.jsx)(O,{label:i(`account.enableTurnstileSignup`,`Enable verification on Signup`),checked:a.turnstile_enabled_signup===`true`,onChange:e=>s({...a,turnstile_enabled_signup:String(e.currentTarget.checked)})}),(0,Q.jsx)(O,{label:i(`account.enableTurnstileLogin`,`Enable verification on Login`),checked:a.turnstile_enabled_login===`true`,onChange:e=>s({...a,turnstile_enabled_login:String(e.currentTarget.checked)})}),(0,Q.jsx)(T,{className:`my-2`}),(0,Q.jsx)(k,{className:`text-sm font-bold opacity-70 text-indigo-500`,children:i(`account.userLimits`,`User Quota`)}),(0,Q.jsx)(A,{label:i(`account.maxUsers`,`Max Users`),helperText:i(`account.maxUsersHelper`,`Maximum number of users allowed in the system (0 for unlimited).`),children:(0,Q.jsx)(D,{type:`number`,min:0,value:a.max_users||``,onChange:e=>s({...a,max_users:e.target.value}),placeholder:`0`})})]})]}),(0,Q.jsx)(T,{className:`my-4`}),(0,Q.jsx)(`div`,{className:`flex justify-end`,children:(0,Q.jsx)(b,{intent:w.PRIMARY,icon:`floppy-disk`,text:i(`common.save`,`Save`),loading:c,onClick:async()=>{l(!0),n?.(!0);try{await X(G({turnstile_site_key:a.turnstile_site_key||``,turnstile_secret_key:a.turnstile_secret_key||``,turnstile_enabled_signup:a.turnstile_enabled_signup||`false`,turnstile_enabled_login:a.turnstile_enabled_login||`false`,max_users:a.max_users||`0`}),1e4),r?.current?.show({message:i(`common.saveSuccess`,`保存成功`),intent:w.SUCCESS,icon:`tick`}),t()}catch(t){console.error(t),s(e),r?.current?.show({message:t.message||i(`common.saveFailed`,`保存失败`),intent:w.DANGER,icon:`error`})}finally{l(!1),n?.(!1)}}})})]})]})},ae=({status:e,onRefresh:n,toasterRef:i})=>{let{t:a}=f(),[o,s]=(0,Z.useState)(!1),[c,l]=(0,Z.useState)(!1),m=e?.migrations,h=m?.completed??!1;return(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsxs)(`div`,{className:`flex flex-col sm:flex-row sm:items-center justify-between gap-2`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Q.jsx)(p,{size:20,className:`text-gray-500`}),(0,Q.jsx)(k,{style:{margin:0},children:a(`account.databaseSettings`,`数据库 (管理员)`)})]}),m?(0,Q.jsx)(j,{large:!0,round:!0,intent:h?w.SUCCESS:w.WARNING,icon:h?(0,Q.jsx)(u,{size:16}):(0,Q.jsx)(d,{size:16}),className:`whitespace-nowrap self-start sm:self-auto`,children:h?a(`account.migrationCompleted`,`迁移已完成`):a(`account.migrationPending`,`有待执行迁移`)}):(0,Q.jsx)(j,{large:!0,round:!0,intent:w.NONE,className:`whitespace-nowrap self-start sm:self-auto`,children:a(`common.loading`,`加载中...`)})]}),(0,Q.jsx)(N,{elevation:v.ONE,children:(0,Q.jsxs)(`div`,{className:`space-y-5`,children:[(0,Q.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-4`,children:[(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`span`,{className:`text-xs uppercase font-semibold text-gray-500 tracking-wider`,children:a(`account.databaseEngine`,`数据库服务`)}),(0,Q.jsx)(`div`,{className:`text-sm font-medium mt-1`,children:(e=>e===`Turso`?`Turso (libSQL)`:e===`D1`?`Cloudflare D1`:e===`File`?`SQLite (Local File)`:e||`SQLite`)(e?.databaseService)})]}),(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`span`,{className:`text-xs uppercase font-semibold text-gray-500 tracking-wider`,children:a(`account.lastAppliedMigration`,`最近应用版本`)}),(0,Q.jsx)(`div`,{className:`text-sm font-medium font-mono text-gray-700 dark:text-gray-300 mt-1 truncate`,children:m?.lastApplied||a(`account.noMigrationsApplied`,`无`)})]})]}),(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`span`,{className:`text-xs uppercase font-semibold text-gray-500 tracking-wider`,children:a(`account.migrationStatus`,`架构状态`)}),(0,Q.jsx)(`p`,{className:`text-sm text-gray-600 dark:text-gray-300 mt-1`,children:m?h?a(`account.migrationCompletedDesc`,{total:m?.totalAvailable||0}):a(`account.migrationPendingDesc`,{applied:m?.appliedCount||0,total:m?.totalAvailable||0,pending:m?.pendingCount||0}):a(`common.loading`,`加载中...`)})]}),!h&&m&&m.pendingFiles.length>0&&(0,Q.jsxs)(S,{intent:w.WARNING,icon:null,children:[(0,Q.jsxs)(y,{className:`flex items-center gap-2 mb-1 text-xs font-semibold`,children:[(0,Q.jsx)(d,{className:`w-4 h-4 shrink-0`}),(0,Q.jsx)(`span`,{children:a(`account.pendingMigrationsList`,`待应用的架构迁移文件:`)})]}),(0,Q.jsx)(`ul`,{className:`list-disc list-inside text-xs font-mono space-y-0.5 text-gray-700 dark:text-gray-300 max-h-32 overflow-y-auto`,children:m.pendingFiles.map(e=>(0,Q.jsx)(`li`,{children:e},e))})]}),(0,Q.jsxs)(`div`,{className:`flex items-center justify-between pt-2 border-t border-gray-100 dark:border-gray-800`,children:[(0,Q.jsx)(b,{minimal:!0,icon:(0,Q.jsx)(t,{size:14,className:c?`animate-spin`:``}),text:a(`account.checkMigration`,`刷新状态`),onClick:async()=>{l(!0);try{await n()}finally{l(!1)}},disabled:o||c}),(0,Q.jsx)(b,{intent:w.PRIMARY,icon:(0,Q.jsx)(r,{size:14}),text:o?a(`account.runningMigration`,`正在迁移...`):a(`account.runMigration`,`执行迁移`),loading:o,disabled:h||o,onClick:async()=>{s(!0);try{let e=await F();i?.current?.show({message:a(`account.migrationSuccess`,{count:e.appliedCount}),intent:w.SUCCESS,icon:`tick`}),await n()}catch(e){console.error(e),i?.current?.show({message:e.message||a(`account.migrationFailed`),intent:w.DANGER,icon:`error`})}finally{s(!1)}}})]})]})})]})},oe=({onSavingChange:e,toasterRef:t})=>{let[r,i]=(0,Z.useState)(null),[o,s]=(0,Z.useState)([]),[c,l]=(0,Z.useState)(!0),{t:u}=f(),d=J(),[p,m]=(0,Z.useState)({}),[h,g]=(0,Z.useState)(null),_=async()=>{try{s(await W())}catch(e){console.error(e)}},v=async()=>{try{m(await B())}catch(e){console.error(e)}},b=(0,Z.useCallback)(async()=>{try{g(await I())}catch(e){console.error(`Failed to fetch database status:`,e)}},[]),x=(0,Z.useCallback)(async()=>{try{let e=await R();i(e),e.role===`admin`&&(_(),v(),b())}catch(e){console.error(e)}finally{l(!1)}},[b]);return(0,Z.useEffect)(()=>{x()},[x]),c?(0,Q.jsx)(`div`,{className:`p-8 text-center`,children:u(`common.loading`,`加载中...`)}):r?.role===`admin`?(0,Q.jsxs)(`div`,{className:P(`max-w-5xl mx-auto space-y-8`,d?`p-0`:`px-8`),children:[(0,Q.jsxs)(`div`,{className:`flex justify-between items-start sm:items-end gap-3 flex-wrap sm:flex-nowrap`,children:[(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`h2`,{className:`bp6-heading`,children:u(`system.title`,`系统管理`)}),(0,Q.jsx)(`p`,{className:`bp6-text-muted`,children:u(`system.subtitle`,`管理用户、系统过滤列表、系统配置与数据库维护`)})]}),(0,Q.jsx)(j,{large:!0,round:!0,intent:w.DANGER,icon:(0,Q.jsx)(a,{size:16}),className:`shrink-0 whitespace-nowrap`,children:u(`account.roleAdmin`,`管理员`)})]}),r?.jwt_secret_warning&&(0,Q.jsxs)(S,{intent:w.WARNING,icon:null,children:[(0,Q.jsxs)(y,{className:`flex items-center gap-2 mb-1 font-semibold`,children:[(0,Q.jsx)(n,{className:`w-4 h-4 shrink-0`}),(0,Q.jsx)(`span`,{children:u(`account.jwtSecretWarningTitle`)})]}),(0,Q.jsx)(`div`,{className:`text-sm leading-relaxed mt-1`,children:u(`account.jwtSecretWarningDesc`)})]}),(0,Q.jsx)(`div`,{className:`space-y-4`,children:(0,Q.jsx)($,{users:o,currentUserId:r.id,onRefresh:_,registrationEnabled:p.registration_enabled!==`false`,maxUsers:p.max_users,onRefreshSettings:v,onSavingChange:e,toasterRef:t})}),(0,Q.jsx)(T,{}),(0,Q.jsx)(`div`,{className:`space-y-4`,children:(0,Q.jsx)(re,{onSavingChange:e,toasterRef:t})}),(0,Q.jsx)(T,{}),(0,Q.jsx)(`div`,{className:`space-y-4`,children:(0,Q.jsx)(ie,{initialSettings:p,onRefresh:v,onSavingChange:e,toasterRef:t})}),(0,Q.jsx)(T,{}),(0,Q.jsx)(`div`,{className:`space-y-4`,children:(0,Q.jsx)(ae,{status:h,onRefresh:b,toasterRef:t})})]}):(0,Q.jsx)(`div`,{className:P(`max-w-5xl mx-auto space-y-6`,d?`p-0`:`px-8`),children:(0,Q.jsx)(S,{intent:w.DANGER,icon:`error`,title:u(`system.accessDenied`,`访问受限`),children:u(`system.accessDeniedDesc`,`当前页面仅限管理员访问。`)})})};export{oe as SystemView};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{_ as e,g as t,h as n}from"./index-DEIEgGUw.js";export{t as setSystemLocale,e as setSystemTimeZone};
|