dns-worker 1.2.0 → 1.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (66) hide show
  1. package/.env.serverfull +1 -1
  2. package/dist/serverfull.mjs +396 -103
  3. package/dist/serverfull.mjs.map +4 -4
  4. package/migrations/0063_add_list_etag_and_last_modified.sql +4 -0
  5. package/migrations/0064_globalize_list_compilation.sql +51 -0
  6. package/migrations/0065_add_is_system_to_lists.sql +2 -0
  7. package/migrations/0066_standardize_last_modified_timestamp.sql +32 -0
  8. package/migrations/0067_add_user_lists.sql +50 -0
  9. package/package.json +103 -99
  10. package/static/assets/AccountView-0QcFZ1Jr.js +4 -0
  11. package/static/assets/{AnalyticsView-DduTz2mL.js → AnalyticsView-DPHx2dY5.js} +2 -2
  12. package/static/assets/DestinationMap-B3EEJV7e.js +1 -0
  13. package/static/assets/FilteringView-PYhZsfXI.js +1 -0
  14. package/static/assets/LogsView-DS6lzitI.js +5 -0
  15. package/static/assets/RulesView-CtQt9Fju.js +1 -0
  16. package/static/assets/SettingsView-B6nhXQtx.js +1 -0
  17. package/static/assets/SetupView-DNfTcqJY.js +1 -0
  18. package/static/assets/{SwipeableDrawer-B1CCYC-Y.js → SwipeableDrawer-BuCjl9Vd.js} +1 -1
  19. package/static/assets/SystemView-CpIEbDsf.js +1 -0
  20. package/static/assets/{TrendChart-CcVh0Ul8.js → TrendChart-wgomUkAw.js} +1 -1
  21. package/static/assets/browser-D1bxqOmO.js +1 -0
  22. package/static/assets/date-BFCCct66.js +1 -0
  23. package/static/assets/de-DE-DkZSdTly.js +12 -0
  24. package/static/assets/es-ES-B6WvDhm2.js +12 -0
  25. package/static/assets/fr-FR-83O7dpp-.js +12 -0
  26. package/static/assets/index-DEIEgGUw.js +17 -0
  27. package/static/assets/index-DzxNVvDJ.css +2 -0
  28. package/static/assets/ja-JP-TsIw1jL8.js +12 -0
  29. package/static/assets/ko-KR-BJCV1gAO.js +12 -0
  30. package/static/assets/ru-RU-D7sFMEOm.js +12 -0
  31. package/static/assets/services-BF0oUgkb.js +1 -0
  32. package/static/assets/useLogsE2ee-CARmudiz.js +1 -0
  33. package/static/assets/vendor-i18next-DlmslyBB.js +1 -0
  34. package/static/assets/vendor-react-DYK5a2J9.js +11 -0
  35. package/static/assets/vendor-ui-core-C4974KNo.js +1 -0
  36. package/static/assets/vendor-utils-Bab4qB3W.js +9 -0
  37. package/static/assets/vi-VN-B01Yq7PJ.js +12 -0
  38. package/static/assets/zh-CN-DmAkz3rO.js +12 -0
  39. package/static/assets/zh-TW-osJQe9X5.js +12 -0
  40. package/static/index.html +6 -6
  41. package/static/assets/AccountView-BRbZJ2sH.js +0 -4
  42. package/static/assets/DestinationMap-BU-Qz1TJ.js +0 -1
  43. package/static/assets/FilteringView-BZyNVjG8.js +0 -1
  44. package/static/assets/LogsView-3pkdqVwJ.js +0 -5
  45. package/static/assets/RulesView-DL_nXrE1.js +0 -1
  46. package/static/assets/SettingsView-VQgi2SoD.js +0 -1
  47. package/static/assets/SetupView-KiWkymII.js +0 -1
  48. package/static/assets/browser-DGSv7yOq.js +0 -1
  49. package/static/assets/date-X7Pe3vrN.js +0 -1
  50. package/static/assets/de-DE-7fbCt68F.js +0 -12
  51. package/static/assets/es-ES-8PlbA4am.js +0 -12
  52. package/static/assets/fr-FR-C5yENtwk.js +0 -12
  53. package/static/assets/index-DAlgfwkx.css +0 -2
  54. package/static/assets/index-tOK5I5yC.js +0 -17
  55. package/static/assets/ja-JP-DSySc1Ss.js +0 -12
  56. package/static/assets/ko-KR-Cs8hF_3q.js +0 -12
  57. package/static/assets/ru-RU-BjRr4hiJ.js +0 -12
  58. package/static/assets/services-p_KEZfBm.js +0 -1
  59. package/static/assets/useLogsE2ee-Dof2Ttto.js +0 -1
  60. package/static/assets/vendor-i18next-BC3ewzY3.js +0 -1
  61. package/static/assets/vendor-react-BtC4HVVO.js +0 -11
  62. package/static/assets/vendor-ui-core-DUyKOLA8.js +0 -1
  63. package/static/assets/vendor-utils-xrsi4rSa.js +0 -9
  64. package/static/assets/vi-VN-D1zLdtwy.js +0 -12
  65. package/static/assets/zh-CN-DUVQN_SI.js +0 -12
  66. package/static/assets/zh-TW-C51Jc3Hf.js +0 -12
@@ -0,0 +1,4 @@
1
+ -- Migration 0063: Add HTTP ETag and Last-Modified headers to lists table for conditional request (304 Not Modified) optimization
2
+
3
+ ALTER TABLE lists ADD COLUMN etag TEXT;
4
+ ALTER TABLE lists ADD COLUMN last_modified TEXT;
@@ -0,0 +1,51 @@
1
+ -- Migration 0064: Globalize compiled filter lists storage and metadata
2
+
3
+ -- 1. Create global list metadata table
4
+ CREATE TABLE IF NOT EXISTS global_list_metadata (
5
+ url TEXT PRIMARY KEY,
6
+ etag TEXT,
7
+ last_modified TEXT,
8
+ last_synced_at INTEGER,
9
+ sync_error TEXT,
10
+ created_at INTEGER NOT NULL
11
+ );
12
+
13
+ -- 2. Create global list bloom filter chunks table
14
+ CREATE TABLE IF NOT EXISTS global_list_blooms (
15
+ url TEXT NOT NULL,
16
+ chunk_index INTEGER NOT NULL,
17
+ bloom_filter_chunk BLOB NOT NULL,
18
+ updated_at INTEGER NOT NULL,
19
+ PRIMARY KEY (url, chunk_index),
20
+ FOREIGN KEY (url) REFERENCES global_list_metadata(url) ON DELETE CASCADE
21
+ );
22
+
23
+ CREATE INDEX IF NOT EXISTS idx_global_list_blooms_url ON global_list_blooms(url);
24
+
25
+ -- 3. Create global list AdGuard rules payload table
26
+ CREATE TABLE IF NOT EXISTS global_list_adguard_rules (
27
+ url TEXT PRIMARY KEY,
28
+ payload TEXT NOT NULL,
29
+ updated_at INTEGER NOT NULL,
30
+ FOREIGN KEY (url) REFERENCES global_list_metadata(url) ON DELETE CASCADE
31
+ );
32
+
33
+ -- 4. Backfill existing lists data into global tables
34
+ INSERT OR IGNORE INTO global_list_metadata (url, etag, last_modified, last_synced_at, sync_error, created_at)
35
+ SELECT url, etag, last_modified, last_synced_at, sync_error, strftime('%s', 'now')
36
+ FROM lists
37
+ GROUP BY url;
38
+
39
+ INSERT OR IGNORE INTO global_list_blooms (url, chunk_index, bloom_filter_chunk, updated_at)
40
+ SELECT l.url, lb.chunk_index, lb.bloom_filter_chunk, lb.updated_at
41
+ FROM list_blooms lb
42
+ JOIN lists l ON lb.list_id = l.id;
43
+
44
+ INSERT OR IGNORE INTO global_list_adguard_rules (url, payload, updated_at)
45
+ SELECT l.url, ar.payload, ar.updated_at
46
+ FROM list_adguard_rules ar
47
+ JOIN lists l ON ar.list_id = l.id;
48
+
49
+ -- 5. Drop old redundant per-list bloom and rule tables to reclaim storage
50
+ DROP TABLE IF EXISTS list_blooms;
51
+ DROP TABLE IF EXISTS list_adguard_rules;
@@ -0,0 +1,2 @@
1
+ ALTER TABLE lists ADD COLUMN is_system INTEGER DEFAULT 0;
2
+ CREATE INDEX IF NOT EXISTS idx_lists_url ON lists(url);
@@ -0,0 +1,32 @@
1
+ -- Migration 0066: Standardize global_list_metadata last_modified column to integer Unix timestamp
2
+
3
+ CREATE TABLE IF NOT EXISTS global_list_metadata_new (
4
+ url TEXT PRIMARY KEY,
5
+ etag TEXT,
6
+ last_modified INTEGER,
7
+ last_synced_at INTEGER,
8
+ sync_error TEXT,
9
+ created_at INTEGER NOT NULL
10
+ );
11
+
12
+ INSERT OR IGNORE INTO global_list_metadata_new (url, etag, last_modified, last_synced_at, sync_error, created_at)
13
+ SELECT
14
+ url,
15
+ etag,
16
+ CASE
17
+ WHEN typeof(last_modified) = 'integer' THEN last_modified
18
+ WHEN typeof(last_modified) = 'text' AND last_modified GLOB '[0-9]*' THEN CAST(last_modified AS INTEGER)
19
+ ELSE NULL
20
+ END,
21
+ last_synced_at,
22
+ sync_error,
23
+ created_at
24
+ FROM global_list_metadata;
25
+
26
+ DROP TABLE global_list_metadata;
27
+ ALTER TABLE global_list_metadata_new RENAME TO global_list_metadata;
28
+
29
+ -- Sanitize legacy lists table column values if present
30
+ UPDATE lists
31
+ SET last_modified = NULL
32
+ WHERE last_modified IS NOT NULL AND typeof(last_modified) != 'integer' AND last_modified NOT GLOB '[0-9]*';
@@ -0,0 +1,50 @@
1
+ -- Migration 0067: Add user-level filter lists and profile override tables
2
+ --
3
+ -- 1. user_lists: Stores User-level filter lists (both user-created and system-distributed)
4
+ -- which apply to all profiles belonging to that user.
5
+ -- 2. profile_user_list_overrides: Allows enabling/disabling a user-level or system-level
6
+ -- list for a specific profile without deleting it.
7
+
8
+ CREATE TABLE IF NOT EXISTS user_lists (
9
+ id INTEGER PRIMARY KEY AUTOINCREMENT,
10
+ user_id TEXT NOT NULL,
11
+ url TEXT NOT NULL,
12
+ is_system INTEGER DEFAULT 0, -- 0: User-created, 1: System-distributed
13
+ enabled INTEGER DEFAULT 1, -- Default enabled state for the user
14
+ created_at INTEGER NOT NULL, -- Integer Unix timestamp in seconds
15
+ FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE,
16
+ UNIQUE(user_id, url)
17
+ );
18
+
19
+ CREATE INDEX IF NOT EXISTS idx_user_lists_user_id ON user_lists(user_id);
20
+ CREATE INDEX IF NOT EXISTS idx_user_lists_url ON user_lists(url);
21
+
22
+ CREATE TABLE IF NOT EXISTS profile_user_list_overrides (
23
+ profile_id TEXT NOT NULL,
24
+ user_list_id INTEGER NOT NULL,
25
+ enabled INTEGER NOT NULL, -- 0: Disabled for this profile, 1: Enabled
26
+ updated_at INTEGER NOT NULL, -- Integer Unix timestamp in seconds
27
+ PRIMARY KEY (profile_id, user_list_id),
28
+ FOREIGN KEY (profile_id) REFERENCES profiles(id) ON DELETE CASCADE,
29
+ FOREIGN KEY (user_list_id) REFERENCES user_lists(id) ON DELETE CASCADE
30
+ );
31
+
32
+ CREATE INDEX IF NOT EXISTS idx_pulo_profile_id ON profile_user_list_overrides(profile_id);
33
+
34
+ -- Backfill legacy system lists from lists table to user_lists
35
+ INSERT OR IGNORE INTO user_lists (user_id, url, is_system, enabled, created_at)
36
+ SELECT DISTINCT p.owner_id, l.url, 1, 1, strftime('%s', 'now')
37
+ FROM lists l
38
+ JOIN profiles p ON l.profile_id = p.id
39
+ WHERE l.is_system = 1;
40
+
41
+ -- Backfill any per-profile disabled state for migrated system lists
42
+ INSERT OR IGNORE INTO profile_user_list_overrides (profile_id, user_list_id, enabled, updated_at)
43
+ SELECT l.profile_id, ul.id, l.enabled, strftime('%s', 'now')
44
+ FROM lists l
45
+ JOIN profiles p ON l.profile_id = p.id
46
+ JOIN user_lists ul ON ul.user_id = p.owner_id AND ul.url = l.url
47
+ WHERE l.is_system = 1 AND l.enabled = 0;
48
+
49
+ -- Remove migrated system lists from profile-level lists table
50
+ DELETE FROM lists WHERE is_system = 1;
package/package.json CHANGED
@@ -1,99 +1,103 @@
1
- {
2
- "name": "dns-worker",
3
- "version": "1.2.0",
4
- "private": false,
5
- "description": "Privacy-first DNS & DoH Resolver with modern Web Dashboard, built for Cloudflare Workers & Node.js",
6
- "main": "./dist/serverfull.mjs",
7
- "bin": {
8
- "dns-worker": "./dist/serverfull.mjs",
9
- "obexdns": "./dist/serverfull.mjs"
10
- },
11
- "files": [
12
- "dist/",
13
- "static/",
14
- "migrations/",
15
- ".env.serverfull",
16
- "README.md",
17
- "LICENSE"
18
- ],
19
- "engines": {
20
- "node": ">=22.5.0"
21
- },
22
- "scripts": {
23
- "predev": "npm run db:generate-migrations",
24
- "dev": "npm run db:migrate:dev && concurrently \"npm run ui:dev\" \"wrangler dev\"",
25
- "start": "npm run build && wrangler dev",
26
- "start:serverfull": "npm run build:serverfull && node --enable-source-maps dist/serverfull.mjs",
27
- "serverfull": "npm run build:serverfull && node --enable-source-maps dist/serverfull.mjs",
28
- "build:serverfull": "npm run db:generate-migrations && npm run ui:build && npx esbuild src/serverfull/index.ts --bundle --platform=node --target=node24 --format=esm --outfile=dist/serverfull.mjs --banner:js=\"#!/usr/bin/env node\" --external:node:sqlite --minify --sourcemap --tree-shaking=true --legal-comments=none",
29
- "prepublishOnly": "npm run build:serverfull",
30
- "service-create:linux": "tsx scripts/create-linux-service.ts",
31
- "docker:build": "tsx scripts/docker.ts build",
32
- "docker:build:alpha": "tsx scripts/docker.ts build --alpha",
33
- "docker:build:multiarch": "tsx scripts/docker.ts multiarch",
34
- "docker:push": "tsx scripts/docker.ts push",
35
- "docker:push:alpha": "tsx scripts/docker.ts push --alpha",
36
- "docker:run": "tsx scripts/docker.ts run",
37
- "docs:dev": "npm --prefix docs run dev",
38
- "docs:build": "npm --prefix docs run build",
39
- "docs:convert-tw": "npm --prefix docs run convert-tw",
40
- "deploy": "npm run build && npm run db:migrate:prod && wrangler deploy",
41
- "deploy:skipdb": "npm run build && wrangler deploy",
42
- "build": "npm run ui:build",
43
- "build:pages": "npm run db:generate-migrations && npm run ui:build && npx esbuild src/index.ts --bundle --outfile=static/_worker.js --platform=neutral --format=esm --minify --external:cloudflare:* --external:node:*",
44
- "db:generate-migrations": "tsx scripts/generate-embedded-migrations.ts",
45
- "prebuild": "npm run db:generate-migrations",
46
- "prepare": "npm run db:generate-migrations && npm run ui:install",
47
- "postinstall": "npm run db:generate-migrations",
48
- "db:setup": "wrangler d1 create dns_worker_db",
49
- "db:migrate:dev": "tsx scripts/migrate-dev.ts",
50
- "db:migrate:prod": "tsx scripts/migrate-prod.ts",
51
- "db:status": "wrangler d1 execute dns_worker_db --local --command='SELECT name FROM sqlite_master WHERE type=\"table\"'",
52
- "pretest": "npm run db:generate-migrations",
53
- "test": "tsx test/test_legacy_compat.ts",
54
- "test:compat": "tsx test/test_legacy_compat.ts",
55
- "test:turso": "tsx test/test_turso.ts",
56
- "test:turnstile": "tsx test/test_turnstile.ts",
57
- "test:serverfull": "tsx test/test_serverfull.ts",
58
- "test:reset": "tsx test/test_serverfull_reset.ts",
59
- "lint": "oxlint",
60
- "ui:dev": "cd web && npm run dev",
61
- "ui:build": "cd web && npm run build",
62
- "ui:install": "cd web && npm install",
63
- "tag-promote": "npm version patch",
64
- "tag-push": "git push && git push --tags"
65
- },
66
- "keywords": [
67
- "dns",
68
- "cloudflare-workers",
69
- "doh",
70
- "ad-blocking",
71
- "privacy"
72
- ],
73
- "author": "Hugo Koo",
74
- "license": "AGPL-3.0-or-later",
75
- "repository": {
76
- "type": "git",
77
- "url": "git+https://github.com/Obein/DNS-Worker.git"
78
- },
79
- "homepage": "https://github.com/Obein/DNS-Worker#readme",
80
- "bugs": {
81
- "url": "https://github.com/Obein/DNS-Worker/issues"
82
- },
83
- "devDependencies": {
84
- "@cloudflare/workers-types": "^5.20261101.1",
85
- "@types/node": "^26.6.6",
86
- "concurrently": "^10.0.6",
87
- "oxlint": "^1.90.0",
88
- "tsx": "^4.23.15",
89
- "typescript": "^7.0.2",
90
- "wrangler": "^4.156.0"
91
- },
92
- "overrides": {
93
- "esbuild": "^0.28.1",
94
- "undici": "^7.30.1"
95
- },
96
- "dependencies": {
97
- "@noble/post-quantum": "^0.7.1"
98
- }
99
- }
1
+ {
2
+ "name": "dns-worker",
3
+ "version": "1.2.1",
4
+ "private": false,
5
+ "description": "Privacy-first DNS & DoH Resolver with modern Web Dashboard, built for Cloudflare Workers & Node.js",
6
+ "main": "./dist/serverfull.mjs",
7
+ "bin": {
8
+ "dns-worker": "./dist/serverfull.mjs"
9
+ },
10
+ "files": [
11
+ "dist/",
12
+ "static/",
13
+ "migrations/",
14
+ ".env.serverfull",
15
+ "README.md",
16
+ "LICENSE"
17
+ ],
18
+ "engines": {
19
+ "node": ">=22.5.0"
20
+ },
21
+ "scripts": {
22
+ "predev": "npm run db:generate-migrations",
23
+ "dev": "npm run db:migrate:dev && concurrently \"npm run ui:dev\" \"wrangler dev\"",
24
+ "start": "npm run build && wrangler dev",
25
+ "start:serverfull": "npm run build:serverfull && node --enable-source-maps dist/serverfull.mjs",
26
+ "serverfull": "npm run build:serverfull && node --enable-source-maps dist/serverfull.mjs",
27
+ "build:serverfull": "npm run db:generate-migrations && npm run ui:build && npx esbuild src/serverfull/index.ts --bundle --platform=node --target=node24 --format=esm --outfile=dist/serverfull.mjs --banner:js=\"#!/usr/bin/env node\" --external:node:sqlite --minify --sourcemap --tree-shaking=true --legal-comments=none",
28
+ "prepublishOnly": "npm run build:serverfull",
29
+ "service-create:linux": "tsx scripts/create-linux-service.ts",
30
+ "docker:build": "tsx scripts/docker.ts build",
31
+ "docker:build:alpha": "tsx scripts/docker.ts build --alpha",
32
+ "docker:build:multiarch": "tsx scripts/docker.ts multiarch",
33
+ "docker:push": "tsx scripts/docker.ts push",
34
+ "docker:push:alpha": "tsx scripts/docker.ts push --alpha",
35
+ "docker:run": "tsx scripts/docker.ts run",
36
+ "docs:dev": "npm --prefix docs run dev",
37
+ "docs:build": "npm --prefix docs run build",
38
+ "docs:convert-tw": "npm --prefix docs run convert-tw",
39
+ "deploy": "npm run build && npm run db:migrate:prod && wrangler deploy",
40
+ "deploy:skipdb": "npm run build && wrangler deploy",
41
+ "build": "npm run ui:build",
42
+ "build:pages": "npm run db:generate-migrations && npm run ui:build && npx esbuild src/index.ts --bundle --outfile=static/_worker.js --platform=neutral --format=esm --minify --external:cloudflare:* --external:node:*",
43
+ "db:generate-migrations": "tsx scripts/generate-embedded-migrations.ts",
44
+ "prebuild": "npm run db:generate-migrations",
45
+ "prepare": "npm run db:generate-migrations && npm run ui:install",
46
+ "postinstall": "npm run db:generate-migrations",
47
+ "db:setup": "wrangler d1 create dns_worker_db",
48
+ "db:migrate:dev": "tsx scripts/migrate-dev.ts",
49
+ "db:migrate:prod": "tsx scripts/migrate-prod.ts",
50
+ "db:status": "wrangler d1 execute dns_worker_db --local --command='SELECT name FROM sqlite_master WHERE type=\"table\"'",
51
+ "pretest": "npm run db:generate-migrations",
52
+ "test": "tsx test/test_legacy_compat.ts",
53
+ "test:compat": "tsx test/test_legacy_compat.ts",
54
+ "test:turso": "tsx test/test_turso.ts",
55
+ "test:turnstile": "tsx test/test_turnstile.ts",
56
+ "test:max-users": "tsx test/test_max_users.ts",
57
+ "test:global-lists": "tsx test/test_global_lists.ts",
58
+ "test:distribute-filter": "tsx test/test_distribute_filter.ts",
59
+ "test:quad9": "tsx test/test_quad9_transport.ts",
60
+ "test:sync-optimizations": "tsx test/test_sync_optimizations.ts",
61
+ "test:serverfull": "tsx test/test_serverfull.ts",
62
+ "test:reset": "tsx test/test_serverfull_reset.ts",
63
+ "lint": "oxlint",
64
+ "ui:dev": "cd web && npm run dev",
65
+ "ui:build": "cd web && npm run build",
66
+ "ui:install": "cd web && npm install",
67
+ "tag-promote": "npm version patch",
68
+ "tag-push": "git push && git push --tags"
69
+ },
70
+ "keywords": [
71
+ "dns",
72
+ "cloudflare-workers",
73
+ "doh",
74
+ "ad-blocking",
75
+ "privacy"
76
+ ],
77
+ "author": "Hugo Koo",
78
+ "license": "AGPL-3.0-or-later",
79
+ "repository": {
80
+ "type": "git",
81
+ "url": "git+https://github.com/Obein/DNS-Worker.git"
82
+ },
83
+ "homepage": "https://github.com/Obein/DNS-Worker#readme",
84
+ "bugs": {
85
+ "url": "https://github.com/Obein/DNS-Worker/issues"
86
+ },
87
+ "devDependencies": {
88
+ "@cloudflare/workers-types": "^5.20261109.1",
89
+ "@types/node": "^26.6.6",
90
+ "concurrently": "^10.0.7",
91
+ "oxlint": "^1.92.0",
92
+ "tsx": "^4.23.15",
93
+ "typescript": "^7.0.2",
94
+ "wrangler": "^4.158.0"
95
+ },
96
+ "overrides": {
97
+ "esbuild": "^0.28.1",
98
+ "undici": "^7.30.1"
99
+ },
100
+ "dependencies": {
101
+ "@noble/post-quantum": "^0.7.1"
102
+ }
103
+ }
@@ -0,0 +1,4 @@
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};