dns-worker 1.2.4 → 1.2.5

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 (64) hide show
  1. package/dist/serverfull.mjs +159 -251
  2. package/dist/serverfull.mjs.map +4 -4
  3. package/migrations/0070_add_list_stats_metadata.sql +2 -0
  4. package/package.json +5 -5
  5. package/static/assets/{AccountView-DWLPLl2r.js → AccountView-DilMdIu2.js} +4 -4
  6. package/static/assets/AnalyticsView-mYuaq2d3.js +2 -0
  7. package/static/assets/{DestinationMap-BFN0JDey.js → DestinationMap-DfE-_-qj.js} +1 -1
  8. package/static/assets/FilteringView-Rla6nBYN.js +1 -0
  9. package/static/assets/LogsView-Bi5St4cR.js +5 -0
  10. package/static/assets/{RulesView-Cdq10tRc.js → RulesView-FQHhXpVf.js} +1 -1
  11. package/static/assets/SettingsView-gLzsNIju.js +1 -0
  12. package/static/assets/{SetupView-CLixnmKc.js → SetupView-BUA7BYMb.js} +1 -1
  13. package/static/assets/{SwipeableDrawer-UY1QWnPj.js → SwipeableDrawer-BHXXZw7l.js} +1 -1
  14. package/static/assets/SystemView-BbOt5twD.js +1 -0
  15. package/static/assets/{TrendChart-DAMeH8DG.js → TrendChart-Kzctv9EA.js} +3 -3
  16. package/static/assets/allPaths-a_Gma8ca.js +1 -0
  17. package/static/assets/allPathsLoader-sY5nfYNE.js +1 -0
  18. package/static/assets/browser-xdENJ9hN.js +1 -0
  19. package/static/assets/date-CuEX0HAJ.js +1 -0
  20. package/static/assets/de-DE-sdqvOhE2.js +25 -0
  21. package/static/assets/es-ES-CZMRaxMw.js +25 -0
  22. package/static/assets/fr-FR-2IQyivXi.js +25 -0
  23. package/static/assets/index-CxK16i2C.js +30 -0
  24. package/static/assets/index-frQljXGb.css +2 -0
  25. package/static/assets/ja-JP-CuCkEZDz.js +25 -0
  26. package/static/assets/{ko-KR--ebX4PUe.js → ko-KR-CWUU7L79.js} +1 -1
  27. package/static/assets/ru-RU-DnuUcJXU.js +25 -0
  28. package/static/assets/services-B-Y_EKlc.js +1 -0
  29. package/static/assets/splitPathsBySizeLoader-CagJEoij.js +1 -0
  30. package/static/assets/{sqlite.worker-BQk-r3bK.js → sqlite.worker-RAW9CPiV.js} +2 -2
  31. package/static/assets/{useLogsE2ee-C5IGsZNu.js → useLogsE2ee-BEETAe5O.js} +1 -1
  32. package/static/assets/vendor-i18next-J2aoF7F1.js +1 -0
  33. package/static/assets/{vendor-icons-other-BTYC6Wvz.js → vendor-icons-other-kRhgWBno.js} +2 -2
  34. package/static/assets/vendor-react-R4_BUhus.js +11 -0
  35. package/static/assets/vendor-ui-core-CKSrm0Y8.js +1 -0
  36. package/static/assets/{vendor-utils-Bab4qB3W.js → vendor-utils-y3vK_J_u.js} +1 -1
  37. package/static/assets/vi-VN-Cyv4XVb4.js +25 -0
  38. package/static/assets/zh-CN-BFVuQTvF.js +25 -0
  39. package/static/assets/zh-TW-y_EkxxXD.js +25 -0
  40. package/static/index.html +7 -7
  41. package/static/assets/AnalyticsView-DOZ_4PlV.js +0 -2
  42. package/static/assets/FilteringView-YlS6S19l.js +0 -1
  43. package/static/assets/LogsView-C5on_f9X.js +0 -5
  44. package/static/assets/SettingsView-D8Q09eFj.js +0 -1
  45. package/static/assets/SystemView-0acjSWwE.js +0 -1
  46. package/static/assets/allPaths-ZKIw3HqD.js +0 -1
  47. package/static/assets/allPathsLoader-CvGx1ejI.js +0 -1
  48. package/static/assets/browser-D1bxqOmO.js +0 -1
  49. package/static/assets/date-Mn7JuCwI.js +0 -1
  50. package/static/assets/de-DE-ChqTmNoZ.js +0 -25
  51. package/static/assets/es-ES-DJyD_FHe.js +0 -25
  52. package/static/assets/fr-FR-BA1vQe8U.js +0 -25
  53. package/static/assets/index-BlF_HYXE.css +0 -2
  54. package/static/assets/index-C--PEfmU.js +0 -30
  55. package/static/assets/ja-JP-ndkxicCP.js +0 -25
  56. package/static/assets/ru-RU-DOZjzIx2.js +0 -25
  57. package/static/assets/services-DTfjQuNl.js +0 -1
  58. package/static/assets/splitPathsBySizeLoader-htHoS0DT.js +0 -1
  59. package/static/assets/vendor-i18next-DlmslyBB.js +0 -1
  60. package/static/assets/vendor-react-DYK5a2J9.js +0 -11
  61. package/static/assets/vendor-ui-core-CodM8CpF.js +0 -1
  62. package/static/assets/vi-VN-DgVTajq8.js +0 -25
  63. package/static/assets/zh-CN-C_Po-z3K.js +0 -25
  64. package/static/assets/zh-TW-C4h6ckgV.js +0 -25
@@ -0,0 +1,2 @@
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/TrendChart-Kzctv9EA.js","assets/index-CxK16i2C.js","assets/vendor-icons-other-kRhgWBno.js","assets/vendor-icons-16-BgwRBCeU.js","assets/rolldown-runtime-C4Xdq4VV.js","assets/vendor-icons-20-X5NPN60g.js","assets/vendor-react-R4_BUhus.js","assets/vendor-i18next-J2aoF7F1.js","assets/vendor-ui-core-CKSrm0Y8.js","assets/vendor-utils-y3vK_J_u.js","assets/index-frQljXGb.css","assets/DestinationMap-DfE-_-qj.js","assets/formatCountryName-C6cFVUu2.js","assets/getFlagEmoji-Cd2A891A.js"])))=>i.map(i=>d[i]);
2
+ import{i as e}from"./rolldown-runtime-C4Xdq4VV.js";import{$ as t,Ct as n,O as r,X as i,it as a,j as o,rn as s,v as c,z as l}from"./vendor-react-R4_BUhus.js";import{S as u,b as d,x as f}from"./vendor-icons-other-kRhgWBno.js";import"./vendor-i18next-J2aoF7F1.js";import{E as p,F as m,H as h,N as g,P as _,S as v,U as y,d as b,f as x,o as S,p as C,r as w,u as T,w as E}from"./vendor-ui-core-CKSrm0Y8.js";import{_t as D}from"./vendor-utils-y3vK_J_u.js";import{T as O,ht as k,j as A,mt as j,pt as M,vn as N}from"./index-CxK16i2C.js";import{t as P}from"./getFlagEmoji-Cd2A891A.js";import{i as F,n as I,r as L,t as R}from"./useLogsE2ee-BEETAe5O.js";var z=e(u(),1);function B(e,t,n){if(!e)return[];let r={},i=Math.floor(Date.now()/1e3),a,o;switch(t){case`10m`:o=60,a=i-600;break;case`1h`:o=60,a=i-3600;break;case`24h`:o=3600,a=i-24*3600;break;case`7d`:o=86400,a=i-7*86400;break;case`30d`:o=86400,a=i-30*86400;break;case`custom`:if(o=3600,n.start&&n.end)a=Math.floor(new Date(n.start).getTime()/1e3),i=Math.floor(new Date(n.end).getTime()/1e3);else{let t=e.trend.map(e=>e.timestamp);a=t.length?Math.min(...t):i-86400,i=t.length?Math.max(...t):i}break;default:o=60,a=i-3600}a=Math.floor(a/o)*o,i=Math.floor(i/o)*o;for(let e=a;e<=i;e+=o)r[e]={timestamp:e,allowed:0,blocked:0,redirected:0};return e.trend.forEach(e=>{let t=Math.floor(e.timestamp/o)*o;r[t]||(r[t]={timestamp:t,allowed:0,blocked:0,redirected:0}),e.action===`PASS`?r[t].allowed+=e.count:e.action===`BLOCK`?r[t].blocked+=e.count:e.action===`REDIRECT`&&(r[t].redirected+=e.count)}),Object.keys(r).sort((e,t)=>Number(e)-Number(t)).map(e=>r[Number(e)])}var V=e(d(),1);const H=({title:e,data:n,intent:r})=>{let{t:i}=s(),a=[{key:`rank`,cellClassName:`w-8 opacity-30 font-mono text-xs`,render:(e,t)=>t+1},{key:`domain`,cellClassName:`font-medium text-sm truncate max-w-50`,render:e=>e.domain===`[Encrypted]`?(0,V.jsxs)(`span`,{className:`inline-flex items-center gap-1.5 text-gray-400 dark:text-gray-500 italic font-normal`,children:[(0,V.jsx)(t,{size:14,className:`text-amber-500 shrink-0`}),(0,V.jsx)(`span`,{children:i(`logs.encryptedRecord`,`[加密记录]`)})]}):e.domain===`[Decryption Failed]`?(0,V.jsxs)(`span`,{className:`inline-flex items-center gap-1.5 text-red-400 dark:text-red-500 italic font-normal`,children:[(0,V.jsx)(t,{size:14,className:`text-red-500 shrink-0`}),(0,V.jsx)(`span`,{children:i(`logs.decryptionFailed`,`[解密失败]`)})]}):e.domain},{key:`count`,cellClassName:`text-right`,render:e=>(0,V.jsx)(w,{minimal:!0,intent:r,className:`font-bold`,children:e.count})}];return(0,V.jsxs)(v,{elevation:y.ZERO,className:`dark:bg-gray-900 dark:border-gray-800 border border-gray-100 shadow-sm`,children:[(0,V.jsx)(g,{className:`mb-4 font-bold`,children:e}),(0,V.jsx)(T,{striped:!0,className:`w-full`,children:(0,V.jsxs)(`tbody`,{children:[n.map((e,t)=>(0,V.jsx)(`tr`,{children:a.map(n=>(0,V.jsx)(`td`,{className:n.cellClassName,children:n.render(e,t)},n.key))},t)),n.length===0&&(0,V.jsx)(`tr`,{children:(0,V.jsx)(`td`,{colSpan:a.length,className:`text-center py-8 opacity-50`,children:i(`analytics.noData`)})})]})})]})},U=new class{cache=new Map;MAX_ENTRIES=50;buildKey(e,t,n,r,i){return`${e}|${t}|${n||``}|${r||``}|${i||`all`}`}getTtlConfig(e,t){if(e===`custom`&&t&&Date.now()-new Date(t).getTime()>2*3600*1e3)return{staleAfterMs:1800*1e3,ttlMs:3600*1e3};switch(e){case`10m`:case`1h`:return{staleAfterMs:30*1e3,ttlMs:60*1e3};case`24h`:return{staleAfterMs:120*1e3,ttlMs:300*1e3};case`7d`:case`30d`:return{staleAfterMs:300*1e3,ttlMs:900*1e3};default:return{staleAfterMs:60*1e3,ttlMs:120*1e3}}}get(e){let t=this.cache.get(e);if(!t)return null;let n=Date.now()-t.timestamp;return n>t.ttlMs?(this.cache.delete(e),null):{data:t.data,isStale:n>t.staleAfterMs}}set(e,t,n,r){if(this.cache.size>=this.MAX_ENTRIES){let e=this.cache.keys().next().value;e&&this.cache.delete(e)}let{ttlMs:i,staleAfterMs:a}=this.getTtlConfig(n,r);this.cache.set(e,{data:t,timestamp:Date.now(),ttlMs:i,staleAfterMs:a})}invalidateProfile(e){for(let t of Array.from(this.cache.keys()))t.startsWith(`${e}|`)&&this.cache.delete(t)}clear(){this.cache.clear()}};function W(e,t,n,r){let i=r??Math.floor(Date.now()/1e3);if(e===`custom`&&t&&n){let e=Math.floor(new Date(t).getTime()/1e3),r=Math.floor(new Date(n).getTime()/1e3),i=Math.max(0,r-e);return{since:e,until:r,bucketSec:i<=7200?60:i<=172800?3600:86400}}switch(e){case`10m`:return{since:i-600,until:i,bucketSec:60};case`1h`:return{since:i-3600,until:i,bucketSec:60};case`24h`:return{since:i-86400,until:i,bucketSec:3600};case`7d`:return{since:i-604800,until:i,bucketSec:86400};case`30d`:return{since:i-2592e3,until:i,bucketSec:86400};default:return{since:i-3600,until:i,bucketSec:60}}}function G(e,t,n){let r=`?range=${e}`;return e===`custom`&&(r+=`&start=${t.since}&end=${t.until}`),n&&(r+=`&access_point_id=${encodeURIComponent(n)}`),r}function K(e){return!e||e.length===0?!1:e.some(e=>!!e.client_ip&&e.client_ip!==`[Encrypted]`&&e.client_ip!==`[Decryption Failed]`)}function q(e){return!e||e.length===0?!1:e.some(e=>!!e.domain&&e.domain!==`[Encrypted]`&&e.domain!==`[Decryption Failed]`)}function J(e){return{serverHasValidClients:K(e.clients),serverHasValidTopAllowed:q(e.top_allowed),serverHasValidTopBlocked:q(e.top_blocked),serverHasDestinations:(e.destinations||[]).length>0}}function Y(e,t,n){return{...e,trend:e.trend||[],summary:e.summary||[],top_allowed:n.serverHasValidTopAllowed?e.top_allowed:t?.top_allowed?.length?t.top_allowed:e.top_allowed||[],top_blocked:n.serverHasValidTopBlocked?e.top_blocked:t?.top_blocked?.length?t.top_blocked:e.top_blocked||[],clients:n.serverHasValidClients?e.clients:t?.clients?.length?t.clients:e.clients||[],destinations:n.serverHasDestinations?e.destinations:t?.destinations&&t.destinations.length>0?t.destinations:[]}}function X(e){return!e||e.length===0?0:e.reduce((e,t)=>e+(Number(t.count)||0),0)}function Z(e,t,n){if(!e)return t;let r=(e,t,n)=>n.length===0?t:e?X(n)>X(t)?n:t:n;return{...e,destinations:r(n.serverHasDestinations,e.destinations,t.destinations),top_allowed:r(n.serverHasValidTopAllowed,e.top_allowed,t.top_allowed),top_blocked:r(n.serverHasValidTopBlocked,e.top_blocked,t.top_blocked),clients:r(n.serverHasValidClients,e.clients,t.clients)}}function Q(e){let[t,n]=(0,z.useState)([]),[r,i]=(0,z.useState)(30);return(0,z.useEffect)(()=>{let t=!0;return M(e).then(e=>{t&&n(e)}).catch(e=>console.error(`[useProfileMetadata] Failed to load access points:`,e)),()=>{t=!1}},[e]),(0,z.useEffect)(()=>{let t=!0;return k(e).then(e=>{if(t)try{let t=JSON.parse(e.settings||`{}`);i(t.log_retention_days===void 0?30:Number(t.log_retention_days))}catch(e){console.error(`[useProfileMetadata] Failed to parse settings:`,e)}}).catch(e=>console.error(`[useProfileMetadata] Failed to fetch profile settings:`,e)),()=>{t=!1}},[e]),{accessPoints:t,logRetentionDays:r}}function ee({profileId:e,range:t,customRange:n,accessPointIdFilter:r,toasterRef:i,onRefreshLocal:a}){let{t:o}=s(),[c,l]=(0,z.useState)(!1),[u,d]=(0,z.useState)(0),f=(0,z.useRef)(null),p=(0,z.useRef)(null);return(0,z.useEffect)(()=>()=>{f.current?.abort()},[]),{syncing:c,syncProgress:u,syncTargetRange:(0,z.useCallback)(async()=>{if(c)return;let s=Math.floor(Date.now()/1e3),u=p.current;if(u!==null&&u.range===t&&u.accessPointId===r&&(t!==`custom`||u.customStart===n.start&&u.customEnd===n.end)&&s-u.completedAt<30){i?.current?.show({message:o(`analytics.syncAlreadyUpToDate`,`本地记录已是最新`),intent:h.PRIMARY,icon:`tick`});return}l(!0),d(.05),f.current?.abort();let m=new AbortController;f.current=m;let g=m.signal,_=W(t,n.start,n.end,s);try{let s=await O.syncTargetInterval(e,_.since,_.until,g,e=>{g.aborted||(d(e),a(_))});g.aborted||(p.current={range:t,customStart:n.start,customEnd:n.end,accessPointId:r,completedAt:Math.floor(Date.now()/1e3)},U.invalidateProfile(e),s===0?i?.current?.show({message:o(`analytics.syncAlreadyUpToDate`,`本地记录已是最新`),intent:h.PRIMARY,icon:`tick`}):(d(1),await a(_),i?.current?.show({message:o(`analytics.syncSuccess`,`本地记录同步完成`),intent:h.SUCCESS,icon:`tick`}),await new Promise(e=>setTimeout(e,600))))}catch(e){e?.name!==`AbortError`&&!g.aborted&&(console.error(`[useAnalyticsSync] Manual sync error:`,e),i?.current?.show({message:o(`analytics.syncFailed`,`本地记录同步失败`),intent:h.DANGER,icon:`error`}))}finally{l(!1),d(0)}},[e,t,n,r,c,i,o,a]),stopSync:(0,z.useCallback)(()=>{f.current&&=(f.current.abort(),null),l(!1),d(0),i?.current?.show({message:o(`analytics.syncStopped`,`同步已停止`),intent:h.WARNING,icon:`stop`})},[i,o])}}function te(e,t){let[n,r]=(0,z.useState)(null),[i,a]=(0,z.useState)(!0),[o,s]=(0,z.useState)(`1h`),[c,l]=(0,z.useState)({start:``,end:``}),[u,d]=(0,z.useState)(null),f=(0,z.useRef)(null),p=(0,z.useRef)({serverHasValidClients:!1,serverHasValidTopAllowed:!1,serverHasValidTopBlocked:!1,serverHasDestinations:!1}),{accessPoints:m,logRetentionDays:h}=Q(e);(0,z.useEffect)(()=>()=>{f.current?.abort()},[]);let{syncing:g,syncProgress:_,syncTargetRange:v,stopSync:y}=ee({profileId:e,range:o,customRange:c,accessPointIdFilter:u,toasterRef:t,onRefreshLocal:(0,z.useCallback)(async t=>{try{let n=await O.queryAnalytics({profileId:e,since:t.since,until:t.until,bucketSec:t.bucketSec,accessPointId:u||void 0});r(e=>Z(e,n,p.current))}catch{}},[e,u])}),b=(0,z.useCallback)(async(t,n,i,o,s=!1)=>{f.current?.abort();let c=new AbortController;f.current=c;let l=c.signal,u=U.buildKey(e,t,n,i,o);if(s)U.invalidateProfile(e);else{let e=U.get(u);if(e&&!l.aborted&&(r(e.data),a(!1),!e.isStale))return}a(!0);let d=W(t,n,i);try{(A.isProfileUnlocked(e)||A.isUnlocked())&&await O.reDecryptLocalLogs(e)}catch{}try{if(await O.init()&&!l.aborted){let t=await O.queryAnalytics({profileId:e,since:d.since,until:d.until,bucketSec:d.bucketSec,accessPointId:o||void 0});t.summary.some(e=>e.count>0)&&!l.aborted&&(r(t),a(!1))}}catch(e){console.warn(`[useAnalyticsData] Local SQLite preview failed:`,e)}let m;try{let n=G(t,d,o),a=null;try{a=await j(e,``,n)}catch{if(l.aborted)return;let[t,r,i,o,s,c]=await Promise.all([j(e,`summary`,n),j(e,`trend`,n),j(e,`top_allowed`,n),j(e,`top_blocked`,n),j(e,`clients`,n),j(e,`destinations`,n)]);a={summary:t,trend:r,top_allowed:i,top_blocked:o,clients:s,destinations:c}}if(a&&!l.aborted){m=(a.summary||[]).reduce((e,t)=>e+(t.count||0),0);let e=J(a);p.current=e,r(n=>{let r=Y(a,n,e);return U.set(u,r,t,i),r})}}catch(e){l.aborted||console.error(`[useAnalyticsData] Failed to fetch server analytics:`,e)}finally{l.aborted||a(!1)}try{let n=A.isProfileUnlocked(e)||A.isUnlocked(),a=async()=>{if(!l.aborted)try{let n=await O.queryAnalytics({profileId:e,since:d.since,until:d.until,bucketSec:d.bucketSec,accessPointId:o||void 0});l.aborted||r(e=>{let r=Z(e,n,p.current);return U.set(u,r,t,i),r})}catch{}},s=await O.syncMissingIntervals(e,d.since,d.until,l,()=>{a()},m);!l.aborted&&(s>0||n)&&await a()}catch(e){e?.name!==`AbortError`&&console.warn(`[useAnalyticsData] Missing intervals sync error:`,e)}},[e]);return(0,z.useEffect)(()=>{o!==`custom`&&b(o,void 0,void 0,u)},[o,u,b]),{data:n,loading:i,syncing:g,syncProgress:_,range:o,setRange:s,customRange:c,setCustomRange:l,accessPointIdFilter:u,setAccessPointIdFilter:d,accessPoints:m,logRetentionDays:h,fetchData:b,syncTargetRange:v,stopSync:y}}var ne=[{key:`10m`,days:.007},{key:`1h`,days:.0416},{key:`24h`,days:1},{key:`7d`,days:7},{key:`30d`,days:30}];const re=({range:e,setRange:t,customRange:r,setCustomRange:i,logRetentionDays:a,accessPoints:o,accessPointIdFilter:c,setAccessPointIdFilter:l,loading:u,onApplyCustom:d})=>{let{t:f}=s(),v=new Date().toLocaleString(`sv-SE`).replace(` `,`T`).slice(0,16);return(0,V.jsxs)(`div`,{className:`flex justify-between items-center bg-white dark:bg-gray-900 p-2 rounded-lg shadow-sm border border-gray-100 dark:border-gray-800`,children:[(0,V.jsxs)(E,{variant:`minimal`,children:[ne.filter(e=>e.days<=a).map(e=>e.key).map(n=>(0,V.jsx)(_,{active:e===n,onClick:()=>t(n),text:n.toUpperCase()},n)),(0,V.jsx)(p,{content:(0,V.jsxs)(`div`,{className:`p-4 space-y-4 w-64`,children:[(0,V.jsx)(g,{children:f(`analytics.customRange`)}),(0,V.jsx)(C,{label:f(`analytics.startTime`),children:(0,V.jsx)(x,{type:`datetime-local`,max:r.end||v,value:r.start,onChange:e=>i({...r,start:e.target.value})})}),(0,V.jsx)(C,{label:f(`analytics.endTime`),children:(0,V.jsx)(x,{type:`datetime-local`,min:r.start,max:v,value:r.end,onChange:e=>i({...r,end:e.target.value})})}),(0,V.jsx)(_,{fill:!0,intent:h.PRIMARY,text:f(`analytics.apply`),onClick:d})]}),children:(0,V.jsx)(_,{active:e===`custom`,icon:(0,V.jsx)(n,{size:14,className:`mr-1`}),text:f(`analytics.custom`)})})]}),(0,V.jsxs)(`div`,{className:`flex items-center gap-2`,children:[o.length>0&&(0,V.jsx)(b,{value:c||``,onChange:e=>l(e.target.value||null),options:[{label:`${f(`logs.allAccessPoint`)}`,value:``},...o.map(e=>({label:e.name,value:e.id}))],minimal:!0}),u&&(0,V.jsx)(m,{size:16})]})]})},ie=({title:e,value:t,icon:n})=>(0,V.jsxs)(v,{elevation:y.ZERO,className:`flex items-center gap-4 p-4 dark:bg-gray-900 dark:border-gray-800 border border-gray-100 shadow-sm`,children:[(0,V.jsx)(`div`,{className:`p-3 bg-gray-50 dark:bg-gray-800 rounded-lg`,children:n}),(0,V.jsxs)(`div`,{children:[(0,V.jsx)(`div`,{className:`text-xs text-gray-500 font-medium uppercase tracking-wider`,children:e}),(0,V.jsx)(`div`,{className:`text-xl font-bold dark:text-white`,children:t})]})]}),ae=({data:e})=>{let{t}=s(),n=e?.summary.reduce((e,t)=>e+t.count,0)||0,i=e?.summary.find(e=>e.action===`BLOCK`)?.count||0,u=e?.summary.find(e=>e.action===`REDIRECT`)?.count||0,d=n>0?(i/n*100).toFixed(1):`0.0`;return(0,V.jsx)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-5 gap-2 lg:gap-4`,children:[{title:t(`analytics.totalQueries`),value:n.toLocaleString(),icon:(0,V.jsx)(c,{className:`text-blue-500`,size:20})},{title:t(`analytics.blocked`),value:i.toLocaleString(),icon:(0,V.jsx)(o,{className:`text-red-500`,size:20})},{title:t(`analytics.redirected`),value:u.toLocaleString(),icon:(0,V.jsx)(l,{className:`text-amber-500`,size:20})},{title:t(`analytics.blockRate`),value:`${d}%`,icon:(0,V.jsx)(r,{className:`text-green-500`,size:20})},{title:t(`analytics.activeIPs`),value:e?.clients.length.toString()||`0`,icon:(0,V.jsx)(a,{className:`text-purple-500`,size:20})}].map((e,t)=>(0,V.jsx)(ie,{title:e.title,value:e.value,icon:e.icon},t))})},oe=({clients:e})=>{let{t:n}=s();return(0,V.jsx)(S,{title:n(`analytics.clientActivity`),icon:(0,V.jsx)(a,{size:16}),children:(0,V.jsxs)(T,{striped:!0,className:`w-full mt-2`,children:[(0,V.jsx)(`thead`,{children:(0,V.jsxs)(`tr`,{children:[(0,V.jsx)(`th`,{className:`text-xs uppercase opacity-60`,children:n(`analytics.ipAddress`)}),(0,V.jsx)(`th`,{className:`text-xs uppercase opacity-60`,children:n(`analytics.location`)}),(0,V.jsx)(`th`,{className:`text-xs uppercase opacity-60 text-right`,children:n(`analytics.queries`)})]})}),(0,V.jsxs)(`tbody`,{children:[e?.map((e,r)=>(0,V.jsxs)(`tr`,{children:[(0,V.jsx)(`td`,{className:`font-mono text-xs`,children:e.client_ip===`[Encrypted]`?(0,V.jsxs)(`span`,{className:`inline-flex items-center gap-1.5 text-gray-400 dark:text-gray-500 italic`,children:[(0,V.jsx)(t,{size:12,className:`text-amber-500 shrink-0`}),(0,V.jsx)(`span`,{children:n(`logs.encryptedRecord`,`[加密记录]`)})]}):e.client_ip===`[Decryption Failed]`?(0,V.jsxs)(`span`,{className:`inline-flex items-center gap-1.5 text-red-400 dark:text-red-500 italic`,children:[(0,V.jsx)(t,{size:12,className:`text-red-500 shrink-0`}),(0,V.jsx)(`span`,{children:n(`logs.decryptionFailed`,`[解密失败]`)})]}):e.client_ip||`-`}),(0,V.jsx)(`td`,{children:(0,V.jsx)(w,{minimal:!0,children:P(e.geo_country)})}),(0,V.jsx)(`td`,{className:`text-right font-bold`,children:e.count})]},r)),(!e||e.length===0)&&(0,V.jsx)(`tr`,{children:(0,V.jsx)(`td`,{colSpan:3,className:`text-center py-8 opacity-50`,children:n(`analytics.noData`)})})]})]})})};var se=(0,z.lazy)(()=>f(()=>import(`./TrendChart-Kzctv9EA.js`),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10])).then(e=>({default:e.TrendChart}))),ce=(0,z.lazy)(()=>f(()=>import(`./DestinationMap-DfE-_-qj.js`),__vite__mapDeps([11,1,2,3,4,5,6,7,8,9,10,12,13])).then(e=>({default:e.DestinationMap}))),$=()=>(0,V.jsx)(`div`,{className:`h-64 flex items-center justify-center`,children:(0,V.jsx)(m,{size:30})});const le=({profileId:e,toasterRef:t})=>{let{t:n}=s(),r=N(),{data:a,loading:o,range:c,setRange:l,customRange:u,setCustomRange:d,accessPointIdFilter:f,setAccessPointIdFilter:p,accessPoints:_,logRetentionDays:b,fetchData:x}=te(e,t),{isE2eeEnabled:C,isE2eeUnlocked:T,unlocking:E,recoveryDialogOpen:O,setRecoveryDialogOpen:k,recoveryKeyInput:A,setRecoveryKeyInput:j,recoveryError:M,setRecoveryError:P,rotatedKey:U,setRotatedKey:W,copiedKey:G,handleCopyRotatedKey:K,handleUnlockPasskey:q,handleUnlockRecoveryKey:J}=R({profileId:e,range:c,onUnlocked:()=>{x(c,u.start,u.end,f)},toasterRef:t}),Y=!!(a&&(a.top_allowed?.some(e=>e.domain===`[Encrypted]`)||a.top_blocked?.some(e=>e.domain===`[Encrypted]`)||a.clients?.some(e=>e.client_ip===`[Encrypted]`)));if(o&&!a)return(0,V.jsx)(`div`,{className:`p-20 flex justify-center`,children:(0,V.jsx)(m,{size:50})});let X=B(a,c,u);return(0,V.jsxs)(`div`,{className:D(`max-w-7xl mx-auto space-y-6`,r?`p-0`:`p-6`),children:[(0,V.jsx)(re,{range:c,setRange:l,customRange:u,setCustomRange:d,logRetentionDays:b,accessPoints:_,accessPointIdFilter:f,setAccessPointIdFilter:p,loading:o,onApplyCustom:()=>{l(`custom`),x(`custom`,u.start,u.end,f)}}),(C||Y)&&!T&&(0,V.jsx)(F,{isMobile:r,unlocking:E,onUnlockPasskey:q,onOpenRecoveryDialog:()=>{P(``),j(``),k(!0)}}),(0,V.jsx)(ae,{data:a}),(0,V.jsxs)(v,{elevation:y.ONE,className:`dark:bg-gray-900 dark:border-gray-800 relative`,children:[(0,V.jsxs)(g,{className:`mb-4 font-bold flex items-center gap-2`,children:[n(`analytics.queryTrend`),(0,V.jsx)(w,{minimal:!0,round:!0,children:c===`custom`?n(`analytics.custom`):c.toUpperCase()})]}),(0,V.jsx)(z.Suspense,{fallback:(0,V.jsx)($,{}),children:(0,V.jsx)(se,{chartData:X,range:c})})]}),(0,V.jsxs)(`div`,{className:`grid grid-cols-1 lg:grid-cols-2 gap-6`,children:[(0,V.jsx)(H,{title:n(`analytics.topAllowed`),data:a?.top_allowed||[],intent:h.SUCCESS}),(0,V.jsx)(H,{title:n(`analytics.topBlocked`),data:a?.top_blocked||[],intent:h.DANGER})]}),(0,V.jsxs)(`div`,{className:`grid gap-6 grid-cols-1`,children:[(0,V.jsx)(S,{title:n(`analytics.destinationDistribution`),icon:(0,V.jsx)(i,{size:16}),children:(0,V.jsx)(z.Suspense,{fallback:(0,V.jsx)($,{}),children:(0,V.jsx)(ce,{destinations:a?.destinations||[],profileId:e||``,range:c,customRange:u,accessPointId:f||void 0})})}),(0,V.jsx)(oe,{clients:a?.clients})]}),(0,V.jsx)(L,{isOpen:O,onClose:()=>k(!1),recoveryKeyInput:A,setRecoveryKeyInput:j,recoveryError:M,unlocking:E,onSubmit:J}),(0,V.jsx)(I,{rotatedKey:U,onClose:()=>W(null),copiedKey:G,onCopyKey:K})]})};export{le as AnalyticsView};
@@ -1 +1 @@
1
- import{i as e}from"./rolldown-runtime-C4Xdq4VV.js";import{_ as t,d as n,f as r,g as i,i as a,m as o,nn as s,p as c,r as l,u,y as d,z as f}from"./vendor-react-DYK5a2J9.js";import{S as p,b as m}from"./vendor-icons-other-BTYC6Wvz.js";import"./vendor-i18next-DlmslyBB.js";import"./vendor-utils-Bab4qB3W.js";import{G as h,T as g,mt as _}from"./index-C--PEfmU.js";import{n as v,t as y}from"./formatCountryName-C6cFVUu2.js";import{t as b}from"./getFlagEmoji-Cd2A891A.js";var x=e(p(),1);function S(e){let[t,n]=(0,x.useState)(null);(0,x.useEffect)(()=>{h().then(e=>{if(e&&e.objects){let t={};e.objects.countries&&(t.countries=e.objects.countries),e.objects.land&&(t.land=e.objects.land),e.objects=t}e&&e.objects&&e.objects.countries&&Array.isArray(e.objects.countries.geometries)&&e.objects.countries.geometries.forEach(e=>{e.id!==void 0&&e.id!==null&&(e.id=String(e.id).padStart(3,`0`))}),n(e)}).catch(e=>console.error(`Failed to load map topology`,e))},[]);let r=(0,x.useMemo)(()=>e.reduce((e,t)=>e+(Number(t.count)||0),0),[e]),i=(0,x.useMemo)(()=>{if(r<=0)return{maxThreshold:10,step:1};if(r<=1e3)return{maxThreshold:100,step:10};let e=10**Math.floor(Math.log10(r));return{maxThreshold:e,step:e/10}},[r]);return{geographyData:t,destinationMap:(0,x.useMemo)(()=>{let t={};return e.forEach(e=>{if(e.country_code){let n=e.country_code.toUpperCase(),r=Number(e.count)||0;t[n]?(t[n].count+=r,(!t[n].name||t[n].name===`Unknown`)&&e.country&&e.country!==`Unknown`&&(t[n].name=e.country)):t[n]={count:r,name:e.country,countryCode:n}}}),t},[e]),scaleConfig:i,getLevel:e=>!e||e<=0?0:Math.min(10,Math.floor(e/i.step)+1),formatNumber:e=>{if(e>=1e6){let t=e/1e6;return Number.isInteger(t)?`${t}M`:`${t.toFixed(1)}M`}if(e>=1e3){let t=e/1e3;return Number.isInteger(t)?`${t}K`:`${t.toFixed(1)}K`}return e.toString()}}}var C=e(m(),1);const w=({onZoomIn:e,onZoomOut:n,onReset:r})=>(0,C.jsxs)(`div`,{className:`absolute top-3 right-3 flex flex-col gap-1.5 bg-white/80 dark:bg-slate-950/80 backdrop-blur-md p-1.5 rounded-lg border border-gray-200/50 dark:border-slate-800/50 shadow-sm z-10`,children:[(0,C.jsx)(`button`,{type:`button`,onClick:e,className:`p-1.5 hover:bg-gray-100 dark:hover:bg-slate-800 rounded text-gray-600 dark:text-gray-300 transition-colors cursor-pointer`,title:`Zoom In`,children:(0,C.jsx)(t,{size:16})}),(0,C.jsx)(`button`,{type:`button`,onClick:n,className:`p-1.5 hover:bg-gray-100 dark:hover:bg-slate-800 rounded text-gray-600 dark:text-gray-300 transition-colors cursor-pointer`,title:`Zoom Out`,children:(0,C.jsx)(i,{size:16})}),(0,C.jsx)(`button`,{type:`button`,onClick:r,className:`p-1.5 hover:bg-gray-100 dark:hover:bg-slate-800 rounded text-gray-600 dark:text-gray-300 transition-colors cursor-pointer`,title:`Reset Zoom`,children:(0,C.jsx)(f,{size:16})})]}),T=({maxThreshold:e,formatNumber:t})=>{let{t:n}=s();return(0,C.jsxs)(`div`,{className:`sm:absolute sm:bottom-3 sm:left-3 relative m-3 sm:m-0 flex flex-col shrink-0 gap-1.5 bg-white/80 dark:bg-slate-950/80 backdrop-blur-md p-2 rounded-lg border border-gray-200/50 dark:border-slate-800/50 shadow-sm z-10 max-w-70`,children:[(0,C.jsx)(`span`,{className:`text-[9px] font-bold text-gray-500 dark:text-gray-400 uppercase tracking-wider`,children:n(`analytics.queries`)}),(0,C.jsx)(`div`,{className:`flex items-center gap-0.5`,children:Array.from({length:11}).map((e,t)=>(0,C.jsx)(`div`,{className:`w-4 h-2.5 rounded-sm border border-black/5 dark:border-white/5`,style:{backgroundColor:`var(--map-color-${t})`}},t))}),(0,C.jsxs)(`div`,{className:`flex justify-between text-[9px] text-gray-500 dark:text-gray-400 font-semibold px-0.5`,children:[(0,C.jsx)(`span`,{children:`0`}),(0,C.jsx)(`span`,{children:t(e/2)}),(0,C.jsxs)(`span`,{children:[t(e),`+`]})]})]})},E=({name:e,count:t,flag:n,x:r,y:i,countryCode:a,profileId:o,range:c,customRange:l,accessPointId:u,ispCache:f,onCacheIsp:p,isPinned:m,onClose:h})=>{let{t:v}=s(),y=(0,x.useRef)(null),[b,S]=(0,x.useState)({left:r,top:i-10,alignBottom:!1}),[w,T]=(0,x.useState)([]),[E,D]=(0,x.useState)(!1),O=(0,x.useRef)(f);O.current=f;let k=(0,x.useRef)(p);return k.current=p,(0,x.useEffect)(()=>{if(!a||!o)return;if(t<=0){T([]),D(!1);return}let e=O.current[a];if(e){T(e),D(!1);return}D(!0);let n=Math.floor(Date.now()/1e3),r,i=n,s=`?country_code=${a}&range=${c}`;if(c===`custom`&&l.start&&l.end)r=Math.floor(new Date(l.start).getTime()/1e3),i=Math.floor(new Date(l.end).getTime()/1e3),s+=`&start=${r}&end=${i}`;else switch(c){case`10m`:r=n-600;break;case`1h`:r=n-3600;break;case`24h`:r=n-86400;break;case`7d`:r=n-604800;break;case`30d`:r=n-2592e3;break;default:r=n-3600;break}u&&(s+=`&access_point_id=${u}`);let d=!0,f=setTimeout(async()=>{let e=[],n=0;try{let r=await _(o,`isps`,s),i=Array.isArray(r)?r:[];if(i.length>0&&(e=i,n=i.reduce((e,t)=>e+(Number(t.count)||0),0),n>=t)){k.current(a,i),d&&(T(i),D(!1));return}}catch(e){console.debug(`[MapTooltip] Server ISP fetch failed, trying local DB fallback:`,e)}try{let t=await g.queryISPs({profileId:o,countryCode:a,since:r,until:i,accessPointId:u||void 0});t&&t.length>0&&t.reduce((e,t)=>e+(Number(t.count)||0),0)>n&&(e=t)}catch(e){console.warn(`[MapTooltip] Local SQLite ISP query failed:`,e)}finally{d&&(e.length>0&&(k.current(a,e),T(e)),D(!1))}},150);return()=>{d=!1,clearTimeout(f)}},[a,o,c,l,u,t]),(0,x.useEffect)(()=>{if(!m)return;let e=e=>{if(y.current&&!y.current.contains(e.target)){let t=e.target,n=t.classList.contains(`rsm-geography`)||t.closest(`.rsm-geography`),r=t.classList.contains(`map-marker-circle`)||t.closest(`.map-marker-circle`);!n&&!r&&h()}},t=setTimeout(()=>{document.addEventListener(`click`,e,!0)},0);return()=>{clearTimeout(t),document.removeEventListener(`click`,e,!0)}},[m,h]),(0,x.useLayoutEffect)(()=>{if(!y.current)return;let e=y.current.getBoundingClientRect(),t=y.current.parentElement;if(!t)return;let n=t.getBoundingClientRect(),a=r,o=e.width/2;r-o<4?a=o+4:r+o>n.width-4&&(a=n.width-o-4);let s=i-10,c=!1;i-e.height-15<4&&(s=i+15,c=!0),S({left:a,top:s,alignBottom:c})},[r,i,w]),(0,C.jsxs)(`div`,{ref:y,onMouseLeave:m?h:void 0,className:`absolute bg-white/95 dark:bg-slate-900/95 backdrop-blur-sm px-3 py-2 rounded-lg shadow-xl border border-gray-200/50 dark:border-slate-800/50 text-xs z-50 flex flex-col gap-1 transition-all duration-75 text-gray-900 dark:text-gray-100 ${m?`pointer-events-auto cursor-default`:`pointer-events-none`}`,style:{left:`${b.left}px`,top:`${b.top}px`,transform:b.alignBottom?`translate(-50%, 0)`:`translate(-50%, -100%)`},children:[(0,C.jsxs)(`div`,{className:`flex items-center justify-between gap-4`,children:[(0,C.jsxs)(`div`,{className:`flex flex-col gap-0.5`,children:[(0,C.jsxs)(`div`,{className:`flex items-center gap-1.5 font-semibold whitespace-nowrap`,children:[(0,C.jsx)(`span`,{className:`text-sm`,children:n}),(0,C.jsx)(`span`,{children:e})]}),(0,C.jsxs)(`div`,{className:`text-gray-500 dark:text-gray-400 whitespace-nowrap`,children:[t.toLocaleString(),` `,v(`analytics.queries`)]})]}),m&&(0,C.jsx)(`button`,{onClick:e=>{e.stopPropagation(),h()},className:`flex items-center justify-center p-2 rounded-lg border border-gray-200 dark:border-slate-800 text-gray-500 hover:text-red-500 hover:bg-red-50 dark:hover:bg-red-950/20 hover:border-red-200 dark:hover:border-red-900/50 transition-colors cursor-pointer self-stretch aspect-square`,title:v(`common.close`,`Close`),children:(0,C.jsx)(d,{size:18})})]}),E?(0,C.jsxs)(`div`,{className:`mt-1.5 pt-1.5 border-t border-gray-150 dark:border-slate-850 flex flex-col gap-1 min-w-36`,children:[(0,C.jsx)(`div`,{className:`text-[10px] uppercase font-bold text-gray-400 dark:text-gray-500 tracking-wider`,children:v(`analytics.topIsps`,`Top ISPs`)}),(0,C.jsx)(`div`,{className:`text-[11px] text-gray-400 dark:text-gray-500 italic`,children:v(`analytics.loading`,`Loading...`)})]}):w.length>0&&(0,C.jsxs)(`div`,{className:`mt-1.5 pt-1.5 border-t border-gray-150 dark:border-slate-800 flex flex-col gap-1`,children:[(0,C.jsx)(`div`,{className:`text-[10px] uppercase font-bold text-gray-400 dark:text-gray-500 tracking-wider`,children:v(`analytics.topIsps`,`Top ISPs`)}),(0,C.jsxs)(`div`,{className:`flex flex-col gap-0.5 min-w-36 max-w-48 ${m?`max-h-36 overflow-y-auto pr-1`:``}`,children:[(m?w:w.slice(0,5)).map(e=>(0,C.jsxs)(`div`,{className:`flex justify-between gap-3 text-[11px] text-gray-600 dark:text-gray-300`,children:[(0,C.jsx)(`span`,{className:`truncate`,title:e.name,children:e.name}),(0,C.jsx)(`span`,{className:`font-mono text-gray-400 dark:text-gray-500`,children:e.count.toLocaleString()})]},e.name)),!m&&w.length>5&&(0,C.jsxs)(C.Fragment,{children:[(0,C.jsx)(`div`,{className:`text-center text-gray-400 dark:text-gray-500 leading-none py-0.5 font-bold`,children:`...`}),(0,C.jsx)(`div`,{className:`text-[10px] text-center text-blue-500 dark:text-blue-400 font-medium whitespace-nowrap mt-0.5`,children:v(`analytics.pressToShowMore`,`Click to show more`)})]})]})]})]})},D=({geographyData:e,destinationMap:t,getLevel:r,containerRef:i,hoveredCountry:a,setHoveredCountry:o})=>{let{i18n:c}=s();return e?(0,C.jsx)(n,{geography:e,children:({geographies:e})=>e.map(e=>{let n=e.id==null?void 0:v[String(e.id)],s=n?t[n]:null,l=s?.count||0,d=r(l);return(0,C.jsx)(u,{geography:e,onMouseEnter:e=>{if(!n||a?.isPinned)return;let t=y(n,c.language)||s?.name||n,r=b(n),u=i.current?.getBoundingClientRect();o({name:t,code:n,count:l,flag:r,x:e.clientX-(u?.left||0),y:e.clientY-(u?.top||0)-15})},onMouseMove:e=>{o(t=>{if(t?.isPinned)return t;let n=i.current?.getBoundingClientRect(),r=e.clientX-(n?.left||0),a=e.clientY-(n?.top||0)-15;return t?{...t,x:r,y:a}:null})},onMouseLeave:()=>{o(e=>e?.isPinned?e:null)},onClick:e=>{if(e.stopPropagation(),!n)return;let t=y(n,c.language)||s?.name||n,r=b(n),a=i.current?.getBoundingClientRect(),u=e.clientX-(a?.left||0),d=e.clientY-(a?.top||0)-15;o(e=>e?.code===n&&e?.isPinned?null:{name:t,code:n,count:l,flag:r,x:u,y:d,isPinned:!0})},style:{default:{fill:`var(--map-color-${d})`,stroke:`var(--map-stroke)`,strokeWidth:.5,outline:`none`,transition:`fill 250ms, stroke 250ms`},hover:{fill:`var(--map-hover)`,stroke:`var(--map-stroke)`,strokeWidth:.5,outline:`none`,cursor:`pointer`},pressed:{fill:`var(--map-hover)`,stroke:`var(--map-stroke)`,strokeWidth:.5,outline:`none`}}},e.rsmKey)})}):null},O={SG:{name:`Singapore`,coordinates:[103.8198,1.3521]},HK:{name:`Hong Kong`,coordinates:[114.1694,22.3193]},MO:{name:`Macau`,coordinates:[113.5439,22.1987]},VA:{name:`Vatican City`,coordinates:[12.4534,41.9029]},MC:{name:`Monaco`,coordinates:[7.4246,43.7384]},SM:{name:`San Marino`,coordinates:[12.4578,43.9424]},LI:{name:`Liechtenstein`,coordinates:[9.5209,47.141]},AD:{name:`Andorra`,coordinates:[1.5218,42.5063]},MT:{name:`Malta`,coordinates:[14.3754,35.9375]},GI:{name:`Gibraltar`,coordinates:[-5.3536,36.1408]},BM:{name:`Bermuda`,coordinates:[-64.7505,32.3078]},MV:{name:`Maldives`,coordinates:[73.5089,4.1755]},MU:{name:`Mauritius`,coordinates:[57.5522,-20.3484]}},k=({destinationMap:e,getLevel:t,containerRef:n,hoveredCountry:r,setHoveredCountry:i})=>{let{i18n:a}=s();return(0,C.jsx)(C.Fragment,{children:Object.entries(O).map(([s,c])=>{let u=e[s],d=u?.count||0,f=t(d),p=d>0,m=p?4:1.5;return(0,C.jsx)(l,{coordinates:o(c.coordinates[0],c.coordinates[1]),onMouseEnter:e=>{if(r?.isPinned)return;let t=y(s,a.language)||u?.name||s,o=b(s),c=n.current?.getBoundingClientRect();i({name:t,code:s,count:d,flag:o,x:e.clientX-(c?.left||0),y:e.clientY-(c?.top||0)-15})},onMouseMove:e=>{i(t=>{if(t?.isPinned)return t;let r=n.current?.getBoundingClientRect(),i=e.clientX-(r?.left||0),a=e.clientY-(r?.top||0)-15;return t?{...t,x:i,y:a}:null})},onMouseLeave:()=>{i(e=>e?.isPinned?e:null)},onClick:e=>{e.stopPropagation();let t=y(s,a.language)||u?.name||s,r=b(s),o=n.current?.getBoundingClientRect(),c=e.clientX-(o?.left||0),l=e.clientY-(o?.top||0)-15;i(e=>e?.code===s&&e?.isPinned?null:{name:t,code:s,count:d,flag:r,x:c,y:l,isPinned:!0})},children:p?(0,C.jsxs)(C.Fragment,{children:[(0,C.jsx)(`circle`,{r:m+3,fill:`var(--map-color-${f})`,opacity:.4,className:`animate-ping map-marker-circle`}),(0,C.jsx)(`circle`,{r:m,fill:`var(--map-color-${f})`,stroke:`var(--map-stroke)`,strokeWidth:.75,style:{cursor:`pointer`},className:`map-marker-circle`})]}):(0,C.jsx)(`circle`,{r:m,fill:`var(--text-color)`,opacity:.25,style:{pointerEvents:`none`}})},s)})})},A=({destinations:e,profileId:t,range:n,customRange:i,accessPointId:s})=>{let{geographyData:l,destinationMap:u,scaleConfig:d,getLevel:f,formatNumber:p}=S(e),[m,h]=(0,x.useState)({coordinates:o(0,0),zoom:1.2}),[g,_]=(0,x.useState)(null),[v,y]=(0,x.useState)(null),[b,O]=(0,x.useState)({}),A=(0,x.useRef)(null);A.current=g,(0,x.useEffect)(()=>{if(!g){y(null);return}if(g.isPinned){y(g);return}if(v&&v.code===g.code)return;let e=setTimeout(()=>{A.current&&A.current.code===g.code&&y(A.current)},100);return()=>clearTimeout(e)},[g?.code,g?.isPinned,v?.code]),(0,x.useEffect)(()=>{g&&v&&g.code===v.code&&(g.x!==v.x||g.y!==v.y||g.isPinned!==v.isPinned)&&y(g)},[g?.x,g?.y,g?.isPinned,v]);let j=(0,x.useRef)(null);x.useEffect(()=>{O({})},[t,n,i,s]);let M=x.useCallback((e,t)=>{O(n=>({...n,[e]:t}))},[]),N=x.useMemo(()=>c(o(-100,-50),o(900,600)),[]);return(0,C.jsxs)(`div`,{className:`relative w-full min-h-85 max-h-120 aspect-800/566 bg-gray-50 dark:bg-slate-950 rounded-xl overflow-hidden border border-gray-100 dark:border-slate-800 flex flex-col justify-between shadow-sm`,children:[(0,C.jsxs)(`div`,{ref:j,className:`relative w-full flex-1 min-h-0 overflow-hidden select-none cursor-grab active:cursor-grabbing`,onClick:e=>{(e.target===e.currentTarget||e.target.tagName===`svg`)&&_(null)},children:[(0,C.jsx)(r,{projection:`geoEqualEarth`,width:800,height:566,style:{width:`100%`,height:`100%`},children:(0,C.jsxs)(a,{zoom:m.zoom,center:m.coordinates,onMoveEnd:e=>h({coordinates:o(e.coordinates[0],e.coordinates[1]),zoom:e.zoom}),maxZoom:8,minZoom:1,enablePan:!0,translateExtent:N,children:[(0,C.jsx)(D,{geographyData:l,destinationMap:u,getLevel:f,containerRef:j,hoveredCountry:g,setHoveredCountry:_}),(0,C.jsx)(k,{destinationMap:u,getLevel:f,containerRef:j,hoveredCountry:g,setHoveredCountry:_})]})}),v&&(0,C.jsx)(E,{name:v.name,count:v.count,flag:v.flag,x:v.x,y:v.y,countryCode:v.code,profileId:t,range:n,customRange:i,accessPointId:s,ispCache:b,onCacheIsp:M,isPinned:v.isPinned||!1,onClose:()=>_(null)})]}),(0,C.jsx)(w,{onZoomIn:()=>{m.zoom>=8||h(e=>({...e,zoom:e.zoom*1.5}))},onZoomOut:()=>{m.zoom<=1||h(e=>({...e,zoom:e.zoom/1.5}))},onReset:()=>{h({coordinates:o(0,0),zoom:1.2})}}),(0,C.jsx)(T,{maxThreshold:d.maxThreshold,formatNumber:p})]})};export{A as DestinationMap};
1
+ import{i as e}from"./rolldown-runtime-C4Xdq4VV.js";import{_ as t,d as n,f as r,g as i,i as a,m as o,p as s,r as c,rn as l,u,y as d,z as f}from"./vendor-react-R4_BUhus.js";import{S as p,b as m}from"./vendor-icons-other-kRhgWBno.js";import"./vendor-i18next-J2aoF7F1.js";import"./vendor-utils-y3vK_J_u.js";import{G as h,T as g,mt as _}from"./index-CxK16i2C.js";import{n as v,t as y}from"./formatCountryName-C6cFVUu2.js";import{t as b}from"./getFlagEmoji-Cd2A891A.js";var x=e(p(),1);function S(e){let[t,n]=(0,x.useState)(null);(0,x.useEffect)(()=>{h().then(e=>{if(e&&e.objects){let t={};e.objects.countries&&(t.countries=e.objects.countries),e.objects.land&&(t.land=e.objects.land),e.objects=t}e&&e.objects&&e.objects.countries&&Array.isArray(e.objects.countries.geometries)&&e.objects.countries.geometries.forEach(e=>{e.id!==void 0&&e.id!==null&&(e.id=String(e.id).padStart(3,`0`))}),n(e)}).catch(e=>console.error(`Failed to load map topology`,e))},[]);let r=(0,x.useMemo)(()=>e.reduce((e,t)=>e+(Number(t.count)||0),0),[e]),i=(0,x.useMemo)(()=>{if(r<=0)return{maxThreshold:10,step:1};if(r<=1e3)return{maxThreshold:100,step:10};let e=10**Math.floor(Math.log10(r));return{maxThreshold:e,step:e/10}},[r]);return{geographyData:t,destinationMap:(0,x.useMemo)(()=>{let t={};return e.forEach(e=>{if(e.country_code){let n=e.country_code.toUpperCase(),r=Number(e.count)||0;t[n]?(t[n].count+=r,(!t[n].name||t[n].name===`Unknown`)&&e.country&&e.country!==`Unknown`&&(t[n].name=e.country)):t[n]={count:r,name:e.country,countryCode:n}}}),t},[e]),scaleConfig:i,getLevel:e=>!e||e<=0?0:Math.min(10,Math.floor(e/i.step)+1),formatNumber:e=>{if(e>=1e6){let t=e/1e6;return Number.isInteger(t)?`${t}M`:`${t.toFixed(1)}M`}if(e>=1e3){let t=e/1e3;return Number.isInteger(t)?`${t}K`:`${t.toFixed(1)}K`}return e.toString()}}}var C=e(m(),1);const w=({onZoomIn:e,onZoomOut:n,onReset:r})=>(0,C.jsxs)(`div`,{className:`absolute top-3 right-3 flex flex-col gap-1.5 bg-white/80 dark:bg-slate-950/80 backdrop-blur-md p-1.5 rounded-lg border border-gray-200/50 dark:border-slate-800/50 shadow-sm z-10`,children:[(0,C.jsx)(`button`,{type:`button`,onClick:e,className:`p-1.5 hover:bg-gray-100 dark:hover:bg-slate-800 rounded text-gray-600 dark:text-gray-300 transition-colors cursor-pointer`,title:`Zoom In`,children:(0,C.jsx)(t,{size:16})}),(0,C.jsx)(`button`,{type:`button`,onClick:n,className:`p-1.5 hover:bg-gray-100 dark:hover:bg-slate-800 rounded text-gray-600 dark:text-gray-300 transition-colors cursor-pointer`,title:`Zoom Out`,children:(0,C.jsx)(i,{size:16})}),(0,C.jsx)(`button`,{type:`button`,onClick:r,className:`p-1.5 hover:bg-gray-100 dark:hover:bg-slate-800 rounded text-gray-600 dark:text-gray-300 transition-colors cursor-pointer`,title:`Reset Zoom`,children:(0,C.jsx)(f,{size:16})})]}),T=({maxThreshold:e,formatNumber:t})=>{let{t:n}=l();return(0,C.jsxs)(`div`,{className:`sm:absolute sm:bottom-3 sm:left-3 relative m-3 sm:m-0 flex flex-col shrink-0 gap-1.5 bg-white/80 dark:bg-slate-950/80 backdrop-blur-md p-2 rounded-lg border border-gray-200/50 dark:border-slate-800/50 shadow-sm z-10 max-w-70`,children:[(0,C.jsx)(`span`,{className:`text-[9px] font-bold text-gray-500 dark:text-gray-400 uppercase tracking-wider`,children:n(`analytics.queries`)}),(0,C.jsx)(`div`,{className:`flex items-center gap-0.5`,children:Array.from({length:11}).map((e,t)=>(0,C.jsx)(`div`,{className:`w-4 h-2.5 rounded-sm border border-black/5 dark:border-white/5`,style:{backgroundColor:`var(--map-color-${t})`}},t))}),(0,C.jsxs)(`div`,{className:`flex justify-between text-[9px] text-gray-500 dark:text-gray-400 font-semibold px-0.5`,children:[(0,C.jsx)(`span`,{children:`0`}),(0,C.jsx)(`span`,{children:t(e/2)}),(0,C.jsxs)(`span`,{children:[t(e),`+`]})]})]})},E=({name:e,count:t,flag:n,x:r,y:i,countryCode:a,profileId:o,range:s,customRange:c,accessPointId:u,ispCache:f,onCacheIsp:p,isPinned:m,onClose:h})=>{let{t:v}=l(),y=(0,x.useRef)(null),[b,S]=(0,x.useState)({left:r,top:i-10,alignBottom:!1}),[w,T]=(0,x.useState)([]),[E,D]=(0,x.useState)(!1),O=(0,x.useRef)(f);O.current=f;let k=(0,x.useRef)(p);return k.current=p,(0,x.useEffect)(()=>{if(!a||!o)return;if(t<=0){T([]),D(!1);return}let e=O.current[a];if(e){T(e),D(!1);return}D(!0);let n=Math.floor(Date.now()/1e3),r,i=n,l=`?country_code=${a}&range=${s}`;if(s===`custom`&&c.start&&c.end)r=Math.floor(new Date(c.start).getTime()/1e3),i=Math.floor(new Date(c.end).getTime()/1e3),l+=`&start=${r}&end=${i}`;else switch(s){case`10m`:r=n-600;break;case`1h`:r=n-3600;break;case`24h`:r=n-86400;break;case`7d`:r=n-604800;break;case`30d`:r=n-2592e3;break;default:r=n-3600;break}u&&(l+=`&access_point_id=${u}`);let d=!0,f=setTimeout(async()=>{let e=[],n=0;try{let r=await _(o,`isps`,l),i=Array.isArray(r)?r:[];if(i.length>0&&(e=i,n=i.reduce((e,t)=>e+(Number(t.count)||0),0),n>=t)){k.current(a,i),d&&(T(i),D(!1));return}}catch(e){console.debug(`[MapTooltip] Server ISP fetch failed, trying local DB fallback:`,e)}try{let t=await g.queryISPs({profileId:o,countryCode:a,since:r,until:i,accessPointId:u||void 0});t&&t.length>0&&t.reduce((e,t)=>e+(Number(t.count)||0),0)>n&&(e=t)}catch(e){console.warn(`[MapTooltip] Local SQLite ISP query failed:`,e)}finally{d&&(e.length>0&&(k.current(a,e),T(e)),D(!1))}},150);return()=>{d=!1,clearTimeout(f)}},[a,o,s,c,u,t]),(0,x.useEffect)(()=>{if(!m)return;let e=e=>{if(y.current&&!y.current.contains(e.target)){let t=e.target,n=t.classList.contains(`rsm-geography`)||t.closest(`.rsm-geography`),r=t.classList.contains(`map-marker-circle`)||t.closest(`.map-marker-circle`);!n&&!r&&h()}},t=setTimeout(()=>{document.addEventListener(`click`,e,!0)},0);return()=>{clearTimeout(t),document.removeEventListener(`click`,e,!0)}},[m,h]),(0,x.useLayoutEffect)(()=>{if(!y.current)return;let e=y.current.getBoundingClientRect(),t=y.current.parentElement;if(!t)return;let n=t.getBoundingClientRect(),a=r,o=e.width/2;r-o<4?a=o+4:r+o>n.width-4&&(a=n.width-o-4);let s=i-10,c=!1;i-e.height-15<4&&(s=i+15,c=!0),S({left:a,top:s,alignBottom:c})},[r,i,w]),(0,C.jsxs)(`div`,{ref:y,onMouseLeave:m?h:void 0,className:`absolute bg-white/95 dark:bg-slate-900/95 backdrop-blur-sm px-3 py-2 rounded-lg shadow-xl border border-gray-200/50 dark:border-slate-800/50 text-xs z-50 flex flex-col gap-1 transition-all duration-75 text-gray-900 dark:text-gray-100 ${m?`pointer-events-auto cursor-default`:`pointer-events-none`}`,style:{left:`${b.left}px`,top:`${b.top}px`,transform:b.alignBottom?`translate(-50%, 0)`:`translate(-50%, -100%)`},children:[(0,C.jsxs)(`div`,{className:`flex items-center justify-between gap-4`,children:[(0,C.jsxs)(`div`,{className:`flex flex-col gap-0.5`,children:[(0,C.jsxs)(`div`,{className:`flex items-center gap-1.5 font-semibold whitespace-nowrap`,children:[(0,C.jsx)(`span`,{className:`text-sm`,children:n}),(0,C.jsx)(`span`,{children:e})]}),(0,C.jsxs)(`div`,{className:`text-gray-500 dark:text-gray-400 whitespace-nowrap`,children:[t.toLocaleString(),` `,v(`analytics.queries`)]})]}),m&&(0,C.jsx)(`button`,{onClick:e=>{e.stopPropagation(),h()},className:`flex items-center justify-center p-2 rounded-lg border border-gray-200 dark:border-slate-800 text-gray-500 hover:text-red-500 hover:bg-red-50 dark:hover:bg-red-950/20 hover:border-red-200 dark:hover:border-red-900/50 transition-colors cursor-pointer self-stretch aspect-square`,title:v(`common.close`,`Close`),children:(0,C.jsx)(d,{size:18})})]}),E?(0,C.jsxs)(`div`,{className:`mt-1.5 pt-1.5 border-t border-gray-150 dark:border-slate-850 flex flex-col gap-1 min-w-36`,children:[(0,C.jsx)(`div`,{className:`text-[10px] uppercase font-bold text-gray-400 dark:text-gray-500 tracking-wider`,children:v(`analytics.topIsps`,`Top ISPs`)}),(0,C.jsx)(`div`,{className:`text-[11px] text-gray-400 dark:text-gray-500 italic`,children:v(`analytics.loading`,`Loading...`)})]}):w.length>0&&(0,C.jsxs)(`div`,{className:`mt-1.5 pt-1.5 border-t border-gray-150 dark:border-slate-800 flex flex-col gap-1`,children:[(0,C.jsx)(`div`,{className:`text-[10px] uppercase font-bold text-gray-400 dark:text-gray-500 tracking-wider`,children:v(`analytics.topIsps`,`Top ISPs`)}),(0,C.jsxs)(`div`,{className:`flex flex-col gap-0.5 min-w-36 max-w-48 ${m?`max-h-36 overflow-y-auto pr-1`:``}`,children:[(m?w:w.slice(0,5)).map(e=>(0,C.jsxs)(`div`,{className:`flex justify-between gap-3 text-[11px] text-gray-600 dark:text-gray-300`,children:[(0,C.jsx)(`span`,{className:`truncate`,title:e.name,children:e.name}),(0,C.jsx)(`span`,{className:`font-mono text-gray-400 dark:text-gray-500`,children:e.count.toLocaleString()})]},e.name)),!m&&w.length>5&&(0,C.jsxs)(C.Fragment,{children:[(0,C.jsx)(`div`,{className:`text-center text-gray-400 dark:text-gray-500 leading-none py-0.5 font-bold`,children:`...`}),(0,C.jsx)(`div`,{className:`text-[10px] text-center text-blue-500 dark:text-blue-400 font-medium whitespace-nowrap mt-0.5`,children:v(`analytics.pressToShowMore`,`Click to show more`)})]})]})]})]})},D=({geographyData:e,destinationMap:t,getLevel:r,containerRef:i,hoveredCountry:a,setHoveredCountry:o})=>{let{i18n:s}=l();return e?(0,C.jsx)(n,{geography:e,children:({geographies:e})=>e.map(e=>{let n=e.id==null?void 0:v[String(e.id)],c=n?t[n]:null,l=c?.count||0,d=r(l),f=e=>{if(!n||a?.isPinned)return;let t=y(n,s.language)||c?.name||n,r=b(n),u=i.current?.getBoundingClientRect();o({name:t,code:n,count:l,flag:r,x:e.clientX-(u?.left||0),y:e.clientY-(u?.top||0)-15})},p=e=>{if(e.stopPropagation(),!n)return;let t=y(n,s.language)||c?.name||n,r=b(n),a=i.current?.getBoundingClientRect(),u=e.clientX-(a?.left||0),d=e.clientY-(a?.top||0)-15;o(e=>e?.code===n&&e?.isPinned?null:{name:t,code:n,count:l,flag:r,x:u,y:d,isPinned:!0})},m=a?.code===n&&!!a?.isPinned,h=m?`var(--map-hover)`:`var(--map-color-${d})`;return(0,C.jsx)(u,{geography:e,onMouseEnter:f,onMouseMove:e=>{o(t=>{if(t?.isPinned)return t;let n=i.current?.getBoundingClientRect(),r=e.clientX-(n?.left||0),a=e.clientY-(n?.top||0)-15;return t?{...t,x:r,y:a}:null})},onMouseLeave:()=>{o(e=>e?.isPinned?e:null)},onClick:p,style:{default:{fill:h,stroke:`var(--map-stroke)`,strokeWidth:m?.9:.5,outline:`none`,transition:`fill 250ms, stroke 250ms`},hover:{fill:`var(--map-hover)`,stroke:`var(--map-stroke)`,strokeWidth:.75,outline:`none`,cursor:`pointer`},pressed:{fill:`var(--map-hover)`,stroke:`var(--map-stroke)`,strokeWidth:.75,outline:`none`},focused:{fill:h,stroke:`var(--map-stroke)`,strokeWidth:m?.9:.5,outline:`none`,cursor:`pointer`}}},e.rsmKey)})}):null},O={SG:{name:`Singapore`,coordinates:[103.8198,1.3521]},HK:{name:`Hong Kong`,coordinates:[114.1694,22.3193]},MO:{name:`Macau`,coordinates:[113.5439,22.1987]},VA:{name:`Vatican City`,coordinates:[12.4534,41.9029]},MC:{name:`Monaco`,coordinates:[7.4246,43.7384]},SM:{name:`San Marino`,coordinates:[12.4578,43.9424]},LI:{name:`Liechtenstein`,coordinates:[9.5209,47.141]},AD:{name:`Andorra`,coordinates:[1.5218,42.5063]},MT:{name:`Malta`,coordinates:[14.3754,35.9375]},GI:{name:`Gibraltar`,coordinates:[-5.3536,36.1408]},BM:{name:`Bermuda`,coordinates:[-64.7505,32.3078]},MV:{name:`Maldives`,coordinates:[73.5089,4.1755]},MU:{name:`Mauritius`,coordinates:[57.5522,-20.3484]}},k=({destinationMap:e,getLevel:t,containerRef:n,hoveredCountry:r,setHoveredCountry:i})=>{let{i18n:a}=l();return(0,C.jsx)(C.Fragment,{children:Object.entries(O).map(([s,l])=>{let u=e[s],d=u?.count||0,f=t(d),p=d>0,m=p?4:1.5;return(0,C.jsx)(c,{coordinates:o(l.coordinates[0],l.coordinates[1]),onMouseEnter:e=>{if(r?.isPinned)return;let t=y(s,a.language)||u?.name||s,o=b(s),c=n.current?.getBoundingClientRect();i({name:t,code:s,count:d,flag:o,x:e.clientX-(c?.left||0),y:e.clientY-(c?.top||0)-15})},onMouseMove:e=>{i(t=>{if(t?.isPinned)return t;let r=n.current?.getBoundingClientRect(),i=e.clientX-(r?.left||0),a=e.clientY-(r?.top||0)-15;return t?{...t,x:i,y:a}:null})},onMouseLeave:()=>{i(e=>e?.isPinned?e:null)},onClick:e=>{e.stopPropagation();let t=y(s,a.language)||u?.name||s,r=b(s),o=n.current?.getBoundingClientRect(),c=e.clientX-(o?.left||0),l=e.clientY-(o?.top||0)-15;i(e=>e?.code===s&&e?.isPinned?null:{name:t,code:s,count:d,flag:r,x:c,y:l,isPinned:!0})},children:p?(0,C.jsxs)(C.Fragment,{children:[(0,C.jsx)(`circle`,{r:m+3,fill:`var(--map-color-${f})`,opacity:.4,className:`animate-ping map-marker-circle`}),(0,C.jsx)(`circle`,{r:m,fill:`var(--map-color-${f})`,stroke:`var(--map-stroke)`,strokeWidth:.75,style:{cursor:`pointer`},className:`map-marker-circle`})]}):(0,C.jsx)(`circle`,{r:m,fill:`var(--text-color)`,opacity:.25,style:{pointerEvents:`none`}})},s)})})},A=({destinations:e,profileId:t,range:n,customRange:i,accessPointId:c})=>{let{geographyData:l,destinationMap:u,scaleConfig:d,getLevel:f,formatNumber:p}=S(e),[m,h]=(0,x.useState)({coordinates:o(0,0),zoom:1.2}),[g,_]=(0,x.useState)(null),[v,y]=(0,x.useState)(null),[b,O]=(0,x.useState)({}),A=(0,x.useRef)(null);A.current=g,(0,x.useEffect)(()=>{if(!g){y(null);return}if(g.isPinned){y(g);return}if(v&&v.code===g.code)return;let e=setTimeout(()=>{A.current&&A.current.code===g.code&&y(A.current)},100);return()=>clearTimeout(e)},[g?.code,g?.isPinned,v?.code]),(0,x.useEffect)(()=>{g&&v&&g.code===v.code&&(g.x!==v.x||g.y!==v.y||g.isPinned!==v.isPinned)&&y(g)},[g?.x,g?.y,g?.isPinned,v]);let j=(0,x.useRef)(null);x.useEffect(()=>{O({})},[t,n,i,c]);let M=x.useCallback((e,t)=>{O(n=>({...n,[e]:t}))},[]),N=x.useMemo(()=>s(o(-100,-50),o(900,600)),[]);return(0,C.jsxs)(`div`,{className:`relative w-full min-h-85 max-h-120 aspect-800/566 bg-gray-50 dark:bg-slate-950 rounded-xl overflow-hidden border border-gray-100 dark:border-slate-800 flex flex-col justify-between shadow-sm`,children:[(0,C.jsxs)(`div`,{ref:j,className:`relative w-full flex-1 min-h-0 overflow-hidden select-none cursor-grab active:cursor-grabbing`,onClick:e=>{(e.target===e.currentTarget||e.target.tagName===`svg`)&&_(null)},children:[(0,C.jsx)(r,{projection:`geoEqualEarth`,width:800,height:566,style:{width:`100%`,height:`100%`},children:(0,C.jsxs)(a,{zoom:m.zoom,center:m.coordinates,onMoveEnd:e=>h({coordinates:o(e.coordinates[0],e.coordinates[1]),zoom:e.zoom}),maxZoom:8,minZoom:1,enablePan:!0,translateExtent:N,children:[(0,C.jsx)(D,{geographyData:l,destinationMap:u,getLevel:f,containerRef:j,hoveredCountry:g,setHoveredCountry:_}),(0,C.jsx)(k,{destinationMap:u,getLevel:f,containerRef:j,hoveredCountry:g,setHoveredCountry:_})]})}),v&&(0,C.jsx)(E,{name:v.name,count:v.count,flag:v.flag,x:v.x,y:v.y,countryCode:v.code,profileId:t,range:n,customRange:i,accessPointId:c,ispCache:b,onCacheIsp:M,isPinned:v.isPinned||!1,onClose:()=>_(null)})]}),(0,C.jsx)(w,{onZoomIn:()=>{m.zoom>=8||h(e=>({...e,zoom:e.zoom*1.5}))},onZoomOut:()=>{m.zoom<=1||h(e=>({...e,zoom:e.zoom/1.5}))},onReset:()=>{h({coordinates:o(0,0),zoom:1.2})}}),(0,C.jsx)(T,{maxThreshold:d.maxThreshold,formatNumber:p})]})};export{A as DestinationMap};
@@ -0,0 +1 @@
1
+ import{i as e}from"./rolldown-runtime-C4Xdq4VV.js";import{A as t,B as n,L as r,Lt as i,St as a,ct as o,ft as s,rn as c,w as l}from"./vendor-react-R4_BUhus.js";import{S as u,b as d}from"./vendor-icons-other-kRhgWBno.js";import"./vendor-i18next-J2aoF7F1.js";import{C as f,D as p,E as m,F as h,H as g,P as _,S as v,T as y,U as b,f as x,h as S,k as C,r as w,u as T,w as E}from"./vendor-ui-core-CKSrm0Y8.js";import{_t as D}from"./vendor-utils-y3vK_J_u.js";import{Dt as O,Et as k,at as A,bt as j,ct as M,et as N,g as P,gt as F,kt as I,q as L,rt as R,vn as z}from"./index-CxK16i2C.js";var B=e(u(),1);const V=()=>{let{t:e}=c(),[t,n]=(0,B.useState)([]);return(0,B.useEffect)(()=>{L().then(t=>{t&&Array.isArray(t)&&n(t.map(t=>({label:e(t.label),url:t.url})))}).catch(e=>console.warn(`Failed to fetch preset filters from API`,e))},[e]),t};var H=e(d(),1);const U=({newUrl:e,setNewUrl:t,onAddList:n,syncing:r,loading:i,lists:a})=>{let{t:o}=c(),s=(0,H.jsx)(p,{className:`min-w-96`,children:V().map((e,t)=>(0,H.jsx)(y,{text:e.label,onClick:()=>n(e.url),disabled:a.some(t=>t.url===e.url),labelElement:(0,H.jsx)(`div`,{className:`flex flex-col items-end text-right`,children:(0,H.jsx)(`span`,{className:`text-[9px] opacity-85 max-w-xl truncate`,title:e.url,children:e.url})})},t))});return(0,H.jsx)(v,{elevation:b.ONE,className:`mb-6`,children:(0,H.jsxs)(`div`,{className:`flex gap-2 flex-col sm:flex-row`,children:[(0,H.jsx)(x,{fill:!0,size:`large`,placeholder:o(`filtering.urlPlaceholder`),value:e,onChange:e=>t(e.target.value),leftIcon:`globe`,rightElement:(0,H.jsx)(m,{content:s,placement:`bottom-end`,animation:`minimal`,arrow:!1,usePortal:!0,children:(0,H.jsx)(_,{variant:`minimal`,icon:`chevron-down`})})}),(0,H.jsx)(_,{intent:g.PRIMARY,size:`large`,icon:`plus`,onClick:()=>n(),className:`shrink-0`,loading:r||i,disabled:r||i,children:o(`filtering.addSubscription`)})]})})},W=({lists:e,onSelect:t,loading:n=!1,emptyTitle:r,emptyDesc:i})=>{let{t:a}=c(),o=[{key:`url`,header:a(`filtering.tableUrl`),cellClassName:`font-mono text-sm max-w-md truncate`,render:e=>(0,H.jsxs)(`div`,{className:`flex items-center space-x-2 truncate`,children:[(0,H.jsx)(`span`,{className:`truncate`,children:e.url}),e.scope===`system`&&(0,H.jsx)(w,{intent:g.PRIMARY,minimal:!0,className:`shrink-0 text-xs font-sans`,children:a(`filtering.tagSystem`,`系统`)}),e.scope===`user`&&(0,H.jsx)(w,{intent:g.SUCCESS,minimal:!0,className:`shrink-0 text-xs font-sans`,children:a(`filtering.tagUser`,`用户`)})]})},{key:`lastSync`,header:a(`filtering.tableLastSync`),cellClassName:`text-xs opacity-60`,render:e=>e.last_synced_at?P(new Date(e.last_synced_at*1e3)):a(`filtering.neverSynced`)},{key:`status`,header:a(`filtering.tableStatus`),render:e=>{if(!e.enabled)return(0,H.jsx)(w,{intent:g.NONE,minimal:!0,children:a(`filtering.statusDisabled`,`Disabled`)});let t=!!e.sync_error,n=!!e.last_synced_at,r=a(`filtering.statusNormal`,`Active`),i=g.SUCCESS;return t&&(n?(r=a(`filtering.statusOutdated`,`Outdated`),i=g.WARNING):(r=a(`filtering.statusMissing`,`Missing`),i=g.DANGER)),(0,H.jsx)(w,{intent:i,minimal:!0,children:r})}}];return(0,H.jsx)(`div`,{className:`w-full max-w-full overflow-x-auto pb-4`,children:(0,H.jsxs)(T,{interactive:!0,striped:!0,className:`w-full min-w-max whitespace-nowrap`,children:[(0,H.jsx)(`thead`,{children:(0,H.jsx)(`tr`,{children:o.map(e=>(0,H.jsx)(`th`,{className:e.headerClassName,children:e.header},e.key))})}),(0,H.jsxs)(`tbody`,{children:[e.map(e=>(0,H.jsx)(`tr`,{onClick:()=>t(e),className:`cursor-pointer`,children:o.map(t=>(0,H.jsx)(`td`,{className:t.cellClassName,children:t.render(e)},t.key))},e.id)),e.length===0&&(0,H.jsx)(`tr`,{children:(0,H.jsx)(`td`,{colSpan:o.length,className:`text-center py-10 opacity-60`,children:n?(0,H.jsxs)(`div`,{className:`flex items-center justify-center space-x-2 py-4`,children:[(0,H.jsx)(h,{size:16}),(0,H.jsx)(`span`,{children:a(`common.loading`,`加载中...`)})]}):(0,H.jsxs)(`div`,{className:`flex flex-col items-center justify-center space-y-1 py-4 select-none`,children:[(0,H.jsx)(`span`,{className:`text-sm font-medium`,children:r||a(`filtering.noListsTitle`,`尚未添加列表`)}),(0,H.jsx)(`span`,{className:`text-xs opacity-75`,children:i||a(`filtering.noListsDesc`,`您还没有订阅任何外部拦截列表。`)})]})})})]})]})})},G=({syncing:e,progress:t,label:r,syncingLabel:i,detailText:a,intent:o,iconSize:s=15,loading:c=!1,disabled:l=!1,className:u,onClick:d})=>{let f=Math.max(0,Math.min(100,Math.round(t))),p=o===g.PRIMARY;return e?(0,H.jsxs)(_,{intent:o,disabled:!0,className:D(`relative overflow-hidden cursor-wait!`,u),onClick:d,children:[(0,H.jsx)(`span`,{"aria-hidden":`true`,className:D(`absolute inset-y-0 left-0 transition-all duration-300 ease-out pointer-events-none`,p?`bg-white/20`:`bg-blue-500/20 dark:bg-blue-400/25`),style:{width:`${Math.max(4,f)}%`}}),(0,H.jsx)(`span`,{"aria-hidden":`true`,className:D(`absolute bottom-0 left-0 h-[2.5px] transition-all duration-300 ease-out pointer-events-none`,p?`bg-white/90`:`bg-blue-500 dark:bg-blue-400`),style:{width:`${Math.max(4,f)}%`}}),(0,H.jsxs)(`span`,{className:`relative z-10 inline-flex items-center gap-1.5 font-medium`,children:[(0,H.jsx)(n,{size:s,className:`animate-spin shrink-0`}),(0,H.jsx)(`span`,{children:i||r}),(0,H.jsx)(`span`,{className:`font-mono text-xs opacity-90`,children:a?`${a} · ${f}%`:`${f}%`})]})]}):(0,H.jsx)(_,{icon:(0,H.jsx)(n,{size:s}),text:r,intent:o,loading:c,disabled:l,className:u,onClick:d})};function K(e){return e<1024?`${e} B`:e<1024*1024?`${(e/1024).toFixed(1)} KB`:`${(e/(1024*1024)).toFixed(2)} MB`}const q=({profileId:e,selectedList:n,onClose:i,onCopy:u,onDelete:d,onToggleEnabled:p,onAllowDomain:h,onSyncSingle:v,syncingSingle:y=!1,syncSingleProgress:b=0})=>{let{t:T}=c(),[E,D]=(0,B.useState)(``),[O,k]=(0,B.useState)(!1),[j,M]=(0,B.useState)(null),[N,F]=(0,B.useState)(null),[I,L]=(0,B.useState)(!1),[R,z]=(0,B.useState)(!1),[V,U]=(0,B.useState)(!1),[W,q]=(0,B.useState)(!1),J=y||W,[Y,X]=(0,B.useState)(!1),Z=(0,B.useRef)(0),Q=()=>{Z.current++,k(!1),D(``),M(null),F(null),z(!1),X(!1)},$=async()=>{let t=E.trim().toLowerCase();if(!t||!n||(t=t.replace(/^https?:\/\//,``).split(`/`)[0].split(`:`)[0].replace(/\.+$/,``),!t))return;D(t);let r=++Z.current,i=n.id;k(!0),F(null),M(null),z(!1);try{let n=await A(e,i,t);Z.current===r&&M(n)}catch(e){Z.current===r&&F(e instanceof Error?e.message:String(e))}finally{Z.current===r&&k(!1)}},ee=async e=>{if(n){U(!0);try{await p(n.id,e)}finally{U(!1)}}},te=async()=>{if(j?.matchedEntry){L(!0);try{await h(j.domain),z(!0)}catch(e){F(e instanceof Error?e.message:String(e))}finally{L(!1)}}},ne=async()=>{if(!(!n||!v)){q(!0);try{await v(n.id)}finally{q(!1)}}};return(0,H.jsxs)(C,{isOpen:n!==null,onClose:()=>{Q(),i()},title:T(`filtering.listDetails`,`List Details`),icon:`info-sign`,children:[(0,H.jsxs)(`div`,{className:`p-6 space-y-4`,children:[n?.sync_error&&(0,H.jsx)(f,{intent:g.WARNING,title:T(`filtering.syncError`),icon:`warning-sign`,children:n.sync_error}),(0,H.jsxs)(`div`,{className:`bg-gray-50 dark:bg-gray-800 px-3.5 py-3 rounded-lg border border-gray-200 dark:border-gray-700 font-mono text-sm flex items-center justify-between gap-2`,children:[n?.url&&/^https?:\/\//i.test(n.url)?(0,H.jsxs)(`a`,{href:n.url,target:`_blank`,rel:`noopener noreferrer`,title:T(`setup.learnMore`,`Open link`),className:`inline-flex items-center gap-1.5 min-w-0 break-all text-blue-600 dark:text-blue-400 hover:underline`,children:[(0,H.jsx)(`span`,{children:n.url}),(0,H.jsx)(o,{size:13,className:`shrink-0 opacity-75`})]}):(0,H.jsx)(`span`,{className:`break-all min-w-0`,children:n?.url}),(0,H.jsxs)(`div`,{className:`flex items-center gap-1.5 shrink-0`,children:[n?.scope===`system`&&(0,H.jsx)(w,{intent:g.PRIMARY,minimal:!0,className:`font-sans`,children:T(`filtering.tagSystem`,`系统`)}),n?.scope===`user`&&(0,H.jsx)(w,{intent:g.SUCCESS,minimal:!0,className:`font-sans`,children:T(`filtering.tagUser`,`用户`)}),(0,H.jsx)(_,{minimal:!0,small:!0,icon:(0,H.jsx)(s,{size:14}),title:T(`setup.copyUrl`,`Copy link`),"aria-label":T(`setup.copyUrl`,`Copy link`),onClick:()=>{n&&u(n.url)}})]})]}),n?.scope===`system`&&(0,H.jsx)(f,{intent:g.PRIMARY,icon:`info-sign`,className:`text-xs`,children:T(`filtering.systemListNotice`,`此列表由系统下发并应用于所有配置。可在当前配置中停用,但不可在配置中删除。`)}),n?.scope===`user`&&(0,H.jsx)(f,{intent:g.SUCCESS,icon:`info-sign`,className:`text-xs`,children:T(`filtering.userListNotice`,`此列表为账号级用户规则并应用于所有配置。可在当前配置中停用;如需删除,请前往「账号」管理页面。`)}),(0,H.jsxs)(`div`,{className:`flex items-center justify-between border border-gray-200 dark:border-gray-700 rounded-lg p-3`,children:[(0,H.jsxs)(`div`,{children:[(0,H.jsx)(`div`,{className:`text-sm font-bold`,children:T(`filtering.listEnabled`,`List active`)}),(0,H.jsx)(`div`,{className:`text-xs opacity-60`,children:T(`filtering.listEnabledHint`,`Disable to stop filtering with this list without deleting it. Its subscription and sync history are kept.`)})]}),(0,H.jsx)(S,{large:!0,checked:!!n?.enabled,disabled:V,onChange:e=>ee(e.target.checked)})]}),(0,H.jsxs)(`div`,{className:`border border-gray-200 dark:border-gray-700 rounded-lg p-3 space-y-3`,children:[(0,H.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,H.jsxs)(`div`,{className:`flex items-center gap-1.5 text-sm font-bold`,children:[(0,H.jsx)(a,{size:15,className:`text-blue-500`}),(0,H.jsx)(`span`,{children:T(`filtering.listMetadata`,`列表元数据`)})]}),(0,H.jsxs)(`div`,{className:`flex items-center gap-1.5 flex-wrap justify-end`,children:[n?.metadata&&(0,H.jsx)(w,{minimal:!0,intent:g.PRIMARY,className:`font-mono text-xs`,children:T(`filtering.metaTotalRules`,`有效规则: {{count}}`,{count:n.metadata.total_rules})}),n?.metadata?.truncated&&(0,H.jsx)(w,{minimal:!0,intent:g.WARNING,className:`text-xs`,children:T(`filtering.metaTruncated`,`已截断`)})]})]}),n?.metadata?(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(`div`,{className:`grid grid-cols-2 sm:grid-cols-3 gap-2`,children:[{label:T(`filtering.metaExactRules`,`全匹配`),value:n.metadata.exact_rules},{label:T(`filtering.metaSubdomainRules`,`通配子域名`),value:n.metadata.subdomain_rules},{label:T(`filtering.metaWildcardRules`,`通配符`),value:n.metadata.wildcard_rules},{label:T(`filtering.metaRegexRules`,`正则表达式`),value:n.metadata.regex_rules},{label:T(`filtering.metaExceptionRules`,`放行规则`),value:n.metadata.exception_rules},{label:T(`filtering.metaRewriteRules`,`重定向规则`),value:n.metadata.rewrite_rules}].map(e=>(0,H.jsxs)(`div`,{className:`bg-gray-50 dark:bg-gray-800/70 rounded px-2.5 py-2 border border-gray-100 dark:border-gray-800`,children:[(0,H.jsx)(`div`,{className:`text-[11px] opacity-60 truncate`,children:e.label}),(0,H.jsx)(`div`,{className:`text-sm font-semibold font-mono mt-0.5`,children:e.value.toLocaleString()})]},e.label))}),(0,H.jsxs)(`div`,{className:`flex flex-wrap gap-x-4 gap-y-1 text-[11px] opacity-70 pt-1 border-t border-gray-100 dark:border-gray-800`,children:[(0,H.jsxs)(`span`,{children:[T(`filtering.metaCommentLines`,`注释行`),`:`,` `,(0,H.jsx)(`strong`,{className:`font-mono`,children:n.metadata.comment_lines.toLocaleString()})]}),(0,H.jsxs)(`span`,{children:[T(`filtering.metaUnsupportedLines`,`忽略/非 DNS 行`),`:`,` `,(0,H.jsx)(`strong`,{className:`font-mono`,children:n.metadata.unsupported_lines.toLocaleString()})]}),typeof n.metadata.total_bytes==`number`&&(0,H.jsxs)(`span`,{children:[T(`filtering.metaFileSize`,`体积`),`:`,` `,(0,H.jsx)(`strong`,{className:`font-mono`,children:K(n.metadata.total_bytes)})]}),n.last_modified&&(0,H.jsxs)(`span`,{children:[T(`filtering.metaLastModified`,`上游更新`),`:`,` `,(0,H.jsx)(`strong`,{className:`font-mono`,children:P(new Date(n.last_modified*1e3))})]}),n.etag&&(0,H.jsxs)(`span`,{className:`inline-flex items-center gap-1 max-w-full min-w-0`,title:n.etag,children:[(0,H.jsx)(`span`,{className:`shrink-0`,children:`ETag:`}),(0,H.jsx)(`strong`,{className:`font-mono truncate`,children:n.etag})]})]})]}):(0,H.jsxs)(`div`,{className:`space-y-1.5 text-xs opacity-65`,children:[(0,H.jsx)(`div`,{children:T(`filtering.metaPendingHint`,`暂无规则明细统计,点击「立即同步」后将自动生成。`)}),(n?.last_modified||n?.etag)&&(0,H.jsxs)(`div`,{className:`flex flex-wrap gap-x-4 gap-y-1 text-[11px] pt-1`,children:[n.last_modified&&(0,H.jsxs)(`span`,{children:[T(`filtering.metaLastModified`,`上游更新`),`:`,` `,(0,H.jsx)(`strong`,{className:`font-mono`,children:P(new Date(n.last_modified*1e3))})]}),n.etag&&(0,H.jsxs)(`span`,{className:`inline-flex items-center gap-1 max-w-full min-w-0`,title:n.etag,children:[(0,H.jsx)(`span`,{className:`shrink-0`,children:`ETag:`}),(0,H.jsx)(`strong`,{className:`font-mono truncate`,children:n.etag})]})]})]})]}),(0,H.jsxs)(`div`,{className:`border border-gray-200 dark:border-gray-700 rounded-lg p-3 space-y-3`,children:[(0,H.jsxs)(`div`,{children:[(0,H.jsx)(`div`,{className:`text-sm font-bold`,children:T(`filtering.checkDomain`,`Check a domain`)}),(0,H.jsx)(`div`,{className:`text-xs opacity-60`,children:T(`filtering.checkDomainHint`,`Lists are stored as compact filters, so their entries cannot be browsed. You can test any domain against this list instantly.`)})]}),(0,H.jsxs)(`div`,{className:`flex gap-2 items-center`,children:[(0,H.jsx)(x,{fill:!0,className:`flex-1 min-w-0`,placeholder:`example.com`,value:E,disabled:O,leftIcon:`globe-network`,onChange:e=>{D(e.target.value),M(null)},onKeyDown:e=>{e.key===`Enter`&&$()}}),(0,H.jsx)(_,{className:`shrink-0 whitespace-nowrap min-w-fit w-auto`,icon:(0,H.jsx)(r,{size:14}),text:T(`filtering.check`,`Check`),loading:O,disabled:!E.trim(),onClick:()=>void $()})]}),N&&(0,H.jsx)(f,{intent:g.DANGER,className:`text-xs`,children:N}),j&&!j.synced&&(0,H.jsx)(f,{intent:g.WARNING,className:`text-xs`,children:T(`filtering.checkNotSynced`,`This list has not finished syncing yet, so there is nothing to check against.`)}),j?.synced&&j.enabled===!1&&(0,H.jsx)(f,{intent:g.NONE,className:`text-xs`,children:T(`filtering.checkListDisabled`,`This list is currently disabled, so it is not filtering anything right now.`)}),j?.synced&&(0,H.jsx)(f,{intent:j.blocked?g.WARNING:g.SUCCESS,className:`text-xs`,icon:j.blocked?`ban-circle`:`tick-circle`,children:j.blocked?(0,H.jsxs)(`div`,{className:`space-y-2`,children:[(0,H.jsxs)(`div`,{children:[T(`filtering.checkBlocked`,`Blocked by this list`),j.matchedEntry&&j.matchedEntry!==j.domain&&(0,H.jsxs)(H.Fragment,{children:[` `,(0,H.jsx)(w,{minimal:!0,className:`font-mono`,children:j.matchedEntry}),` `,j.matchedEntry.includes(`*`)||j.matchedEntry.startsWith(`/`)?T(`filtering.checkViaPattern`,`(匹配到通配规则)`):T(`filtering.checkViaParent`,`(matched a parent domain)`)]})]}),R?(0,H.jsx)(w,{intent:g.SUCCESS,minimal:!0,children:T(`filtering.checkAllowed`,`Exception added - this domain now resolves`)}):(0,H.jsx)(_,{small:!0,icon:(0,H.jsx)(t,{size:12}),intent:g.PRIMARY,loading:I,text:T(`filtering.checkAllowAction`,`Allow anyway`),onClick:()=>void te()})]}):j.whitelisted?(0,H.jsxs)(`div`,{className:`space-y-1`,children:[(0,H.jsxs)(`div`,{className:`font-medium text-emerald-700 dark:text-emerald-400`,children:[T(`filtering.checkWhitelisted`,`被该列表放行`),j.matchedEntry&&(0,H.jsxs)(H.Fragment,{children:[` `,(0,H.jsx)(w,{minimal:!0,intent:g.SUCCESS,className:`font-mono`,children:j.matchedEntry})]})]}),(0,H.jsx)(`div`,{className:`opacity-75`,children:T(`filtering.checkWhitelistedDesc`,`命中该订阅列表中的白名单/例外规则 (@@),即使被其他黑名单规则命中也会优先放行。`)})]}):T(`filtering.checkNotBlocked`,`Not blocked by this list`)})]}),(0,H.jsx)(`div`,{className:`flex justify-between items-center gap-3`,children:(0,H.jsxs)(`span`,{className:`text-xs opacity-50 truncate min-w-0`,children:[T(`filtering.tableLastSync`),`:`,` `,n?.last_synced_at?P(new Date(n.last_synced_at*1e3)):`-`]})})]}),(0,H.jsxs)(`div`,{className:`p-4 border-t border-gray-100 dark:border-gray-800 flex justify-between items-center`,children:[n?.scope===`profile`?(0,H.jsx)(m,{isOpen:Y,onInteraction:X,placement:`top-start`,portalClassName:`z-20000`,content:(0,H.jsxs)(`div`,{className:`p-3 space-y-3 max-w-xs`,children:[(0,H.jsx)(`p`,{className:`text-xs font-semibold leading-relaxed m-0 text-gray-800 dark:text-gray-200`,children:T(`filtering.deleteConfirm`,`Are you sure you want to delete this list? This action cannot be undone.`)}),(0,H.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,H.jsx)(_,{small:!0,variant:`minimal`,text:T(`common.cancel`,`Cancel`),onClick:()=>X(!1)}),(0,H.jsx)(_,{small:!0,intent:g.DANGER,text:T(`common.confirm`,`Confirm`),onClick:()=>{if(!n)return;let e=n.id;X(!1),Q(),d(e)}})]})]}),children:(0,H.jsx)(_,{icon:(0,H.jsx)(l,{size:14}),intent:g.DANGER,text:T(`rules.delete`,`Delete`),onClick:()=>X(!0)})}):(0,H.jsx)(`span`,{className:`text-xs text-gray-400 italic`,children:T(`filtering.cannotDeleteUserListDesc`,`用户级与系统级列表不可在配置中删除`)}),(0,H.jsxs)(`div`,{className:`flex gap-2`,children:[v&&(0,H.jsx)(G,{syncing:J,progress:b,intent:g.PRIMARY,iconSize:14,label:T(`filtering.syncSingle`,`同步此列表`),syncingLabel:T(`filtering.syncing`,`同步中...`),onClick:()=>void ne()}),(0,H.jsx)(_,{onClick:()=>{Q(),i()},text:T(`rules.close`,`Close`)})]})]})]})},J=({profileId:e,toasterRef:t})=>{let n=i(),r=z(),[a,o]=(0,B.useState)([]),[s,l]=(0,B.useState)(``),[u,d]=(0,B.useState)(!0),[p,m]=(0,B.useState)(!1),[h,v]=(0,B.useState)(0),[y,b]=(0,B.useState)(void 0),[x,S]=(0,B.useState)(null),[C,w]=(0,B.useState)(0),{t:T}=c(),[A,P]=(0,B.useState)(null),L=async()=>{d(!0);try{o(await F(e))}catch(e){console.error(`Failed to fetch filters`,e)}finally{d(!1)}},V=e=>{navigator.clipboard.writeText(e),t?.current?.show({message:T(`setup.copied`,`已复制到剪贴板`),intent:g.SUCCESS,icon:`duplicate`})},K=async t=>{let n=new Map(t.map(e=>[e.id,e.last_synced_at])),r=0,i=8;for(v(i),b(void 0);r<60;){await new Promise(e=>setTimeout(e,1e3));try{let[t,a]=await Promise.all([F(e),j(e).catch(()=>null)]),s=t,c=0;for(let e of s){let t=n.get(e.id);(t===void 0?e.last_synced_at:e.last_synced_at!==t)&&c++}let l=Math.max(1,s.length),u=Math.round(c/l*95),d=a?.syncing&&a.type===`all`?a.percent:0;if(a?.syncing&&a.type===`all`&&a.total>0?b(`${a.current}/${a.total}`):s.length>0&&b(`${c}/${s.length}`),c>=s.length&&s.length>0||a&&!a.syncing&&r>=1&&c>0)return v(100),o(s),await new Promise(e=>setTimeout(e,300)),!0;i=Math.min(94,Math.max(i+4,u,d)),v(i)}catch{}r++}return await L(),!1},J=async(t,n)=>{let r=0,i=12;for(w(i);r<60;){await new Promise(e=>setTimeout(e,1e3));try{let[a,s]=await Promise.all([F(e),j(e).catch(()=>null)]),c=a,l=c.find(e=>e.id===t),u=l&&(l.last_synced_at??0)!==(n??0),d=s&&!s.syncing&&r>=1;if(u||d&&l?.last_synced_at)return w(100),o(c),l&&P(l),await new Promise(e=>setTimeout(e,300)),!0;let f=s?.syncing&&s.type===`single`&&s.listId===t?s.percent:0;i=Math.min(94,Math.max(i+6,f)),w(i)}catch{}r++}return await L(),!1};return(0,B.useEffect)(()=>{L()},[e]),(0,H.jsxs)(`div`,{className:D(`md:px-8 w-full min-w-0 max-w-5xl mx-auto`,r?`p-1`:`px-8`),children:[(0,H.jsxs)(`div`,{className:`mb-8 flex flex-col md:flex-row justify-between items-start md:items-end gap-4`,children:[(0,H.jsxs)(`div`,{className:`w-full md:w-auto flex-1`,children:[r?(0,H.jsxs)(E,{minimal:!0,fill:r,children:[(0,H.jsx)(_,{active:!1,onClick:()=>n(`/dash/${e}/rules`),text:T(`rules.title`),large:!0}),(0,H.jsx)(_,{active:!0,onClick:()=>n(`/dash/${e}/filter`),text:T(`filtering.title`),large:!0})]}):(0,H.jsx)(`h1`,{className:`bp6-heading`,children:T(`filtering.title`)}),(0,H.jsx)(`p`,{className:`bp6-text-muted mt-2!`,children:T(`filtering.subtitle`)})]}),(0,H.jsx)(G,{syncing:p,progress:h,detailText:y,iconSize:16,label:T(`filtering.syncAll`),syncingLabel:T(`filtering.syncing`,`同步中...`),loading:u,disabled:u||a.length===0,className:r?`w-full`:``,onClick:async()=>{m(!0),v(5),b(void 0);try{await k(e),t?.current?.show({message:T(`filtering.syncTaskStarted`),intent:g.PRIMARY,icon:`cloud-download`}),await K(a)&&t?.current?.show({message:T(`filtering.syncCheckComplete`),intent:g.SUCCESS,icon:`tick`})}catch(e){console.error(e)}finally{m(!1),v(0),b(void 0)}}})]}),(0,H.jsxs)(f,{intent:g.WARNING,icon:`info-sign`,className:`mb-6`,children:[(0,H.jsx)(`p`,{className:`m-0`,children:T(`filtering.formatDisclaimer`)}),(0,H.jsx)(`p`,{className:`mt-1.5 mb-0`,children:T(`filtering.priorityDisclaimer`,`外部列表之间不分先后(合并生效),其条目优先级统一遵循:「放行 (@@)」>「重写 ($dnsrewrite)」>「拦截」;本地自定义规则始终优先于外部列表。`)})]}),(0,H.jsx)(U,{newUrl:s,setNewUrl:l,onAddList:async n=>{let r=n||s;if(r){m(!0);try{let n=await N(e,r);t?.current?.show({message:T(`filtering.addSuccess`),intent:g.SUCCESS,icon:`tick`}),l(``),t?.current?.show({message:T(`filtering.singleSyncStarted`,`列表同步任务已开始`),intent:g.PRIMARY,icon:`cloud-download`});let i=n?.id;if(!i){let t=await F(e);i=t.find(e=>e.url.trim().toLowerCase()===r.trim().toLowerCase())?.id,o(t)}i?await J(i,0)&&t?.current?.show({message:T(`filtering.syncCheckComplete`),intent:g.SUCCESS,icon:`tick`}):await L()}catch(e){console.error(e),t?.current?.show({message:e instanceof Error?e.message:String(e),intent:g.DANGER,icon:`error`})}finally{m(!1)}}},syncing:p,loading:u,lists:a}),(0,H.jsx)(`div`,{className:`mb-6`,children:(0,H.jsx)(W,{lists:a.filter(e=>e.scope===`profile`),onSelect:P,loading:u,emptyTitle:T(`filtering.noProfileListsTitle`,`尚未添加配置级列表`),emptyDesc:T(`filtering.noProfileListsDesc`,`您可在此为当前配置添加专属的拦截列表。`)})}),(0,H.jsxs)(`div`,{className:`border-t border-gray-200 dark:border-gray-800 my-8 pt-6`,children:[(0,H.jsxs)(`div`,{className:`mb-4`,children:[(0,H.jsxs)(`h3`,{className:`text-base font-semibold text-gray-900 dark:text-gray-100 flex items-center gap-2`,children:[(0,H.jsx)(`span`,{children:T(`filtering.userAndSystemListsTitle`,`用户级与系统级列表`)}),(0,H.jsxs)(`span`,{className:`text-xs font-normal text-gray-400`,children:[`(`,a.filter(e=>e.scope!==`profile`).length,`)`]})]}),(0,H.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-gray-400 mt-1`,children:T(`filtering.userAndSystemListsSubtitle`,`继承自账号设置或由系统下发的全局规则列表,自动应用于所有配置。可在此处针对当前配置停用,但不可在此删除。`)})]}),(0,H.jsx)(W,{lists:a.filter(e=>e.scope!==`profile`),onSelect:P,loading:u,emptyTitle:T(`filtering.noUserSystemListsTitle`,`暂无用户级与系统级列表`),emptyDesc:T(`filtering.noUserSystemListsDesc`,`可在账号设置页面中添加应用于所有配置的用户级规则。`)})]}),(0,H.jsx)(q,{profileId:e,selectedList:A,onClose:()=>P(null),onCopy:V,onDelete:async n=>{try{await M(e,n),t?.current?.show({message:T(`filtering.deleteSuccess`),intent:g.PRIMARY,icon:`trash`}),P(null),await L()}catch(e){console.error(e)}},onToggleEnabled:async(n,r)=>{try{await I(e,n,r),t?.current?.show({message:r?T(`filtering.listEnabledToast`,`List enabled - rebuilding filter`):T(`filtering.listDisabledToast`,`List disabled - rebuilding filter`),intent:g.PRIMARY,icon:r?`tick`:`disable`});let i=await F(e);if(o(i),A){let e=i.find(e=>e.id===n||e.url===A.url);e&&P(e)}}catch(e){console.error(e),t?.current?.show({message:e instanceof Error?e.message:String(e),intent:g.DANGER,icon:`error`})}},onAllowDomain:async n=>{await R(e,{type:`ALLOW`,pattern:n}),t?.current?.show({message:T(`filtering.allowRuleAdded`,`Exception added for {{domain}}`,{domain:n}),intent:g.SUCCESS,icon:`tick`})},onSyncSingle:async n=>{S(n),w(8);try{let r=a.find(e=>e.id===n)?.last_synced_at;await O(e,n),t?.current?.show({message:T(`filtering.singleSyncStarted`,`列表同步任务已开始`),intent:g.PRIMARY,icon:`cloud-download`}),await J(n,r)&&t?.current?.show({message:T(`filtering.syncCheckComplete`),intent:g.SUCCESS,icon:`tick`})}catch(e){console.error(e),t?.current?.show({message:e instanceof Error?e.message:String(e),intent:g.DANGER,icon:`error`})}finally{S(null),w(0)}},syncingSingle:A!==null&&x===A.id,syncSingleProgress:C})]})};export{J as FilteringView};
@@ -0,0 +1,5 @@
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/services-B-Y_EKlc.js","assets/index-CxK16i2C.js","assets/vendor-icons-other-kRhgWBno.js","assets/vendor-icons-16-BgwRBCeU.js","assets/rolldown-runtime-C4Xdq4VV.js","assets/vendor-icons-20-X5NPN60g.js","assets/vendor-react-R4_BUhus.js","assets/vendor-i18next-J2aoF7F1.js","assets/vendor-ui-core-CKSrm0Y8.js","assets/vendor-utils-y3vK_J_u.js","assets/index-frQljXGb.css"])))=>i.map(i=>d[i]);
2
+ import{i as e}from"./rolldown-runtime-C4Xdq4VV.js";import{$ as t,Ct as n,Et as r,G as i,J as a,M as o,W as s,X as c,at as l,b as u,it as d,j as f,jt as p,rn as m,wt as h}from"./vendor-react-R4_BUhus.js";import{S as g,b as _,x as v}from"./vendor-icons-other-kRhgWBno.js";import"./vendor-i18next-J2aoF7F1.js";import{C as y,D as b,E as x,F as S,H as C,N as w,P as T,S as E,T as D,a as O,f as k,h as A,l as j,o as M,p as N,r as P,u as F,w as I}from"./vendor-ui-core-CKSrm0Y8.js";import{_t as L}from"./vendor-utils-y3vK_J_u.js";import{C as R,T as z,_t as ee,g as B,ht as te,j as V,mt as H,pt as U,vn as ne,vt as W}from"./index-CxK16i2C.js";import{n as G,t as K}from"./formatCountryName-C6cFVUu2.js";import{t as q}from"./getFlagEmoji-Cd2A891A.js";import{i as re,n as ie,r as ae,t as oe}from"./useLogsE2ee-BEETAe5O.js";import{t as J}from"./SwipeableDrawer-BHXXZw7l.js";var Y=e(g(),1),X=e(_(),1);const se=({range:e,setRange:t,customRange:r,setCustomRange:i,nowStr:a,fetchLogs:o,isMobile:s,logRetentionDays:c})=>{let{t:l}=m(),u=[{key:`10m`,days:.007},{key:`1h`,days:.0416},{key:`24h`,days:1},{key:`7d`,days:7},{key:`30d`,days:30}].filter(e=>e.days<=c).map(e=>e.key);return(0,X.jsx)(`div`,{className:`overflow-x-auto pb-1 -mx-4 px-4 md:mx-0 md:px-0`,children:(0,X.jsxs)(I,{minimal:s,variant:s?void 0:`minimal`,children:[u.map(n=>(0,X.jsx)(T,{active:e===n,onClick:()=>t(n),text:n.toUpperCase(),small:s},n)),(0,X.jsx)(x,{content:(0,X.jsxs)(`div`,{className:`p-4 space-y-2 w-64`,children:[(0,X.jsx)(w,{children:l(`analytics.customRange`)}),(0,X.jsx)(N,{label:l(`analytics.startTime`),children:(0,X.jsx)(k,{type:`datetime-local`,max:r.end||a,value:r.start,onChange:e=>i({...r,start:e.target.value})})}),(0,X.jsx)(N,{label:l(`analytics.endTime`),children:(0,X.jsx)(k,{type:`datetime-local`,min:r.start,max:a,value:r.end,onChange:e=>i({...r,end:e.target.value})})}),(0,X.jsx)(T,{fill:!0,intent:C.PRIMARY,text:l(`analytics.apply`),onClick:()=>{t(`custom`),o(`custom`,!0)}})]}),children:(0,X.jsx)(T,{active:e===`custom`,icon:(0,X.jsx)(n,{size:14}),text:s?``:l(`analytics.custom`),small:s})})]})})},ce=({statusFilter:e,setStatusFilter:t,isMobile:n})=>{let{t:r}=m(),i=(0,X.jsxs)(b,{children:[(0,X.jsx)(D,{icon:e===null?`tick`:void 0,text:r(`logs.allStatus`),onClick:()=>t(null)}),(0,X.jsx)(j,{}),(0,X.jsx)(D,{icon:e===`PASS`?`tick`:void 0,intent:C.SUCCESS,text:r(`logs.onlyPass`),onClick:()=>t(`PASS`)}),(0,X.jsx)(D,{icon:e===`BLOCK`?`tick`:void 0,intent:C.DANGER,text:r(`logs.onlyBlock`),onClick:()=>t(`BLOCK`)}),(0,X.jsx)(D,{icon:e===`REDIRECT`?`tick`:void 0,intent:C.WARNING,text:r(`logs.onlyRedirect`),onClick:()=>t(`REDIRECT`)})]}),a=(()=>{switch(e){case`PASS`:return{text:r(`logs.statusPass`),intent:C.SUCCESS};case`BLOCK`:return{text:r(`logs.statusBlock`),intent:C.DANGER};case`REDIRECT`:return{text:r(`logs.statusRedirect`),intent:C.WARNING};default:return{text:r(`logs.allStatus`),intent:C.NONE}}})();return(0,X.jsx)(x,{content:i,placement:`bottom-start`,children:(0,X.jsx)(T,{icon:(0,X.jsx)(l,{size:14}),rightIcon:`caret-down`,intent:a.intent,text:a.text,variant:`outlined`,fill:n})})},le=({accessPointIdFilter:e,setAccessPointIdFilter:t,accessPoints:n,isMobile:r})=>{let{t:i}=m(),o=(0,X.jsxs)(b,{children:[(0,X.jsx)(D,{icon:e===null?`tick`:void 0,text:i(`logs.allAccessPoint`),onClick:()=>t(null)}),(0,X.jsx)(j,{}),n.map(n=>(0,X.jsx)(D,{icon:e===n.id?`tick`:void 0,text:n.name,onClick:()=>t(n.id)},n.id))]}),s=e&&n.find(t=>t.id===e)?.name||i(`logs.allAccessPoint`);return(0,X.jsx)(x,{content:o,placement:`bottom-start`,children:(0,X.jsx)(T,{icon:(0,X.jsx)(a,{size:14}),rightIcon:`caret-down`,intent:e?C.PRIMARY:C.NONE,text:s,variant:`outlined`,fill:r})})},ue=Array.from(new Set(Object.values(G))).sort((e,t)=>e.localeCompare(t)),de=({destCountryFilter:e,setDestCountryFilter:t,isMobile:n})=>{let{t:r,i18n:i}=m(),[a,o]=(0,Y.useState)(!1),[s,c]=(0,Y.useState)(``),l=(0,Y.useMemo)(()=>{let e=i.language;return ue.map(t=>{let n=K(t,e),r=K(t,`en`);return{code:t,name:n||r||t,searchStr:`${t} ${n} ${r}`.toLowerCase()}})},[i.language]),u=(0,Y.useMemo)(()=>{let e=s.trim().toLowerCase();return e?l.filter(t=>t.searchStr.includes(e)):l},[l,s]),f=(0,X.jsxs)(`div`,{className:`w-72 flex flex-col p-1.5`,children:[(0,X.jsx)(`div`,{className:`pb-1.5`,children:(0,X.jsx)(k,{leftIcon:`search`,placeholder:r(`logs.searchCountry`,`Search country...`),value:s,onChange:e=>c(e.target.value),small:!0,autoFocus:!0,rightElement:s?(0,X.jsx)(T,{icon:`cross`,variant:`minimal`,small:!0,onClick:()=>c(``)}):void 0})}),(0,X.jsxs)(b,{className:`max-h-64 overflow-y-auto`,children:[!s&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(D,{icon:e===null?`tick`:void 0,text:r(`logs.allCountry`),onClick:()=>{t(null),o(!1)}}),(0,X.jsx)(j,{})]}),u.length===0?(0,X.jsx)(D,{disabled:!0,text:r(`logs.noMatchingCountries`,`No matching countries found`)}):u.map(n=>(0,X.jsx)(D,{icon:e===n.code?`tick`:void 0,text:(0,X.jsxs)(`span`,{className:`flex items-center justify-between gap-2 w-full`,children:[(0,X.jsxs)(`span`,{className:`truncate`,children:[q(n.code),` `,n.name]}),(0,X.jsx)(`span`,{className:`text-xs text-gray-400 shrink-0 font-mono`,children:n.code})]}),onClick:()=>{t(n.code),o(!1)}},n.code))]})]}),p=e?`${q(e)} ${K(e,i.language)||e} (${e})`:r(`logs.allCountry`);return(0,X.jsx)(x,{content:f,placement:`bottom-start`,isOpen:a,onInteraction:e=>{o(e),e||c(``)},children:(0,X.jsx)(T,{icon:(0,X.jsx)(d,{size:14}),rightIcon:`caret-down`,intent:e?C.PRIMARY:C.NONE,text:p,variant:`outlined`,fill:n})})},fe=({profileId:e,range:t,customRange:n,destCountryFilter:r,accessPointIdFilter:a,ispFilter:o,setIspFilter:s,isMobile:c})=>{let{t:l}=m(),[u,d]=(0,Y.useState)(!1),[f,p]=(0,Y.useState)([]),[h,g]=(0,Y.useState)(!1),[_,v]=(0,Y.useState)(``),y=(0,Y.useRef)(``),w=`${e}:${t}:${n.start?Math.floor(new Date(n.start).getTime()/1e3):``}:${n.end?Math.floor(new Date(n.end).getTime()/1e3):``}:${r||``}:${a||``}`,E=async()=>{g(!0);try{let i=Math.floor(Date.now()/1e3),o,s=i,c=new URLSearchParams;if(t===`custom`&&n.start&&n.end)o=Math.floor(new Date(n.start).getTime()/1e3),s=Math.floor(new Date(n.end).getTime()/1e3),c.set(`range`,`custom`),c.set(`start`,String(o)),c.set(`end`,String(s));else{switch(t){case`10m`:o=i-600;break;case`1h`:o=i-3600;break;case`24h`:o=i-86400;break;case`7d`:o=i-604800;break;case`30d`:o=i-2592e3;break;default:o=i-3600;break}c.set(`range`,t)}r&&c.set(`country_code`,r),a&&c.set(`access_point_id`,a);let l=[],u=0;try{let t=await H(e,`isps`,c.toString());Array.isArray(t)&&t.length>0&&(l=t,u=t.reduce((e,t)=>e+(Number(t.count)||0),0))}catch(e){console.debug(`[IspFilter] Server ISP fetch failed, falling back to local DB:`,e)}try{let t=await z.queryISPs({profileId:e,countryCode:r||void 0,since:o,until:s,accessPointId:a||void 0});t&&t.length>0&&t.reduce((e,t)=>e+(Number(t.count)||0),0)>u&&(l=t)}catch(e){console.warn(`[IspFilter] Local SQLite query failed:`,e)}p(l),y.current=w}catch(e){console.error(`Failed to fetch ISPs for filter`,e)}finally{g(!1)}},O=e=>{d(e),e?y.current!==w&&E():v(``)},A=(0,Y.useMemo)(()=>{let e=_.trim().toLowerCase();return e?f.filter(t=>t.name.toLowerCase().includes(e)):f},[f,_]),M=(0,X.jsxs)(`div`,{className:`w-72 flex flex-col p-1.5`,children:[(0,X.jsx)(`div`,{className:`pb-1.5`,children:(0,X.jsx)(k,{leftIcon:`search`,placeholder:l(`logs.searchIsp`,`Search ISP...`),value:_,onChange:e=>v(e.target.value),small:!0,autoFocus:!0,rightElement:_?(0,X.jsx)(T,{icon:`cross`,variant:`minimal`,small:!0,onClick:()=>v(``)}):void 0})}),(0,X.jsx)(b,{className:`max-h-64 overflow-y-auto`,children:h?(0,X.jsxs)(`div`,{className:`flex items-center justify-center p-6 text-gray-500 gap-2`,children:[(0,X.jsx)(S,{size:16}),(0,X.jsx)(`span`,{className:`text-xs`,children:l(`logs.loadingIsps`,`Loading ISPs...`)})]}):(0,X.jsxs)(X.Fragment,{children:[!_&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(D,{icon:o===null?`tick`:void 0,text:l(`logs.allIsp`),onClick:()=>{s(null),d(!1)}}),(0,X.jsx)(j,{})]}),A.length===0?(0,X.jsx)(D,{disabled:!0,text:l(`logs.noMatchingIsps`,`No matching ISPs found`)}):A.map(e=>(0,X.jsx)(D,{icon:o===e.name?`tick`:void 0,text:(0,X.jsxs)(`span`,{className:`flex items-center justify-between gap-2 w-full`,children:[(0,X.jsx)(`span`,{className:`truncate`,title:e.name,children:e.name}),(0,X.jsx)(`span`,{className:`text-xs text-gray-400 shrink-0 font-mono`,children:e.count.toLocaleString()})]}),onClick:()=>{s(e.name),d(!1)}},e.name))]})})]}),N=o||l(`logs.allIsp`);return(0,X.jsx)(x,{content:M,placement:`bottom-start`,isOpen:u,onInteraction:O,children:(0,X.jsx)(T,{icon:(0,X.jsx)(i,{size:14}),rightIcon:`caret-down`,intent:o?C.PRIMARY:C.NONE,text:N,variant:`outlined`,fill:c})})},pe=({profileId:e,range:t,setRange:n,customRange:r,setCustomRange:i,nowStr:a,fetchLogs:o,isMobile:s,realtimeRefresh:c,setRealtimeRefresh:l,statusFilter:u,setStatusFilter:d,accessPointIdFilter:f,setAccessPointIdFilter:p,accessPoints:h,destCountryFilter:g,setDestCountryFilter:_,ispFilter:v,setIspFilter:y,searchQuery:b,setSearchQuery:x,stats:S,logRetentionDays:w,onExport:E,exporting:D,loading:O=!1,syncing:j=!1})=>{let{t:M}=m(),[N,F]=(0,Y.useState)(!0),I=u!==null||f!==null||g!==null||v!==null;return(0,X.jsxs)(`div`,{className:`p-4 ${s&&N?`space-y-0`:`space-y-4`} shrink-0 bg-white/50 dark:bg-gray-900/50 backdrop-blur-sm border-b border-gray-100 dark:border-gray-800`,children:[(0,X.jsxs)(`div`,{className:`flex flex-col md:flex-row md:items-center justify-between gap-4`,children:[(0,X.jsxs)(`div`,{className:`flex items-center justify-between w-full md:w-auto`,children:[(0,X.jsxs)(`div`,{children:[(0,X.jsxs)(`h2`,{className:`bp6-heading flex flex-wrap items-center gap-2 text-xl md:text-2xl m-0`,children:[M(`logs.title`),` `,(!s||!N)&&(0,X.jsx)(P,{minimal:!0,round:!0,children:t===`custom`?M(`analytics.custom`):t.toUpperCase()}),S&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(P,{minimal:!0,round:!0,children:S.total.toLocaleString()}),(0,X.jsx)(P,{minimal:!0,round:!0,intent:C.SUCCESS,children:S.pass.toLocaleString()}),(0,X.jsx)(P,{minimal:!0,round:!0,intent:C.DANGER,children:S.block.toLocaleString()}),(0,X.jsx)(P,{minimal:!0,round:!0,intent:C.WARNING,children:S.redirect.toLocaleString()})]})]}),!s&&(0,X.jsx)(`p`,{className:`bp6-text-muted mt-1`,children:M(`logs.subtitle`)})]}),s&&(0,X.jsx)(T,{icon:N?`chevron-down`:`chevron-up`,variant:`minimal`,onClick:()=>F(!N)})]}),(!s||!N)&&(0,X.jsxs)(`div`,{className:`flex flex-col items-stretch md:items-end gap-2`,children:[(0,X.jsx)(se,{range:t,setRange:n,customRange:r,setCustomRange:i,nowStr:a,fetchLogs:o,isMobile:s,logRetentionDays:w}),(0,X.jsxs)(`div`,{className:`flex items-center justify-end gap-4`,children:[(0,X.jsx)(T,{icon:`download`,onClick:E,loading:D,title:M(`logs.export`,`Export Logs`),text:s?void 0:M(`logs.export`,`Export Logs`)}),(0,X.jsx)(A,{label:M(`logs.realtime`),checked:c,onChange:e=>l(e.target.checked),className:`mb-0!`}),(0,X.jsx)(T,{icon:`refresh`,onClick:()=>o(t,!0,!1,!0),loading:O||j,variant:`minimal`,small:s})]})]})]}),(!s||!N)&&(0,X.jsxs)(`div`,{className:`flex flex-col md:flex-row items-stretch md:items-center justify-between gap-3`,children:[(0,X.jsxs)(`div`,{className:`grid grid-cols-2 md:flex md:items-center gap-2`,children:[I&&(0,X.jsx)(`div`,{className:`col-span-2 md:contents`,children:(0,X.jsx)(T,{icon:`filter-remove`,onClick:()=>{d(null),p(null),_(null),y(null)},variant:`minimal`,title:M(`logs.clearFilters`),text:s?M(`logs.clearFilters`):void 0,fill:s})}),(0,X.jsx)(ce,{statusFilter:u,setStatusFilter:d,isMobile:s}),h.length>0&&(0,X.jsx)(le,{accessPointIdFilter:f,setAccessPointIdFilter:p,accessPoints:h,isMobile:s}),(0,X.jsx)(de,{destCountryFilter:g,setDestCountryFilter:_,isMobile:s}),(0,X.jsx)(fe,{profileId:e,range:t,customRange:r,destCountryFilter:g,accessPointIdFilter:f,ispFilter:v,setIspFilter:y,isMobile:s})]}),(0,X.jsx)(`div`,{className:`flex items-center gap-2 flex-1 md:max-w-md justify-end`,children:(0,X.jsx)(`div`,{className:`flex-1 md:max-w-xs`,children:(0,X.jsx)(k,{leftIcon:`search`,placeholder:M(`logs.searchPlaceholder`),value:b,onChange:e=>x(e.target.value),rightElement:b?(0,X.jsx)(T,{icon:`cross`,minimal:!0,onClick:()=>x(``)}):void 0,fill:!0})})})]})]})},me=({logs:e,setSelectedLog:n,setIsDrawerOpen:r,lastLogElementRef:i,prevLatestTimestamp:a,realtimeRefresh:o})=>{let{t:s}=m();return(0,X.jsx)(`div`,{className:`space-y-3 py-4`,children:e.map((c,l)=>{let u=o&&a!==null&&c.timestamp>a,d=(c.encrypt_version??0)>0||!!(c.kem_key_id||c.encrypted_payload),f=d&&(!c.domain||c.domain===`[Encrypted]`),p=d&&!!(c.domain&&c.domain!==`[Encrypted]`);return(0,X.jsxs)(E,{interactive:!0,onClick:()=>{n(c),r(!0)},className:L(`p-3 dark:bg-gray-900 rounded-xl border border-gray-200 dark:border-gray-800 shadow-sm overflow-hidden`,{"animate-row-glow":u}),ref:l===e.length-1?i:null,children:[(0,X.jsxs)(`div`,{className:`flex justify-between items-start mb-2`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-2 min-w-0`,children:[f?(0,X.jsx)(t,{size:14,className:`text-amber-500 shrink-0`}):(0,X.jsx)(`img`,{src:`/api/icon/${c.domain.replace(/^\*\./,``)}.ico`,className:`w-4 h-4 rounded-sm shrink-0`,alt:``,referrerPolicy:`no-referrer`,onError:e=>e.currentTarget.style.opacity=`0`}),(0,X.jsx)(`span`,{className:L(`font-bold text-sm truncate`,{"italic text-gray-400 dark:text-gray-500":f}),children:f?s(`logs.encryptedRecord`,`[加密记录]`):c.domain}),p&&(0,X.jsx)(t,{size:12,className:`text-emerald-500 shrink-0 opacity-80`})]}),(0,X.jsx)(P,{minimal:!0,round:!0,intent:c.action===`PASS`?C.SUCCESS:c.action===`BLOCK`?C.DANGER:C.WARNING,className:`text-[10px] shrink-0`,children:c.action})]}),(0,X.jsxs)(`div`,{className:`flex justify-between items-center`,children:[(0,X.jsxs)(`div`,{className:`flex gap-2 items-center`,children:[(0,X.jsx)(`span`,{className:`text-[10px] font-mono opacity-50`,children:new Date(c.timestamp*1e3).toLocaleTimeString([],{hour12:!1})}),(0,X.jsx)(`span`,{className:`text-[10px] bg-gray-100 dark:bg-gray-800 px-1 rounded opacity-60`,children:c.record_type}),c.access_point_name&&(0,X.jsx)(`span`,{className:`text-[10px] opacity-50 truncate max-w-25`,children:c.access_point_name})]}),(0,X.jsx)(`div`,{className:`text-[10px] opacity-40 font-mono italic`,children:c.latency?`${c.latency}ms`:``})]})]},c.id)})})},he=({logs:e,setSelectedLog:n,setIsDrawerOpen:r,lastLogElementRef:i,prevLatestTimestamp:a,realtimeRefresh:o})=>{let{t:s}=m(),c=[{key:`time`,header:s(`logs.tableTime`),headerClassName:`w-24 rounded-tl-xl`,cellClassName:`font-mono text-[11px] opacity-60`,render:e=>new Date(e.timestamp*1e3).toLocaleTimeString([],{hour12:!1})},{key:`domain`,header:s(`logs.tableDomain`),headerClassName:`w-1/4`,render:e=>{let n=(e.encrypt_version??0)>0||!!(e.kem_key_id||e.encrypted_payload),r=n&&(!e.domain||e.domain===`[Encrypted]`),i=n&&!!(e.domain&&e.domain!==`[Encrypted]`);return(0,X.jsxs)(`div`,{className:`flex items-center gap-2 truncate`,children:[r?(0,X.jsx)(t,{size:14,className:`text-amber-500 shrink-0`}):(0,X.jsx)(`img`,{src:`/api/icon/${e.domain.replace(/^\*\./,``)}.ico`,className:`w-4 h-4 rounded-sm shrink-0`,alt:``,referrerPolicy:`no-referrer`}),(0,X.jsx)(`span`,{className:L(`font-bold text-sm truncate`,{"italic text-gray-400 dark:text-gray-500":r}),children:r?s(`logs.encryptedRecord`,`[加密记录]`):e.domain}),i&&(0,X.jsx)(`span`,{title:s(`settings.e2eeEnabled`,`已加密`),className:`inline-flex items-center`,children:(0,X.jsx)(t,{size:12,className:`text-emerald-500 shrink-0 opacity-80`})})]})}},{key:`answer`,header:s(`logs.tableAnswer`),headerClassName:`w-1/4`,cellClassName:`truncate font-mono text-[11px] opacity-70`,render:e=>e.answer||`-`},{key:`source`,header:s(`logs.tableSource`),headerClassName:`w-32`,render:e=>(0,X.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,X.jsx)(P,{minimal:!0,className:`font-mono text-[10px]`,title:e.geo_country||`Unknown`,children:q(e.geo_country)}),e.access_point_name&&(0,X.jsx)(`span`,{className:`text-xs opacity-70 truncate max-w-20`,title:e.access_point_name,children:e.access_point_name})]})},{key:`type`,header:s(`logs.tableType`),headerClassName:`w-20`,cellClassName:`text-center`,render:e=>(0,X.jsx)(`code`,{className:`text-[10px]`,children:e.record_type})},{key:`status`,header:s(`logs.tableStatus`),headerClassName:`w-28`,cellClassName:`text-center`,render:e=>(0,X.jsx)(`span`,{className:L(`bp6-tag`,`bp6-fill`,`bp6-minimal`,`bp6-round`,{"bp6-intent-success":e.action===`PASS`,"bp6-intent-danger":e.action===`BLOCK`,"bp6-intent-warning":e.action===`REDIRECT`}),children:(0,X.jsx)(`span`,{className:`bp6-text-overflow-ellipsis bp6-fill text-center`,children:e.action})})},{key:`reason`,header:s(`logs.tableReason`),headerClassName:`rounded-tr-xl`,cellClassName:`text-xs text-gray-500 italic truncate`,render:e=>e.reason||`-`}];return(0,X.jsx)(`div`,{className:`min-w-full inline-block align-middle py-0`,children:(0,X.jsx)(`div`,{className:`bg-white dark:bg-gray-900 rounded-xl border border-gray-200 dark:border-gray-800 shadow-sm overflow-visible`,children:(0,X.jsxs)(F,{interactive:!0,striped:!0,className:`w-full table-fixed`,children:[(0,X.jsx)(`thead`,{className:`sticky top-0 z-20 backdrop-blur-md`,children:(0,X.jsx)(`tr`,{children:c.map(e=>(0,X.jsx)(`th`,{className:L(`px-4 py-3 text-xs font-bold uppercase text-gray-500 bg-white/80 dark:bg-gray-900/80 border-b border-gray-100 dark:border-gray-800`,e.headerClassName),children:e.header},e.key))})}),(0,X.jsx)(`tbody`,{className:`divide-y divide-gray-100 dark:divide-gray-800`,children:e.map((t,s)=>{let l=o&&a!==null&&t.timestamp>a;return(0,X.jsx)(`tr`,{onClick:()=>{n(t),r(!0)},className:L(`cursor-pointer`,{"animate-row-glow":l}),ref:s===e.length-1?i:null,children:c.map(e=>(0,X.jsx)(`td`,{className:L(`px-4 py-3`,e.cellClassName),children:e.render(t,s)},e.key))},t.id)})})]})})})},ge=({logs:e,loading:t,loadingMore:n,hasMore:r,realtimeRefresh:i,isMobile:a,searchQuery:o,scrollContainerRef:s,lastLogElementRef:c,prevLatestTimestamp:l,setSelectedLog:u,setIsDrawerOpen:d,logRetentionDays:f})=>{let{t:p}=m(),[g,_]=(0,Y.useState)(!1),v=(0,Y.useCallback)(()=>{s.current&&_(s.current.scrollTop>300)},[s]);return(0,Y.useEffect)(()=>{let e=s.current;if(e)return e.addEventListener(`scroll`,v,{passive:!0}),v(),()=>{e.removeEventListener(`scroll`,v)}},[s,v,e]),(0,X.jsxs)(`div`,{className:`flex-1 relative overflow-hidden flex flex-col min-h-0`,children:[(0,X.jsxs)(`div`,{ref:s,onScroll:v,className:L(`flex-1 overflow-y-auto`,a?`px-1`:`px-0`),children:[e.length===0&&!t?(0,X.jsx)(`div`,{className:`py-20`,children:(0,X.jsx)(y,{title:f===0?p(`logs.loggingDisabledTitle`,`日志记录已关闭`):p(o?`logs.noResults`:`logs.noRecords`),icon:f===0?`disable`:o?`search`:`outdated`,intent:f===0?C.WARNING:C.NONE,children:f===0?p(`logs.loggingDisabledDesc`,`当前配置的日志留存已设置为“关闭”,系统不记录任何查询日志。如需查看,请在设置中启用日志留存。`):o?p(`logs.noResultsDesc`,{query:o}):p(`logs.noRecordsDesc`)})}):a?(0,X.jsx)(me,{logs:e,setSelectedLog:u,setIsDrawerOpen:d,lastLogElementRef:c,prevLatestTimestamp:l,realtimeRefresh:i}):(0,X.jsx)(he,{logs:e,setSelectedLog:u,setIsDrawerOpen:d,lastLogElementRef:c,prevLatestTimestamp:l,realtimeRefresh:i}),(0,X.jsx)(`div`,{className:`p-6 flex flex-col items-center`,children:n?(0,X.jsx)(S,{size:16}):i?e.length>0&&(0,X.jsx)(`span`,{className:`text-[10px] opacity-30 italic`,children:p(`logs.realtimeLoadMoreTip`)}):!r&&e.length>0&&(0,X.jsx)(`span`,{className:`text-[10px] opacity-30 italic`,children:p(`logs.loadedAll`,{count:e.length})})})]}),(0,X.jsx)(`div`,{className:L(`absolute z-30 pointer-events-none transition-all duration-300 ease-out`,a?`bottom-20 right-3`:`bottom-6 right-6`,g?`opacity-100 translate-y-0`:`opacity-0 translate-y-3`),children:(0,X.jsx)(`button`,{type:`button`,onClick:()=>{s.current?.scrollTo({top:0,behavior:`smooth`})},"aria-label":p(`logs.scrollToTop`),title:p(`logs.scrollToTop`),className:L(`pointer-events-auto group inline-flex items-center gap-1.5 rounded-full select-none`,`backdrop-blur-md bg-white/70 dark:bg-gray-900/70 hover:bg-white/90 dark:hover:bg-gray-800/90`,`border border-gray-200/80 dark:border-gray-700/80 hover:border-gray-300 dark:hover:border-gray-600`,`text-gray-700 dark:text-gray-200 hover:text-gray-950 dark:hover:text-white`,`shadow-sm hover:shadow active:scale-95 transition-all duration-200 cursor-pointer`,a?`px-2.5 py-1.5 text-[11px]`:`px-3.5 py-2 text-xs`),children:(0,X.jsx)(h,{size:a?13:15,strokeWidth:2.4,className:`transition-transform duration-200 group-hover:scale-105`})})})]})};function _e(e,t,n){let[r,i]=(0,Y.useState)(null),[a,o]=(0,Y.useState)(!1);return(0,Y.useEffect)(()=>{if(e&&t?.id){o(!0),i(t);let e=new AbortController;return ee(n,t.id,t.timestamp,{signal:e.signal}).then(async r=>{if(!e.signal.aborted)try{let e=r?.encrypt_version??t.encrypt_version,a=await V.decryptLogEntry(n,r);i(n=>({...n||t,...a,encrypt_version:e??a.encrypt_version}))}catch{i(e=>({...e||t,...r}))}}).catch(e=>{e.name!==`AbortError`&&(console.error(e),i(e=>e||t))}).finally(()=>{e.signal.aborted||o(!1)}),()=>{e.abort()}}else i(null)},[e,t?.id,n]),{detailedLog:r,loading:a}}const Z=({label:e,value:t,bold:n,italic:r})=>(0,X.jsxs)(`div`,{className:`flex justify-between items-start gap-4`,children:[(0,X.jsx)(`span`,{className:`text-xs opacity-50 mt-1`,children:e}),(0,X.jsx)(`span`,{className:L(`text-sm text-right`,n&&`font-bold`,r&&`italic`),children:t})]}),ve=({selectedLog:e,detailedLog:n,loading:r})=>{let{t:i}=m(),a=n?.encrypt_version??e.encrypt_version??(n?.kem_key_id||e.kem_key_id?2:0),o=a>0||!!(e.kem_key_id||e.encrypted_payload||n?.kem_key_id||n?.encrypted_payload),s=a===2||!!(e.kem_key_id||n?.kem_key_id),c=o&&(!e.domain||e.domain===`[Encrypted]`);return(0,X.jsx)(M,{title:i(`logs.basicInfo`),icon:(0,X.jsx)(p,{size:16}),className:`shadow-none! rounded-lg!`,children:(0,X.jsx)(O,{children:(0,X.jsxs)(`div`,{className:`space-y-3`,children:[(0,X.jsx)(Z,{label:i(`logs.detailDomain`),value:(0,X.jsxs)(`div`,{className:`flex items-center gap-2 justify-end font-bold`,children:[c?(0,X.jsx)(t,{size:14,className:`text-amber-500`}):(0,X.jsx)(`img`,{src:`/api/icon/${e.domain.replace(/^\*\./,``)}.ico`,className:`w-4 h-4 rounded-sm`,alt:``,referrerPolicy:`no-referrer`,onError:e=>e.currentTarget.style.display=`none`}),(0,X.jsx)(`span`,{className:L({"italic text-gray-400 dark:text-gray-500":c}),children:c?i(`logs.encryptedRecord`,`[加密记录]`):e.domain})]}),bold:!0}),(0,X.jsx)(Z,{label:i(`logs.detailType`),value:e.record_type}),(0,X.jsx)(Z,{label:i(`logs.detailLatency`),value:e.latency?`${e.latency} ms`:`-`}),(0,X.jsx)(Z,{label:i(`logs.detailAccessPoint`),value:(()=>{let t=n?.access_point_name||e.access_point_name,i=n?.access_point_id||e.access_point_id;return t?i&&i!==t?(0,X.jsx)(`span`,{title:i,className:`cursor-help`,children:t}):t:i?(0,X.jsx)(`span`,{className:`font-mono text-xs`,children:i}):r?(0,X.jsx)(S,{size:12}):`-`})()}),(0,X.jsx)(Z,{label:i(`logs.detailProfile`),value:n?.profile_name||n?.client_ip||e.client_ip||(r?(0,X.jsx)(S,{size:12}):`-`)}),(0,X.jsx)(Z,{label:i(`logs.detailTime`),value:B(new Date(e.timestamp*1e3))}),(0,X.jsx)(Z,{label:i(`logs.detailStatus`),value:(0,X.jsx)(P,{minimal:!0,intent:e.action===`PASS`?C.SUCCESS:e.action===`BLOCK`?C.DANGER:C.WARNING,children:e.action})}),(0,X.jsx)(Z,{label:i(`logs.detailUpstream`),value:n?.upstream||e.upstream||(r?(0,X.jsx)(S,{size:12}):`-`)}),(0,X.jsx)(Z,{label:i(`logs.detailReason`),value:e.reason||i(`logs.detailNoReason`),italic:!0}),(0,X.jsx)(Z,{label:i(`logs.detailECS`),value:n?.ecs||e.ecs||(r?(0,X.jsx)(S,{size:12}):`-`),italic:!0}),(0,X.jsx)(Z,{label:i(`logs.detailIsClientEncrypted`,`是否用户端加密`),value:o?(0,X.jsxs)(`div`,{className:`flex items-center gap-1.5 justify-end`,children:[(0,X.jsx)(t,{size:13,className:c?`text-amber-500`:`text-emerald-500`}),(0,X.jsxs)(`span`,{className:L(`text-xs font-medium`,c?`text-amber-600 dark:text-amber-400`:`text-emerald-600 dark:text-emerald-400`),children:[c?i(`logs.encryptedLocked`,`是 (未解锁)`):i(`logs.encryptedYes`,`是`),s?` (PQC)`:``]})]}):(0,X.jsx)(`span`,{className:`text-xs text-gray-400 dark:text-gray-500`,children:i(`logs.notEncrypted`,`否`)})})]})})})},ye=({selectedLog:e})=>{let{t}=m(),n=e.record_type===`HTTPS`||e.record_type===`SVCB`||e.record_type===`TYPE65`||e.record_type===`TYPE64`,r=n&&(e.reason===`ECH Rewritten`||(e.reason?.toLowerCase().includes(`rewritten`)??!1));return(0,X.jsx)(M,{title:(0,X.jsxs)(`div`,{className:`flex items-center justify-between w-full pr-2`,children:[(0,X.jsx)(`span`,{children:t(`logs.resolutionResult`)}),r&&(0,X.jsx)(P,{minimal:!0,intent:C.PRIMARY,className:`text-xs`,children:t(`logs.rewritten`,`已重写`)})]}),icon:(0,X.jsx)(d,{size:16}),className:`shadow-none! rounded-lg!`,children:(0,X.jsx)(O,{children:(0,X.jsx)(`div`,{className:`bg-gray-50 dark:bg-gray-800 p-3 font-mono text-xs break-all leading-relaxed rounded-lg`,children:(()=>{if(!e.answer)return t(`logs.noResult`);let r=e.answer.split(`
3
+ `).map(e=>e.trim()).filter(Boolean);return r.length===0?t(`logs.noResult`):(0,X.jsx)(`div`,{className:`space-y-2`,children:r.map((e,t)=>{let r=e.match(/^(\d+)\s+([^\s]+)(?:\s+(.*))?$/);if(r&&(n||e.includes(`alpn=`)||e.includes(`ech=`)||e.includes(`ipv4hint=`))){let e=r[1],n=r[2],i=(r[3]||``).split(/\s+/).filter(Boolean);return(0,X.jsxs)(`div`,{className:`bg-white dark:bg-gray-900 p-2.5 rounded-md space-y-2 border border-gray-200 dark:border-gray-700`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-2 text-xs`,children:[(0,X.jsxs)(P,{minimal:!0,intent:C.PRIMARY,children:[`Priority `,e]}),(0,X.jsxs)(`span`,{className:`font-semibold text-gray-700 dark:text-gray-300`,children:[`Target: `,n]})]}),i.length>0&&(0,X.jsx)(`div`,{className:`flex flex-wrap gap-1.5 pt-1 border-t border-gray-100 dark:border-gray-800 text-xs`,children:i.map((e,t)=>{let n=e.indexOf(`=`);if(n===-1)return(0,X.jsx)(P,{minimal:!0,className:`font-mono`,children:e},t);let r=e.substring(0,n),i=e.substring(n+1);return r===`ech`?(0,X.jsxs)(P,{minimal:!0,intent:C.SUCCESS,className:`font-mono break-all max-w-full select-all text-left whitespace-normal h-auto py-1 inline-block`,title:i,children:[(0,X.jsx)(`span`,{className:`font-bold`,children:`ech:`}),` `,i]},t):r===`alpn`?(0,X.jsxs)(P,{minimal:!0,intent:C.WARNING,className:`font-mono`,children:[(0,X.jsx)(`span`,{className:`font-bold`,children:`alpn:`}),` `,i]},t):(0,X.jsxs)(P,{minimal:!0,className:`font-mono`,children:[(0,X.jsxs)(`span`,{className:`font-bold`,children:[r,`:`]}),` `,i]},t)})})]},t)}return(0,X.jsx)(`div`,{className:`space-y-1`,children:e.split(`,`).map(e=>e.trim()).filter(Boolean).map((e,t)=>(0,X.jsx)(`div`,{className:`text-xs font-mono text-gray-800 dark:text-gray-200 select-all`,children:e},t))},t)})})})()})})})},be=({selectedLog:e,detailedLog:t,loading:n})=>{let{t:r,i18n:i}=m(),a=t?.client_ip||e.client_ip,o=t?.geo_country||e.geo_country,s=`Unknown`;if(o){let e=o.toUpperCase().trim();s=e===`LAN`||e===`LOCAL`||e===`PRIVATE`||e===`PRIVATE NETWORK`?r(`setup.privateNetwork`,`Private Network`):e===`UN`||e===`UNKNOWN`||e===`XX`?r(`common.unknown`,`Unknown`):K(o,i.language)||o}let l=t?.dest_country_code||e.dest_country_code,d=t?.dest_country||e.dest_country,f=t?.dest_isp||e.dest_isp,p=null,h=t?.dest_geoip||e.dest_geoip;if(h)try{let e=JSON.parse(h);!l&&e.country_code&&(l=e.country_code);let t=[e.city,e.region,e.country].filter(Boolean),n=d||l||void 0;p={locationTitle:t.length>0?t.join(`, `):n,isp:e.isp||f||void 0,as:e.as||void 0}}catch{}return!p&&(d||l||f)&&(p={locationTitle:d||l||void 0,isp:f||void 0}),(0,X.jsx)(M,{title:r(`logs.networkDetails`),icon:(0,X.jsx)(u,{size:16}),className:`shadow-none! rounded-lg!`,children:(0,X.jsx)(O,{children:(0,X.jsxs)(`div`,{className:`space-y-4`,children:[(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`div`,{className:`text-[10px] uppercase font-bold opacity-50 mb-1`,children:r(`logs.clientSource`)}),(0,X.jsxs)(`div`,{className:`flex justify-between items-center`,children:[(0,X.jsx)(`span`,{className:`font-mono`,children:a||(n?(0,X.jsx)(S,{size:12}):`-`)}),(o||n)&&(0,X.jsx)(P,{minimal:!0,title:s,children:o?q(o):`-`})]})]}),(0,X.jsxs)(`div`,{children:[(0,X.jsxs)(`div`,{className:`flex justify-between items-center mb-1`,children:[(0,X.jsx)(`div`,{className:`text-[10px] uppercase font-bold opacity-50`,children:r(`logs.destination`)}),(l||n)&&(0,X.jsx)(P,{minimal:!0,title:d||l||`Unknown`,children:l?q(l):`-`})]}),n&&!p?(0,X.jsx)(`div`,{className:`flex items-center justify-center py-2`,children:(0,X.jsx)(S,{size:16})}):p?(0,X.jsx)(`div`,{className:`bg-gray-50 dark:bg-gray-800 p-3 rounded-lg mt-1`,children:(0,X.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,X.jsx)(c,{size:16,className:`oklch(60.9% 0.126 221.723) mt-1 shrink-0`}),(0,X.jsxs)(`div`,{children:[p.locationTitle&&(0,X.jsx)(`div`,{className:`font-bold text-sm`,children:p.locationTitle}),(p.isp||p.as)&&(0,X.jsxs)(`div`,{className:`text-xs opacity-70 mt-1`,children:[p.isp,p.as&&(0,X.jsx)(`span`,{className:`opacity-60 block mt-0.5`,children:p.as})]})]})]})}):(0,X.jsx)(`div`,{className:`text-xs opacity-50 py-1`,children:`-`})]})]})})})},xe=({selectedLog:e,onQuickAction:t})=>{let{t:n}=m(),i=(e.encrypt_version??0)>0&&(!e.domain||e.domain===`[Encrypted]`);return(0,X.jsx)(M,{title:n(`logs.quickActions`),icon:(0,X.jsx)(s,{size:16}),className:`shadow-none! rounded-lg!`,children:(0,X.jsx)(O,{children:i?(0,X.jsx)(`p`,{className:`text-xs text-center text-gray-500 italic py-2 m-0`,children:n(`settings.e2eeUnlockPrompt`,`此记录已加密,请先解锁私钥后再进行操作。`)}):(0,X.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,X.jsx)(T,{fill:!0,intent:C.SUCCESS,icon:(0,X.jsx)(o,{size:16}),text:n(`logs.actionAllow`),onClick:()=>t?.(e.domain,`ALLOW`)}),(0,X.jsx)(T,{fill:!0,intent:C.DANGER,icon:(0,X.jsx)(f,{size:16}),text:n(`logs.actionBlock`),onClick:()=>t?.(e.domain,`BLOCK`)}),(0,X.jsx)(T,{fill:!0,icon:(0,X.jsx)(r,{size:16}),text:n(`logs.actionRedirect`),onClick:()=>t?.(e.domain,`REDIRECT`,e.record_type)})]})})})},Se=({isDrawerOpen:e,setIsDrawerOpen:t,selectedLog:n,profileId:r,isMobile:i,onQuickAction:a})=>{let{t:o}=m(),{detailedLog:s,loading:c}=_e(e,n,r);return(0,X.jsx)(J,{isOpen:e&&n!==null,onClose:()=>t(!1),title:(0,X.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,X.jsx)(p,{size:18}),(0,X.jsx)(`span`,{children:o(`logs.logDetails`)})]}),icon:`info-sign`,size:i?`100%`:`450px`,children:n&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(ve,{selectedLog:n,detailedLog:s,loading:c}),(0,X.jsx)(ye,{selectedLog:n}),(0,X.jsx)(be,{selectedLog:n,detailedLog:s,loading:c}),(0,X.jsx)(xe,{selectedLog:n,onQuickAction:a})]})})};function Ce(e){let[t,n]=(0,Y.useState)(`1h`),[r,i]=(0,Y.useState)({start:``,end:``}),[a,o]=(0,Y.useState)(null),[s,c]=(0,Y.useState)(null),[l,u]=(0,Y.useState)([]),[d,f]=(0,Y.useState)(null),[p,m]=(0,Y.useState)(null),[h,g]=(0,Y.useState)(``);return(0,Y.useEffect)(()=>{U(e).then(u).catch(console.error)},[e]),(0,Y.useEffect)(()=>{m(null)},[d]),{range:t,setRange:n,customRange:r,setCustomRange:i,statusFilter:a,setStatusFilter:o,accessPointIdFilter:s,setAccessPointIdFilter:c,accessPoints:l,destCountryFilter:d,setDestCountryFilter:f,ispFilter:p,setIspFilter:m,searchQuery:h,setSearchQuery:g}}function we(e){let[t,n]=(0,Y.useState)(30);return(0,Y.useEffect)(()=>{te(e).then(e=>{try{let t=JSON.parse(e.settings||`{}`);n(t.log_retention_days===void 0?30:Number(t.log_retention_days))}catch(e){console.error(`[useProfileRetention] Failed to parse settings:`,e)}}).catch(e=>console.error(`[useProfileRetention] Failed to fetch profile details:`,e))},[e]),t}function Te(e,t){let n=Math.floor(Date.now()/1e3);if(e===`custom`&&t.start&&t.end)return{since:Math.floor(new Date(t.start).getTime()/1e3),until:Math.floor(new Date(t.end).getTime()/1e3)};let r;switch(e){case`10m`:r=n-600;break;case`1h`:r=n-3600;break;case`24h`:r=n-86400;break;case`7d`:r=n-604800;break;case`30d`:r=n-2592e3;break;default:r=n-3600;break}return{since:r,until:n}}function Q(e){if(!(!e||e.length===0)&&`serviceWorker`in navigator&&navigator.serviceWorker.controller){let t=Array.from(new Set(e.map(e=>e.domain)));navigator.serviceWorker.controller.postMessage({type:`PREFETCH_ICONS`,domains:t})}}async function Ee(e){let{profileId:t,currentRange:n,customRange:r,since:i,until:a,limit:o,isInitial:s,statusFilter:c,accessPointIdFilter:l,destCountryFilter:u,ispFilter:d,searchQuery:f,lastTimestamp:p,signal:m}=e,h=new URLSearchParams({range:n,limit:String(o)});n===`custom`&&r.start&&r.end&&(h.set(`start`,String(i)),h.set(`end`,String(a))),c&&h.set(`status`,c),l&&h.set(`access_point_id`,l),u&&h.set(`dest_country`,u),d&&h.set(`isp`,d),f&&h.set(`search`,f),!s&&p!==void 0&&h.set(`before`,String(p));let g=W(t,h.toString(),{signal:m}),_=Promise.resolve(null);if(s){let e=new URLSearchParams({range:n});n===`custom`&&r.start&&r.end&&(e.set(`start`,String(i)),e.set(`end`,String(a))),f&&e.set(`search`,f),c&&e.set(`status`,c),l&&e.set(`access_point_id`,l),u&&e.set(`dest_country`,u),d&&e.set(`isp`,d),_=H(t,`summary`,e.toString(),{signal:m})}let[v,y]=await Promise.all([g,_]),b=null;if(y){let e={total:0,pass:0,block:0,redirect:0};y.forEach(t=>{let n=t.count;e.total+=n,t.action===`PASS`?e.pass=n:t.action===`BLOCK`?e.block=n:t.action===`REDIRECT`&&(e.redirect=n)}),b=e}return{logs:v||[],stats:b}}async function De(e,t,n,r){if(!await z.init()||t.aborted)return{success:!1};let{profileId:i,searchQuery:a,statusFilter:o,accessPointIdFilter:s,destCountryFilter:c,ispFilter:l,since:u,until:d,limit:f}=e,p=await z.queryLogs({profileId:i,search:a||void 0,action:o||void 0,accessPointId:s||void 0,destCountry:c||void 0,isp:l||void 0,since:u,until:d,before:void 0,limit:f,offset:0});if(t.aborted)return{success:!1};p.rows.length>0&&r&&r({rows:p.rows,hasMore:p.rows.length>=f,stats:p.stats});try{let e=await z.syncProfileLogs(i,void 0,u,t,n);if(!t.aborted&&(e>0||p.rows.length===0)&&(p=await z.queryLogs({profileId:i,search:a||void 0,action:o||void 0,accessPointId:s||void 0,destCountry:c||void 0,isp:l||void 0,since:u,until:d,before:void 0,limit:f,offset:0}),t.aborted))return{success:!1}}catch(e){e.name!==`AbortError`&&console.warn(`[localDbStrategy] Incremental sync error:`,e)}return p.rows.length>0?{success:!0,result:{rows:p.rows,hasMore:p.rows.length>=f,stats:p.stats}}:{success:!1}}async function Oe(e,t,n){if(!await z.init()||n.aborted)return{success:!1};let{profileId:r,searchQuery:i,statusFilter:a,accessPointIdFilter:o,destCountryFilter:s,ispFilter:c,since:l,until:u,limit:d}=e,f=await z.queryLogs({profileId:r,search:i||void 0,action:a||void 0,accessPointId:o||void 0,destCountry:s||void 0,isp:c||void 0,since:l,until:u,before:t,limit:d,offset:0});if(n.aborted)return{success:!1};if(f.rows.length>=d)return{success:!0,result:{rows:f.rows,hasMore:f.rows.length>=d}};if(t>l)try{let e=await z.backfillLogs(r,t,l,d,n);if(n.aborted)return{success:!1};if(e.length>0){let f=await z.queryLogs({profileId:r,search:i||void 0,action:a||void 0,accessPointId:o||void 0,destCountry:s||void 0,isp:c||void 0,since:l,until:u,before:t,limit:d,offset:0});return n.aborted?{success:!1}:{success:!0,result:{rows:f.rows,hasMore:f.rows.length>=d&&e.length>=d}}}return{success:!0,result:{rows:f.rows,hasMore:!1}}}catch(e){return e.name!==`AbortError`&&console.warn(`[localDbStrategy] Backfill error:`,e),{success:!0,result:{rows:f.rows,hasMore:!1}}}return{success:!0,result:{rows:f.rows,hasMore:!1}}}function ke({profileId:e,range:t,customRange:n,statusFilter:r,accessPointIdFilter:i,destCountryFilter:a,ispFilter:o,searchQuery:s,realtimeRefresh:c}){let[l,u]=(0,Y.useState)([]),[d,f]=(0,Y.useState)(!0),[p,m]=(0,Y.useState)(!1),[h,g]=(0,Y.useState)(!1),[_,v]=(0,Y.useState)(!0),[y,b]=(0,Y.useState)(null),[x,S]=(0,Y.useState)(null),C=(0,Y.useRef)([]);(0,Y.useEffect)(()=>{C.current=l},[l]);let w=(0,Y.useRef)(null),T=(0,Y.useRef)(!1);return(0,Y.useEffect)(()=>()=>{w.current&&w.current.abort()},[]),{logs:l,setLogs:u,loading:d,loadingMore:p,syncing:h,hasMore:_,setHasMore:v,stats:y,setStats:b,prevLatestTimestamp:x,setPrevLatestTimestamp:S,fetchLogs:(0,Y.useCallback)(async(t,l=!0,d=!1,p=!1)=>{w.current&&w.current.abort();let h=new AbortController;w.current=h,T.current=!0,l?f(!0):m(!0);try{let _=c?25:50,{since:y,until:x}=Te(t,n),E={profileId:e,searchQuery:s,statusFilter:r,accessPointIdFilter:i,destCountryFilter:a,ispFilter:o,since:y,until:x,limit:_},D=!1;if(l){d||g(!0);let l=new URLSearchParams({range:t});t===`custom`&&n.start&&n.end&&(l.set(`start`,String(y)),l.set(`end`,String(x))),s&&l.set(`search`,s),r&&l.set(`status`,r),i&&l.set(`access_point_id`,i),a&&l.set(`dest_country`,a),o&&l.set(`isp`,o),H(e,`summary`,l.toString(),{signal:h.signal}).then(e=>{if(h.signal.aborted||!e)return;let t={total:0,pass:0,block:0,redirect:0};e.forEach(e=>{let n=Number(e.count)||0;t.total+=n,e.action===`PASS`?t.pass=n:e.action===`BLOCK`?t.block=n:e.action===`REDIRECT`&&(t.redirect=n)}),b(t)}).catch(()=>{});let m=await De(E,h.signal,p,e=>{D=!0,S(d&&C.current.length>0?C.current[0].timestamp:null),u(e.rows),v(c?!1:e.hasMore),c&&e.rows.length>0&&R.updateCursor(e.rows[0].timestamp,e.rows[0].id),e.stats&&b(e.stats),f(!1)});if(h.signal.aborted)return;m.success&&m.result&&(D=!0,S(d&&C.current.length>0?C.current[0].timestamp:null),u(m.result.rows),v(c?!1:m.result.hasMore),c&&m.result.rows.length>0&&R.updateCursor(m.result.rows[0].timestamp,m.result.rows[0].id),m.result.stats&&b(m.result.stats))}else{let e=C.current.length>0?C.current[C.current.length-1].timestamp:void 0;if(e!==void 0){let t=await Oe(E,e,h.signal);if(h.signal.aborted)return;t.success&&t.result&&(D=!0,u(e=>[...e,...t.result.rows]),v(c?!1:t.result.hasMore))}else D=!0,v(!1)}if(D){Q(C.current),w.current===h&&(f(!1),m(!1),g(!1),T.current=!1);return}let O=await Ee({profileId:e,currentRange:t,customRange:n,since:y,until:x,limit:_,isInitial:l,statusFilter:r,accessPointIdFilter:i,destCountryFilter:a,ispFilter:o,searchQuery:s,lastTimestamp:!l&&C.current.length>0?C.current[C.current.length-1].timestamp:void 0,signal:h.signal});if(h.signal.aborted)return;l?(S(d&&C.current.length>0?C.current[0].timestamp:null),u(O.logs),v(c?!1:O.logs.length>=_),O.stats&&b(O.stats)):(u(e=>[...e,...O.logs]),v(c?!1:O.logs.length>=_)),O.logs.length>0&&(c&&R.updateCursor(O.logs[0].timestamp,O.logs[0].id),Q(O.logs))}catch(e){e.name!==`AbortError`&&console.error(e)}finally{w.current===h&&(f(!1),m(!1),g(!1),T.current=!1)}},[e,c,n,s,r,i,a,o]),isFetchingRef:T,logsRef:C}}function Ae({realtimeRefresh:e,statusFilter:t,accessPointIdFilter:n,destCountryFilter:r,ispFilter:i,searchQuery:a,pageSize:o,logsRef:s,setLogs:c,setStats:l,setPrevLatestTimestamp:u}){(0,Y.useEffect)(()=>{if(e)return R.onNewLogs(e=>{if(!e||e.length===0)return;let d=e.filter(e=>{if(t&&e.action!==t||n&&e.access_point_id!==n||r&&(e.dest_country_code||e.dest_country)!==r||i&&e.dest_isp!==i)return!1;if(a){let t=a.toLowerCase(),n=e.domain?.toLowerCase().includes(t),r=e.client_ip?.toLowerCase().includes(t),i=e.reason?.toLowerCase().includes(t);if(!n&&!r&&!i)return!1}return!0});d.length!==0&&(u(s.current.length>0?s.current[0].timestamp:null),c(e=>{let t=new Set(e.map(e=>`${e.timestamp}-${e.id}`)),n=d.filter(e=>!t.has(`${e.timestamp}-${e.id}`));return n.length===0?e:[...n,...e].slice(0,o)}),l(t=>{if(!t)return t;let n=0,r=0,i=0;for(let t of e)t.action===`PASS`?n++:t.action===`BLOCK`?r++:t.action===`REDIRECT`&&i++;return{total:t.total+e.length,pass:t.pass+n,block:t.block+r,redirect:t.redirect+i}}))})},[e,t,n,r,i,a,o,s,c,l,u])}function je({profileId:e,range:t,customRange:n,statusFilter:r,accessPointIdFilter:i,destCountryFilter:a,ispFilter:o,searchQuery:s,realtimeRefresh:c}){let l=we(e),{logs:u,setLogs:d,loading:f,loadingMore:p,syncing:m,hasMore:h,stats:g,setStats:_,prevLatestTimestamp:v,setPrevLatestTimestamp:y,fetchLogs:b,isFetchingRef:x,logsRef:S}=ke({profileId:e,range:t,customRange:n,statusFilter:r,accessPointIdFilter:i,destCountryFilter:a,ispFilter:o,searchQuery:s,realtimeRefresh:c});Ae({realtimeRefresh:c,statusFilter:r,accessPointIdFilter:i,destCountryFilter:a,ispFilter:o,searchQuery:s,pageSize:25,logsRef:S,setLogs:d,setStats:_,setPrevLatestTimestamp:y});let C=(0,Y.useRef)(null),w=(0,Y.useRef)(null),T=(0,Y.useCallback)(()=>{c||x.current||f||p||!h||b(t,!1)},[f,p,h,t,c,b,x]),E=(0,Y.useCallback)(e=>{w.current&&w.current.disconnect(),!(f||p||c||!h)&&(w.current=new IntersectionObserver(e=>{e[0]?.isIntersecting&&h&&!x.current&&T()},{root:C.current,rootMargin:`100px`}),e&&w.current.observe(e))},[f,p,h,T,c,x]);return(0,Y.useEffect)(()=>{if(t===`custom`&&(!n.start||!n.end))return;let e=setTimeout(()=>{b(t,!0)},s?500:0);return()=>clearTimeout(e)},[t,n.start,n.end,s,b]),{logs:u,loading:f,loadingMore:p,syncing:m,hasMore:h,stats:g,logRetentionDays:l,prevLatestTimestamp:v,scrollContainerRef:C,lastLogElementRef:E,fetchLogs:b,isFetchingRef:x,logsRef:S}}function Me({profileId:e,range:t,searchQuery:n,realtimeRefresh:r,scrollContainerRef:i,isFetchingRef:a,fetchLogs:o,logsRef:s}){let c=(0,Y.useRef)({range:t,searchQuery:n,fetchLogs:o,logsRef:s});(0,Y.useEffect)(()=>{c.current={range:t,searchQuery:n,fetchLogs:o,logsRef:s}}),(0,Y.useEffect)(()=>{if(!r){R.disconnect();return}let t=!1,n=null,o=()=>{n||=setInterval(()=>{let{range:e,searchQuery:n,fetchLogs:r}=c.current;!t&&document.visibilityState===`visible`&&i.current&&i.current.scrollTop<50&&!a.current&&!n&&e!==`custom`&&r(e,!0,!0)},8e3)},s=()=>{n&&=(clearInterval(n),null)},l=R.onStatusChange(e=>{t=e,e?s():o()}),u=c.current.logsRef.current,d=u.length>0?u[0]:null,f=d?d.timestamp:Math.floor(Date.now()/1e3)-60,p=d?d.id:0;R.connect(e,f,p);let m=setTimeout(()=>{t||o()},2500),h=()=>{if(document.visibilityState===`visible`)if(t){let e=c.current.logsRef.current,t=e.length>0?e[0]:null;t&&R.updateCursor(t.timestamp,t.id)}else{let{range:e,fetchLogs:t}=c.current;t(e,!0,!0)}};return document.addEventListener(`visibilitychange`,h),()=>{clearTimeout(m),s(),l(),R.disconnect(),document.removeEventListener(`visibilitychange`,h)}},[e,r])}function $(e){let t=new Date(e*1e3),n=-t.getTimezoneOffset(),r=n>=0?`+`:`-`,i=e=>String(e).padStart(2,`0`);return t.getFullYear()+`-`+i(t.getMonth()+1)+`-`+i(t.getDate())+`T`+i(t.getHours())+`:`+i(t.getMinutes())+`:`+i(t.getSeconds())+`.`+(e=>String(e).padStart(3,`0`))(t.getMilliseconds())+(n===0?`Z`:r+i(Math.floor(Math.abs(n)/60))+`:`+i(Math.abs(n)%60))}function Ne(e){let t=[`profile_id`,`access_point_id`,`time`,`client_ip`,`geo_country`,`domain`,`record_type`,`action`,`reason`,`answer`,`dest_geoip`,`ecs`,`upstream`,`latency`],n=[t.join(`,`)];for(let r of e){let e=t.map(e=>{let t=``;if(e===`time`)t=$(r.timestamp);else{let n=r[e];t=n==null?e===`dest_geoip`&&(r.dest_country_code||r.dest_country||r.dest_isp)?JSON.stringify({country_code:r.dest_country_code||``,country:r.dest_country||``,isp:r.dest_isp||``}):``:typeof n==`object`?JSON.stringify(n):String(n)}(/^[\t\r\n ]*[=+\-@]/.test(t)||t.startsWith(` `)||t.startsWith(`\r`))&&(t=`'${t}`);let n=t.replace(/"/g,`""`);return n.includes(`,`)||n.includes(`
4
+ `)||n.includes(`\r`)||n.includes(`"`)?`"${n}"`:n});n.push(e.join(`,`))}return n.join(`
5
+ `)}function Pe(e,t){let n=new Blob([e],{type:`text/csv;charset=utf-8;`}),r=URL.createObjectURL(n),i=document.createElement(`a`);i.setAttribute(`href`,r),i.setAttribute(`download`,t),document.body.appendChild(i),i.click(),document.body.removeChild(i),URL.revokeObjectURL(r)}function Fe(e,t,n,r){let i=e=>e.replace(/[:*?"<>|]/g,`-`),a=i($(t)),o=i($(n)),s=i(r.toString());return`query_logs_${e}_${a}_${o}${s?`_${s}`:``}.csv`}function Ie({profileId:e,range:t,customRange:n,statusFilter:r,accessPointIdFilter:i,destCountryFilter:a,ispFilter:o,searchQuery:s,toasterRef:c}){let{t:l}=m(),[u,d]=(0,Y.useState)(!1);return{exporting:u,handleExportLogs:async()=>{d(!0);try{let{since:u,until:d}=Te(t,n),f=new URLSearchParams({range:t});if(t===`custom`&&n.start&&n.end){let e=Math.floor(new Date(n.start).getTime()/1e3),t=Math.floor(new Date(n.end).getTime()/1e3);f.set(`start`,String(e)),f.set(`end`,String(t))}r&&f.set(`status`,r),i&&f.set(`access_point_id`,i),a&&f.set(`dest_country`,a),o&&f.set(`isp`,o),s&&f.set(`search`,s);let p=[],m=!1;try{if(await z.init()){let t=await z.queryLogs({profileId:e,search:s.trim()||void 0,action:r||void 0,accessPointId:i||void 0,destCountry:a||void 0,isp:o||void 0,since:u,until:d,limit:1e5});t&&Array.isArray(t.rows)&&t.rows.length>0&&(p=t.rows)}}catch(e){console.warn(`[LogExport] Local SQLite query failed or unavailable, falling back to server:`,e)}if(!p||p.length===0){m=!0;let{exportProfileLogs:t}=await v(async()=>{let{exportProfileLogs:e}=await import(`./services-B-Y_EKlc.js`);return{exportProfileLogs:e}},__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10])),n=await t(e,f.toString());n&&Array.isArray(n)&&(p=n)}if(!p||p.length===0){c?.current?.show({message:l(`logs.noResults`,`No logs found to export`),intent:C.WARNING});return}if(p.some(e=>(e.encrypt_version??(e.encrypted_payload?1:0))>0)){if(!V.isProfileUnlocked(e))try{await V.unlockProfile(e)}catch(e){console.warn(`[LogExport] Auto-unlock attempt failed or was cancelled:`,e)}p=await V.decryptLogsBatch(e,p),p.some(e=>(e.encrypt_version??(e.encrypted_payload?1:0))>0||e.domain===`[Encrypted]`)&&c?.current?.show({message:l(`logs.e2eeLockedExportWarning`,`部分日志处于加密状态且未解锁,导出的数据可能包含未解密内容。`),intent:C.WARNING,icon:`lock`})}m&&p.length>0&&z.batchInsertLogs(e,p).catch(e=>{console.warn(`[LogExport] Failed to cache exported logs into local SQLite:`,e)}),Pe(Ne(p),Fe(e,p[0].timestamp,p[p.length-1].timestamp,f)),c?.current?.show({message:l(`logs.exportSuccess`,`Logs exported successfully`),intent:C.SUCCESS})}catch(e){console.error(`Failed to export logs`,e),c?.current?.show({message:l(`logs.exportError`,`Failed to export logs`),intent:C.DANGER})}finally{d(!1)}}}}function Le({profileId:e,toasterRef:t}){let[n,r]=(0,Y.useState)(!1),i=Ce(e),a=je({profileId:e,realtimeRefresh:n,range:i.range,customRange:i.customRange,statusFilter:i.statusFilter,accessPointIdFilter:i.accessPointIdFilter,destCountryFilter:i.destCountryFilter,ispFilter:i.ispFilter,searchQuery:i.searchQuery});Me({profileId:e,realtimeRefresh:n,range:i.range,searchQuery:i.searchQuery,scrollContainerRef:a.scrollContainerRef,isFetchingRef:a.isFetchingRef,fetchLogs:a.fetchLogs,logsRef:a.logsRef});let o=Ie({profileId:e,range:i.range,customRange:i.customRange,statusFilter:i.statusFilter,accessPointIdFilter:i.accessPointIdFilter,destCountryFilter:i.destCountryFilter,ispFilter:i.ispFilter,searchQuery:i.searchQuery,toasterRef:t});return{realtimeRefresh:n,setRealtimeRefresh:r,...i,...a,...o}}const Re=({profileId:e,onQuickAction:t,toasterRef:n})=>{let r=ne(),[i,a]=(0,Y.useState)(null),[o,s]=(0,Y.useState)(!1),{realtimeRefresh:c,setRealtimeRefresh:l,range:u,setRange:d,customRange:f,setCustomRange:p,statusFilter:m,setStatusFilter:h,accessPointIdFilter:g,setAccessPointIdFilter:_,accessPoints:v,destCountryFilter:y,setDestCountryFilter:b,ispFilter:x,setIspFilter:C,searchQuery:w,setSearchQuery:T,logs:E,loading:D,loadingMore:O,syncing:k,hasMore:A,stats:j,logRetentionDays:M,prevLatestTimestamp:N,scrollContainerRef:P,lastLogElementRef:F,fetchLogs:I,exporting:L,handleExportLogs:R}=Le({profileId:e,toasterRef:n}),{isE2eeEnabled:z,isE2eeUnlocked:ee,unlocking:B,recoveryDialogOpen:te,setRecoveryDialogOpen:V,recoveryKeyInput:H,setRecoveryKeyInput:U,recoveryError:W,setRecoveryError:G,rotatedKey:K,setRotatedKey:q,copiedKey:J,handleCopyRotatedKey:se,handleUnlockPasskey:ce,handleUnlockRecoveryKey:le}=oe({profileId:e,range:u,fetchLogs:I,toasterRef:n}),ue=new Date().toLocaleString(`sv-SE`).replace(` `,`T`).slice(0,16);return D&&E.length===0?(0,X.jsx)(`div`,{className:`h-full flex items-center justify-center`,children:(0,X.jsx)(S,{})}):(0,X.jsxs)(`div`,{className:`h-full flex flex-col overflow-hidden bg-gray-50/30 dark:bg-gray-950/10 max-w-7xl mx-auto w-full pt-14`,children:[(0,X.jsx)(pe,{profileId:e,range:u,setRange:d,customRange:f,setCustomRange:p,nowStr:ue,fetchLogs:I,isMobile:r,realtimeRefresh:c,setRealtimeRefresh:l,statusFilter:m,setStatusFilter:h,accessPointIdFilter:g,setAccessPointIdFilter:_,accessPoints:v,destCountryFilter:y,setDestCountryFilter:b,ispFilter:x,setIspFilter:C,searchQuery:w,setSearchQuery:T,stats:j,logRetentionDays:M,onExport:R,exporting:L,loading:D,syncing:k}),z&&!ee&&(0,X.jsx)(re,{isMobile:r,unlocking:B,onUnlockPasskey:ce,onOpenRecoveryDialog:()=>{G(``),U(``),V(!0)}}),(0,X.jsx)(ge,{logs:E,loading:D,loadingMore:O,hasMore:A,realtimeRefresh:c,isMobile:r,searchQuery:w,scrollContainerRef:P,lastLogElementRef:F,prevLatestTimestamp:N,setSelectedLog:a,setIsDrawerOpen:s,logRetentionDays:M}),(0,X.jsx)(Se,{isDrawerOpen:o,setIsDrawerOpen:s,selectedLog:i,profileId:e,isMobile:r,onQuickAction:t}),(0,X.jsx)(ae,{isOpen:te,onClose:()=>V(!1),recoveryKeyInput:H,setRecoveryKeyInput:U,recoveryError:W,unlocking:B,onSubmit:le}),(0,X.jsx)(ie,{rotatedKey:K,onClose:()=>q(null),copiedKey:J,onCopyKey:se})]})};export{Re as LogsView};
@@ -1 +1 @@
1
- import{i as e}from"./rolldown-runtime-C4Xdq4VV.js";import{Ct as t,Et as n,It as r,Ot as i,V as a,_t as o,it as s,k as c,nn as l,w as u,wt as d}from"./vendor-react-DYK5a2J9.js";import{S as f,b as p}from"./vendor-icons-other-BTYC6Wvz.js";import"./vendor-i18next-DlmslyBB.js";import{C as m,E as h,F as g,H as _,P as v,S as y,U as b,b as x,d as S,f as C,k as w,p as T,r as E,u as D,w as O,y as k}from"./vendor-ui-core-CodM8CpF.js";import{_t as A}from"./vendor-utils-Bab4qB3W.js";import{U as j,_n as M,dt as N,g as P,ht as F,kt as I,rt as L,yt as R}from"./index-C--PEfmU.js";var z=e(f(),1),B=e(p(),1);const V=({newRule:e,setNewRule:t,addRule:n,loading:r})=>{let{t:i}=l();return(0,B.jsx)(y,{elevation:b.ONE,className:`mb-8 p-6`,children:(0,B.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[(0,B.jsxs)(`div`,{className:`flex flex-col lg:flex-row justify-between gap-4 items-start lg:items-end`,children:[(0,B.jsx)(`div`,{className:`w-full lg:w-48`,children:(0,B.jsx)(T,{label:i(`rules.action`),labelFor:`rule-type`,className:`mb-0`,children:(0,B.jsx)(S,{id:`rule-type`,fill:!0,large:!0,value:e.type,onChange:n=>t({...e,type:n.target.value}),options:[{label:i(`rules.typeBlock`),value:`BLOCK`},{label:i(`rules.typeAllow`),value:`ALLOW`},{label:i(`rules.typeRedirect`),value:`REDIRECT`}]})})}),(0,B.jsx)(`div`,{className:`flex-1 w-full`,children:(0,B.jsx)(T,{label:i(`rules.pattern`),labelFor:`rule-pattern`,className:`mb-0`,children:(0,B.jsx)(C,{id:`rule-pattern`,size:`large`,placeholder:i(`rules.patternPlaceholder`),value:e.pattern,onChange:n=>t({...e,pattern:n.target.value})})})}),e.type!==`REDIRECT`&&(0,B.jsx)(T,{label:``,labelFor:``,className:`mb-0`,children:(0,B.jsx)(v,{intent:_.PRIMARY,size:`large`,icon:(0,B.jsx)(a,{size:18}),onClick:n,loading:r,disabled:r,children:i(`rules.addRule`)})})]}),e.type===`REDIRECT`&&(0,B.jsxs)(`div`,{className:`bg-gray-50 dark:bg-gray-800/50 p-6 rounded-xl border border-gray-200 dark:border-gray-700`,children:[(0,B.jsxs)(`div`,{className:`flex items-center gap-2 mb-4 text-blue-600 dark:text-blue-400`,children:[(0,B.jsx)(s,{size:16}),(0,B.jsx)(`span`,{className:`text-xs font-bold uppercase tracking-wider`,children:i(`rules.redirectSettings`)})]}),(0,B.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-x-8 gap-y-4`,children:[(0,B.jsx)(T,{label:i(`rules.aRecord`),labelInfo:i(`rules.optional`),children:(0,B.jsx)(C,{placeholder:i(`rules.ipv4Placeholder`),value:e.v_a,onChange:n=>t({...e,v_a:n.target.value})})}),(0,B.jsx)(T,{label:i(`rules.aaaaRecord`),labelInfo:i(`rules.optional`),children:(0,B.jsx)(C,{placeholder:i(`rules.ipv6Placeholder`),value:e.v_aaaa,onChange:n=>t({...e,v_aaaa:n.target.value})})}),(0,B.jsx)(T,{label:i(`rules.cnameRecord`),labelInfo:i(`rules.optional`),children:(0,B.jsx)(C,{placeholder:i(`rules.cnamePlaceholder`),value:e.v_cname,onChange:n=>t({...e,v_cname:n.target.value})})}),(0,B.jsx)(T,{label:i(`rules.txtRecord`),labelInfo:i(`rules.optional`),children:(0,B.jsx)(C,{placeholder:i(`rules.txtPlaceholder`),value:e.v_txt,onChange:n=>t({...e,v_txt:n.target.value})})})]}),(0,B.jsx)(`div`,{className:`mt-6 pt-4 border-t border-gray-200 dark:border-gray-700 flex justify-end`,children:(0,B.jsx)(v,{intent:_.PRIMARY,large:!0,icon:(0,B.jsx)(a,{size:18}),onClick:n,text:i(`rules.saveRedirectRule`),loading:r,disabled:r})})]})]})})},H=({rules:e,startEdit:r,getBlockDetail:a})=>{let{t:s}=l(),[u,f]=(0,z.useState)(`created_at`),[p,m]=(0,z.useState)(`desc`),h=e=>{u===e?m(e=>e===`asc`?`desc`:`asc`):(f(e),m(e===`created_at`?`desc`:`asc`))},g=e=>e.type===`REDIRECT`?[e.v_a,e.v_aaaa,e.v_cname,e.v_txt].filter(Boolean).join(` `):e.type===`BLOCK`?a():s(`rules.detailAllow`,`Forward to upstream`),v=(0,z.useMemo)(()=>[...e].sort((e,t)=>{let n=0;switch(u){case`action`:n=e.type.localeCompare(t.type);break;case`pattern`:n=e.pattern.localeCompare(t.pattern);break;case`details`:n=g(e).localeCompare(g(t));break;case`created_at`:n=(e.created_at??e.id)-(t.created_at??t.id);break}return n===0&&(n=e.id-t.id),p===`asc`?n:-n}),[e,u,p,a,s]),y=[{key:`action`,header:s(`rules.tableAction`),headerClassName:`w-32`,render:e=>(0,B.jsxs)(B.Fragment,{children:[e.type===`BLOCK`&&(0,B.jsx)(E,{intent:_.DANGER,minimal:!0,icon:(0,B.jsx)(c,{size:12,className:`mr-1`}),children:s(`rules.labelBlock`)}),e.type===`ALLOW`&&(0,B.jsx)(E,{intent:_.SUCCESS,minimal:!0,icon:(0,B.jsx)(o,{size:12,className:`mr-1`}),children:s(`rules.labelAllow`)}),e.type===`REDIRECT`&&(0,B.jsx)(E,{intent:_.WARNING,minimal:!0,icon:(0,B.jsx)(n,{size:12,className:`mr-1`}),children:s(`rules.labelRedirect`)})]})},{key:`pattern`,header:s(`rules.tablePattern`),headerClassName:`w-1/4`,cellClassName:`font-mono font-bold`,render:e=>(0,B.jsx)(`span`,{children:e.pattern})},{key:`details`,header:s(`rules.tableDetails`),cellClassName:`py-2`,render:e=>(0,B.jsx)(B.Fragment,{children:e.type===`REDIRECT`?(0,B.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[e.v_a&&(0,B.jsxs)(E,{minimal:!0,className:`font-mono text-[10px]`,children:[`A: `,e.v_a]}),e.v_aaaa&&(0,B.jsxs)(E,{minimal:!0,className:`font-mono text-[10px]`,children:[`AAAA: `,e.v_aaaa]}),e.v_cname&&(0,B.jsxs)(E,{minimal:!0,className:`font-mono text-[10px]`,children:[`CNAME: `,e.v_cname]}),e.v_txt&&(0,B.jsxs)(E,{minimal:!0,className:`font-mono text-[10px]`,children:[`TXT: `,e.v_txt]})]}):e.type===`BLOCK`?(0,B.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,B.jsx)(`span`,{className:`text-gray-400 text-xs italic`,children:s(`rules.detailBlock`)}),(0,B.jsx)(E,{minimal:!0,round:!0,className:`text-[9px] px-1.5 opacity-70`,children:a()})]}):(0,B.jsx)(`span`,{className:`text-gray-400 text-xs italic`,children:s(`rules.detailAllow`)})})},{key:`created_at`,header:s(`rules.tableCreatedAt`,`添加时间`),headerClassName:`w-44`,cellClassName:`text-xs text-gray-500 align-middle`,render:e=>e.created_at?P(new Date(e.created_at*1e3)):`—`}];return(0,B.jsx)(`div`,{className:`w-full max-w-full overflow-x-auto pb-4`,children:(0,B.jsxs)(D,{interactive:!0,striped:!0,className:`w-full min-w-max whitespace-nowrap`,children:[(0,B.jsx)(`thead`,{children:(0,B.jsx)(`tr`,{children:y.map(e=>(0,B.jsx)(`th`,{onClick:()=>h(e.key),className:A(e.headerClassName,`cursor-pointer select-none transition-colors hover:text-blue-500`),title:s(`rules.clickToSort`,`点击排序`),children:(0,B.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,B.jsx)(`span`,{children:e.header}),u===e.key?p===`asc`?(0,B.jsx)(t,{size:13,className:`text-blue-500 shrink-0`}):(0,B.jsx)(i,{size:13,className:`text-blue-500 shrink-0`}):(0,B.jsx)(d,{size:12,className:`opacity-30 hover:opacity-75 shrink-0`})]})},e.key))})}),(0,B.jsx)(`tbody`,{children:v.map(e=>(0,B.jsx)(`tr`,{onClick:()=>r(e),className:`cursor-pointer`,children:y.map(t=>(0,B.jsx)(`td`,{className:t.cellClassName,children:t.render(e)},t.key))},e.id))})]})})},U=({editRule:e,setEditRule:t,saveEditRule:n,cancelEdit:r,deleteRule:i,isSaving:a,isDeleting:o})=>{let{t:c}=l();return(0,B.jsxs)(w,{isOpen:!!e,onClose:r,title:c(`rules.editRule`,`Edit Rule`),style:{width:`600px`},children:[(0,B.jsx)(x,{children:e&&(0,B.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[(0,B.jsxs)(`div`,{className:`flex gap-4`,children:[(0,B.jsx)(T,{label:c(`rules.action`),className:`w-40 mb-0`,children:(0,B.jsx)(S,{fill:!0,value:e.type,onChange:n=>t({...e,type:n.target.value}),options:[{label:c(`rules.typeBlock`),value:`BLOCK`},{label:c(`rules.typeAllow`),value:`ALLOW`},{label:c(`rules.typeRedirect`),value:`REDIRECT`}]})}),(0,B.jsx)(T,{label:c(`rules.pattern`),className:`flex-1 mb-0`,children:(0,B.jsx)(C,{placeholder:c(`rules.patternPlaceholder`),value:e.pattern,onChange:n=>t({...e,pattern:n.target.value})})})]}),(0,B.jsx)(`div`,{className:`text-xs text-gray-500 dark:text-gray-400`,children:c(`rules.wildcardDisclaimer`)}),e.type===`REDIRECT`&&(0,B.jsxs)(`div`,{className:`bg-gray-50 dark:bg-gray-800 p-4 rounded-lg border border-gray-200 dark:border-gray-700`,children:[(0,B.jsxs)(`div`,{className:`flex items-center gap-2 mb-4 text-blue-600 dark:text-blue-400`,children:[(0,B.jsx)(s,{size:14}),(0,B.jsx)(`span`,{className:`text-xs font-bold uppercase tracking-wider`,children:c(`rules.redirectSettings`)})]}),(0,B.jsxs)(`div`,{className:`grid grid-cols-2 gap-4`,children:[(0,B.jsx)(T,{label:c(`rules.aRecord`),className:`mb-0`,children:(0,B.jsx)(C,{placeholder:c(`rules.ipv4Placeholder`),value:e.v_a||``,onChange:n=>t({...e,v_a:n.target.value})})}),(0,B.jsx)(T,{label:c(`rules.aaaaRecord`),className:`mb-0`,children:(0,B.jsx)(C,{placeholder:c(`rules.ipv6Placeholder`),value:e.v_aaaa||``,onChange:n=>t({...e,v_aaaa:n.target.value})})}),(0,B.jsx)(T,{label:c(`rules.cnameRecord`),className:`mb-0`,children:(0,B.jsx)(C,{placeholder:c(`rules.cnamePlaceholder`),value:e.v_cname||``,onChange:n=>t({...e,v_cname:n.target.value})})}),(0,B.jsx)(T,{label:c(`rules.txtRecord`),className:`mb-0`,children:(0,B.jsx)(C,{placeholder:c(`rules.txtPlaceholder`),value:e.v_txt||``,onChange:n=>t({...e,v_txt:n.target.value})})})]})]})]})}),(0,B.jsx)(k,{actions:(0,B.jsxs)(`div`,{className:`flex gap-2`,children:[(0,B.jsx)(v,{onClick:r,disabled:a||o,children:c(`rules.cancel`,`Cancel`)}),(0,B.jsx)(v,{intent:_.PRIMARY,onClick:n,loading:a,disabled:a||o,children:c(`rules.saveChanges`,`Save Changes`)})]}),children:(0,B.jsx)(v,{icon:(0,B.jsx)(u,{size:14}),intent:_.DANGER,text:c(`rules.delete`,`Delete`),onClick:()=>{e&&i(e.id)},loading:o,disabled:a||o})})]})},W=({profileId:e,prefill:t,onPrefillUsed:n,toasterRef:i})=>{let a=r(),[o,s]=(0,z.useState)([]),[c,u]=(0,z.useState)(null),[d,f]=(0,z.useState)(!0),[p,y]=(0,z.useState)(!1),[b,x]=(0,z.useState)(!1),[S,C]=(0,z.useState)(!1),{t:w}=l(),T=M(),[D,k]=(0,z.useState)({type:`BLOCK`,pattern:``,include_subdomains:!1,v_a:``,v_aaaa:``,v_txt:``,v_cname:``}),[P,W]=(0,z.useState)(null),[G,K]=(0,z.useState)(`www.okx.com`),[q,J]=(0,z.useState)(!1);(0,z.useEffect)(()=>{j().then(e=>{e.substituteDomain&&K(e.substituteDomain)}).catch(e=>console.warn(`Failed to fetch clientInfo for substituteDomain:`,e))},[]);let Y=(0,z.useMemo)(()=>{let e=window.location.hostname.trim().toLowerCase();return e?o.some(t=>{if(t.type!==`REDIRECT`)return!1;let n=t.pattern.trim().toLowerCase();return n===e||n===`*.${e}`}):!1},[o]),X=()=>{J(!1),k({type:`REDIRECT`,pattern:window.location.hostname,include_subdomains:!1,v_a:``,v_aaaa:``,v_txt:``,v_cname:G||`www.okx.com`}),setTimeout(()=>{document.getElementById(`rule-pattern`)?.focus()},100)};(0,z.useEffect)(()=>{t&&(k({type:t.type,pattern:t.domain,include_subdomains:!1,v_a:t.recordType===`A`?`0.0.0.0`:``,v_aaaa:t.recordType===`AAAA`?`::`:``,v_txt:t.recordType===`TXT`?`Pre-filled`:``,v_cname:t.recordType===`CNAME`?`target.com`:``}),n?.())},[t,n]);let Z=async()=>{f(!0);try{let[t,n]=await Promise.all([R(e),F(e)]);s(t),u(JSON.parse(n.settings||`{}`))}catch(e){console.error(`Failed to fetch data`,e)}finally{f(!1)}};return(0,z.useEffect)(()=>{Z()},[e]),(0,B.jsxs)(`div`,{className:A(`md:px-8 w-full min-w-0 max-w-5xl mx-auto`,T?`p-1`:`px-8`),children:[(0,B.jsx)(`div`,{className:`mb-8`,children:(0,B.jsxs)(`div`,{className:`flex flex-col md:flex-row justify-between items-start md:items-center gap-4`,children:[(0,B.jsxs)(`div`,{className:`w-full md:w-auto flex-1`,children:[T?(0,B.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,B.jsxs)(O,{minimal:!0,fill:T,className:`flex-1`,children:[(0,B.jsx)(v,{active:!0,onClick:()=>a(`/dash/${e}/rules`),text:w(`rules.title`),large:!0}),(0,B.jsx)(v,{active:!1,onClick:()=>a(`/dash/${e}/filter`),text:w(`filtering.title`),large:!0})]}),d&&(0,B.jsx)(g,{size:16})]}):(0,B.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,B.jsx)(`h1`,{className:`bp6-heading m-0`,children:w(`rules.title`)}),d&&(0,B.jsx)(g,{size:20})]}),(0,B.jsx)(`p`,{className:`bp6-text-muted mt-2!`,children:w(`rules.subtitle`)})]}),!d&&!Y&&(0,B.jsx)(`div`,{className:`flex items-center gap-3 self-start md:self-auto`,children:(0,B.jsx)(h,{isOpen:q,onInteraction:J,placement:`bottom-end`,portalClassName:`z-20000`,content:(0,B.jsxs)(`div`,{className:`p-4 w-72 sm:w-80 space-y-3 text-sm`,children:[(0,B.jsx)(`p`,{className:`text-xs text-gray-700 dark:text-gray-300 leading-relaxed m-0`,children:w(`rules.addSelfRedirectPrompt`,`是否增加指向本站的 CNAME 规则,用于地区网络优化(中国大陆用户推荐)?`)}),(0,B.jsxs)(`div`,{className:`flex justify-end gap-2 pt-1`,children:[(0,B.jsx)(v,{size:`small`,variant:`minimal`,text:w(`common.no`,`否`),onClick:()=>J(!1)}),(0,B.jsx)(v,{size:`small`,intent:_.PRIMARY,text:w(`common.yes`,`是`),onClick:X})]})]}),children:(0,B.jsx)(E,{minimal:!0,interactive:!0,intent:_.PRIMARY,className:`cursor-pointer select-none font-medium`,children:w(`rules.addSelfRedirectTag`,`增加本站重定向?`)})})})]})}),(0,B.jsx)(m,{intent:_.PRIMARY,icon:`info-sign`,className:`mb-6`,children:(0,B.jsx)(`p`,{children:w(`rules.wildcardDisclaimer`,`若要匹配子域名,需使用通配符 *.example.com ,example.com 不会匹配子域名。`)})}),(0,B.jsx)(V,{newRule:D,setNewRule:k,addRule:async()=>{let t=D.pattern.trim();if(!t){i?.current?.show({message:w(`rules.patternEmpty`,`Domain pattern cannot be empty`),intent:_.DANGER});return}let n=t.toLowerCase();if(o.some(e=>e.pattern.trim().toLowerCase()===n)){i?.current?.show({message:w(`rules.duplicatePattern`,`Rule for this domain already exists`),intent:_.DANGER});return}y(!0);try{await L(e,{...D,pattern:t,include_subdomains:0}),i?.current?.show({message:w(`rules.addSuccess`,`Rule added successfully`),intent:_.SUCCESS}),k({type:`BLOCK`,pattern:``,include_subdomains:!1,v_a:``,v_aaaa:``,v_txt:``,v_cname:``}),await Z()}catch(e){i?.current?.show({message:e.message||w(`rules.addFailed`,`Failed to add rule`),intent:_.DANGER})}finally{y(!1)}},loading:p}),d&&o.length===0?(0,B.jsxs)(`div`,{className:`p-16 flex flex-col justify-center items-center gap-3`,children:[(0,B.jsx)(g,{size:32}),(0,B.jsx)(`span`,{className:`text-xs text-gray-500 dark:text-gray-400 font-medium`,children:w(`common.loading`,`加载中...`)})]}):o.length===0?(0,B.jsx)(m,{title:w(`rules.noRulesTitle`),children:w(`rules.noRulesDesc`)}):(0,B.jsxs)(`div`,{className:`relative`,children:[d&&(0,B.jsx)(`div`,{className:`absolute inset-0 bg-white/40 dark:bg-gray-900/40 backdrop-blur-xs flex items-center justify-center z-10 rounded-lg`,children:(0,B.jsx)(g,{size:32})}),(0,B.jsx)(H,{rules:o,startEdit:e=>{W({...e,include_subdomains:e.include_subdomains===1||e.include_subdomains===!0})},getBlockDetail:()=>{if(!c)return w(`rules.detailBlock`);switch(c.block_mode||`NULL_IP`){case`NXDOMAIN`:return`NXDOMAIN`;case`NODATA`:return`NODATA`;case`CUSTOM_IP`:return`${c.custom_block_ipv4||`0.0.0.0`} / ${c.custom_block_ipv6||`::`}`;default:return`0.0.0.0 / ::`}}})]}),(0,B.jsx)(U,{editRule:P,setEditRule:W,saveEditRule:async()=>{if(!P)return;let t=P.pattern.trim();if(!t){i?.current?.show({message:w(`rules.patternEmpty`,`Domain pattern cannot be empty`),intent:_.DANGER});return}let n=t.toLowerCase();if(o.some(e=>e.id!==P.id&&e.pattern.trim().toLowerCase()===n)){i?.current?.show({message:w(`rules.duplicatePattern`,`Rule for this domain already exists`),intent:_.DANGER});return}x(!0);try{await I(e,{...P,pattern:t,include_subdomains:0}),i?.current?.show({message:w(`rules.updateSuccess`,`Rule updated successfully`),intent:_.SUCCESS}),W(null),await Z()}catch(e){i?.current?.show({message:e.message||w(`rules.updateFailed`,`Failed to update rule`),intent:_.DANGER})}finally{x(!1)}},cancelEdit:()=>{W(null)},deleteRule:async t=>{C(!0);try{await N(e,t)}catch(e){console.error(e)}finally{C(!1)}W(null),await Z()},isSaving:b,isDeleting:S})]})};export{W as RulesView};
1
+ import{i as e}from"./rolldown-runtime-C4Xdq4VV.js";import{Dt as t,Lt as n,Tt as r,V as i,it as a,k as o,kt as s,rn as c,vt as l,w as u,wt as d}from"./vendor-react-R4_BUhus.js";import{S as f,b as p}from"./vendor-icons-other-kRhgWBno.js";import"./vendor-i18next-J2aoF7F1.js";import{C as m,E as h,F as g,H as _,P as v,S as y,U as b,b as x,d as S,f as C,k as w,p as T,r as E,u as D,w as O,y as k}from"./vendor-ui-core-CKSrm0Y8.js";import{_t as A}from"./vendor-utils-y3vK_J_u.js";import{At as j,U as M,dt as N,g as P,ht as F,rt as I,vn as L,yt as R}from"./index-CxK16i2C.js";var z=e(f(),1),B=e(p(),1);const V=({newRule:e,setNewRule:t,addRule:n,loading:r})=>{let{t:o}=c();return(0,B.jsx)(y,{elevation:b.ONE,className:`mb-8 p-6`,children:(0,B.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[(0,B.jsxs)(`div`,{className:`flex flex-col lg:flex-row justify-between gap-4 items-start lg:items-end`,children:[(0,B.jsx)(`div`,{className:`w-full lg:w-48`,children:(0,B.jsx)(T,{label:o(`rules.action`),labelFor:`rule-type`,className:`mb-0`,children:(0,B.jsx)(S,{id:`rule-type`,fill:!0,large:!0,value:e.type,onChange:n=>t({...e,type:n.target.value}),options:[{label:o(`rules.typeBlock`),value:`BLOCK`},{label:o(`rules.typeAllow`),value:`ALLOW`},{label:o(`rules.typeRedirect`),value:`REDIRECT`}]})})}),(0,B.jsx)(`div`,{className:`flex-1 w-full`,children:(0,B.jsx)(T,{label:o(`rules.pattern`),labelFor:`rule-pattern`,className:`mb-0`,children:(0,B.jsx)(C,{id:`rule-pattern`,size:`large`,placeholder:o(`rules.patternPlaceholder`),value:e.pattern,onChange:n=>t({...e,pattern:n.target.value})})})}),e.type!==`REDIRECT`&&(0,B.jsx)(T,{label:``,labelFor:``,className:`mb-0`,children:(0,B.jsx)(v,{intent:_.PRIMARY,size:`large`,icon:(0,B.jsx)(i,{size:18}),onClick:n,loading:r,disabled:r,children:o(`rules.addRule`)})})]}),e.type===`REDIRECT`&&(0,B.jsxs)(`div`,{className:`bg-gray-50 dark:bg-gray-800/50 p-6 rounded-xl border border-gray-200 dark:border-gray-700`,children:[(0,B.jsxs)(`div`,{className:`flex items-center gap-2 mb-4 text-blue-600 dark:text-blue-400`,children:[(0,B.jsx)(a,{size:16}),(0,B.jsx)(`span`,{className:`text-xs font-bold uppercase tracking-wider`,children:o(`rules.redirectSettings`)})]}),(0,B.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-x-8 gap-y-4`,children:[(0,B.jsx)(T,{label:o(`rules.aRecord`),labelInfo:o(`rules.optional`),children:(0,B.jsx)(C,{placeholder:o(`rules.ipv4Placeholder`),value:e.v_a,onChange:n=>t({...e,v_a:n.target.value})})}),(0,B.jsx)(T,{label:o(`rules.aaaaRecord`),labelInfo:o(`rules.optional`),children:(0,B.jsx)(C,{placeholder:o(`rules.ipv6Placeholder`),value:e.v_aaaa,onChange:n=>t({...e,v_aaaa:n.target.value})})}),(0,B.jsx)(T,{label:o(`rules.cnameRecord`),labelInfo:o(`rules.optional`),children:(0,B.jsx)(C,{placeholder:o(`rules.cnamePlaceholder`),value:e.v_cname,onChange:n=>t({...e,v_cname:n.target.value})})}),(0,B.jsx)(T,{label:o(`rules.txtRecord`),labelInfo:o(`rules.optional`),children:(0,B.jsx)(C,{placeholder:o(`rules.txtPlaceholder`),value:e.v_txt,onChange:n=>t({...e,v_txt:n.target.value})})})]}),(0,B.jsx)(`div`,{className:`mt-6 pt-4 border-t border-gray-200 dark:border-gray-700 flex justify-end`,children:(0,B.jsx)(v,{intent:_.PRIMARY,large:!0,icon:(0,B.jsx)(i,{size:18}),onClick:n,text:o(`rules.saveRedirectRule`),loading:r,disabled:r})})]})]})})},H=({rules:e,startEdit:n,getBlockDetail:i})=>{let{t:a}=c(),[u,f]=(0,z.useState)(`created_at`),[p,m]=(0,z.useState)(`desc`),h=e=>{u===e?m(e=>e===`asc`?`desc`:`asc`):(f(e),m(e===`created_at`?`desc`:`asc`))},g=e=>e.type===`REDIRECT`?[e.v_a,e.v_aaaa,e.v_cname,e.v_txt].filter(Boolean).join(` `):e.type===`BLOCK`?i():a(`rules.detailAllow`,`Forward to upstream`),v=(0,z.useMemo)(()=>[...e].sort((e,t)=>{let n=0;switch(u){case`action`:n=e.type.localeCompare(t.type);break;case`pattern`:n=e.pattern.localeCompare(t.pattern);break;case`details`:n=g(e).localeCompare(g(t));break;case`created_at`:n=(e.created_at??e.id)-(t.created_at??t.id);break}return n===0&&(n=e.id-t.id),p===`asc`?n:-n}),[e,u,p,i,a]),y=[{key:`action`,header:a(`rules.tableAction`),headerClassName:`w-32`,render:e=>(0,B.jsxs)(B.Fragment,{children:[e.type===`BLOCK`&&(0,B.jsx)(E,{intent:_.DANGER,minimal:!0,icon:(0,B.jsx)(o,{size:12,className:`mr-1`}),children:a(`rules.labelBlock`)}),e.type===`ALLOW`&&(0,B.jsx)(E,{intent:_.SUCCESS,minimal:!0,icon:(0,B.jsx)(l,{size:12,className:`mr-1`}),children:a(`rules.labelAllow`)}),e.type===`REDIRECT`&&(0,B.jsx)(E,{intent:_.WARNING,minimal:!0,icon:(0,B.jsx)(t,{size:12,className:`mr-1`}),children:a(`rules.labelRedirect`)})]})},{key:`pattern`,header:a(`rules.tablePattern`),headerClassName:`w-1/4`,cellClassName:`font-mono font-bold`,render:e=>(0,B.jsx)(`span`,{children:e.pattern})},{key:`details`,header:a(`rules.tableDetails`),cellClassName:`py-2`,render:e=>(0,B.jsx)(B.Fragment,{children:e.type===`REDIRECT`?(0,B.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[e.v_a&&(0,B.jsxs)(E,{minimal:!0,className:`font-mono text-[10px]`,children:[`A: `,e.v_a]}),e.v_aaaa&&(0,B.jsxs)(E,{minimal:!0,className:`font-mono text-[10px]`,children:[`AAAA: `,e.v_aaaa]}),e.v_cname&&(0,B.jsxs)(E,{minimal:!0,className:`font-mono text-[10px]`,children:[`CNAME: `,e.v_cname]}),e.v_txt&&(0,B.jsxs)(E,{minimal:!0,className:`font-mono text-[10px]`,children:[`TXT: `,e.v_txt]})]}):e.type===`BLOCK`?(0,B.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,B.jsx)(`span`,{className:`text-gray-400 text-xs italic`,children:a(`rules.detailBlock`)}),(0,B.jsx)(E,{minimal:!0,round:!0,className:`text-[9px] px-1.5 opacity-70`,children:i()})]}):(0,B.jsx)(`span`,{className:`text-gray-400 text-xs italic`,children:a(`rules.detailAllow`)})})},{key:`created_at`,header:a(`rules.tableCreatedAt`,`添加时间`),headerClassName:`w-44`,cellClassName:`text-xs text-gray-500 align-middle`,render:e=>e.created_at?P(new Date(e.created_at*1e3)):`—`}];return(0,B.jsx)(`div`,{className:`w-full max-w-full overflow-x-auto pb-4`,children:(0,B.jsxs)(D,{interactive:!0,striped:!0,className:`w-full min-w-max whitespace-nowrap`,children:[(0,B.jsx)(`thead`,{children:(0,B.jsx)(`tr`,{children:y.map(e=>(0,B.jsx)(`th`,{onClick:()=>h(e.key),className:A(e.headerClassName,`cursor-pointer select-none transition-colors hover:text-blue-500`),title:a(`rules.clickToSort`,`点击排序`),children:(0,B.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,B.jsx)(`span`,{children:e.header}),u===e.key?p===`asc`?(0,B.jsx)(d,{size:13,className:`text-blue-500 shrink-0`}):(0,B.jsx)(s,{size:13,className:`text-blue-500 shrink-0`}):(0,B.jsx)(r,{size:12,className:`opacity-30 hover:opacity-75 shrink-0`})]})},e.key))})}),(0,B.jsx)(`tbody`,{children:v.map(e=>(0,B.jsx)(`tr`,{onClick:()=>n(e),className:`cursor-pointer`,children:y.map(t=>(0,B.jsx)(`td`,{className:t.cellClassName,children:t.render(e)},t.key))},e.id))})]})})},U=({editRule:e,setEditRule:t,saveEditRule:n,cancelEdit:r,deleteRule:i,isSaving:o,isDeleting:s})=>{let{t:l}=c();return(0,B.jsxs)(w,{isOpen:!!e,onClose:r,title:l(`rules.editRule`,`Edit Rule`),style:{width:`600px`},children:[(0,B.jsx)(x,{children:e&&(0,B.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[(0,B.jsxs)(`div`,{className:`flex gap-4`,children:[(0,B.jsx)(T,{label:l(`rules.action`),className:`w-40 mb-0`,children:(0,B.jsx)(S,{fill:!0,value:e.type,onChange:n=>t({...e,type:n.target.value}),options:[{label:l(`rules.typeBlock`),value:`BLOCK`},{label:l(`rules.typeAllow`),value:`ALLOW`},{label:l(`rules.typeRedirect`),value:`REDIRECT`}]})}),(0,B.jsx)(T,{label:l(`rules.pattern`),className:`flex-1 mb-0`,children:(0,B.jsx)(C,{placeholder:l(`rules.patternPlaceholder`),value:e.pattern,onChange:n=>t({...e,pattern:n.target.value})})})]}),(0,B.jsx)(`div`,{className:`text-xs text-gray-500 dark:text-gray-400`,children:l(`rules.wildcardDisclaimer`)}),e.type===`REDIRECT`&&(0,B.jsxs)(`div`,{className:`bg-gray-50 dark:bg-gray-800 p-4 rounded-lg border border-gray-200 dark:border-gray-700`,children:[(0,B.jsxs)(`div`,{className:`flex items-center gap-2 mb-4 text-blue-600 dark:text-blue-400`,children:[(0,B.jsx)(a,{size:14}),(0,B.jsx)(`span`,{className:`text-xs font-bold uppercase tracking-wider`,children:l(`rules.redirectSettings`)})]}),(0,B.jsxs)(`div`,{className:`grid grid-cols-2 gap-4`,children:[(0,B.jsx)(T,{label:l(`rules.aRecord`),className:`mb-0`,children:(0,B.jsx)(C,{placeholder:l(`rules.ipv4Placeholder`),value:e.v_a||``,onChange:n=>t({...e,v_a:n.target.value})})}),(0,B.jsx)(T,{label:l(`rules.aaaaRecord`),className:`mb-0`,children:(0,B.jsx)(C,{placeholder:l(`rules.ipv6Placeholder`),value:e.v_aaaa||``,onChange:n=>t({...e,v_aaaa:n.target.value})})}),(0,B.jsx)(T,{label:l(`rules.cnameRecord`),className:`mb-0`,children:(0,B.jsx)(C,{placeholder:l(`rules.cnamePlaceholder`),value:e.v_cname||``,onChange:n=>t({...e,v_cname:n.target.value})})}),(0,B.jsx)(T,{label:l(`rules.txtRecord`),className:`mb-0`,children:(0,B.jsx)(C,{placeholder:l(`rules.txtPlaceholder`),value:e.v_txt||``,onChange:n=>t({...e,v_txt:n.target.value})})})]})]})]})}),(0,B.jsx)(k,{actions:(0,B.jsxs)(`div`,{className:`flex gap-2`,children:[(0,B.jsx)(v,{onClick:r,disabled:o||s,children:l(`rules.cancel`,`Cancel`)}),(0,B.jsx)(v,{intent:_.PRIMARY,onClick:n,loading:o,disabled:o||s,children:l(`rules.saveChanges`,`Save Changes`)})]}),children:(0,B.jsx)(v,{icon:(0,B.jsx)(u,{size:14}),intent:_.DANGER,text:l(`rules.delete`,`Delete`),onClick:()=>{e&&i(e.id)},loading:s,disabled:o||s})})]})},W=({profileId:e,prefill:t,onPrefillUsed:r,toasterRef:i})=>{let a=n(),[o,s]=(0,z.useState)([]),[l,u]=(0,z.useState)(null),[d,f]=(0,z.useState)(!0),[p,y]=(0,z.useState)(!1),[b,x]=(0,z.useState)(!1),[S,C]=(0,z.useState)(!1),{t:w}=c(),T=L(),[D,k]=(0,z.useState)({type:`BLOCK`,pattern:``,include_subdomains:!1,v_a:``,v_aaaa:``,v_txt:``,v_cname:``}),[P,W]=(0,z.useState)(null),[G,K]=(0,z.useState)(`www.okx.com`),[q,J]=(0,z.useState)(!1);(0,z.useEffect)(()=>{M().then(e=>{e.substituteDomain&&K(e.substituteDomain)}).catch(e=>console.warn(`Failed to fetch clientInfo for substituteDomain:`,e))},[]);let Y=(0,z.useMemo)(()=>{let e=window.location.hostname.trim().toLowerCase();return e?o.some(t=>{if(t.type!==`REDIRECT`)return!1;let n=t.pattern.trim().toLowerCase();return n===e||n===`*.${e}`}):!1},[o]),X=()=>{J(!1),k({type:`REDIRECT`,pattern:window.location.hostname,include_subdomains:!1,v_a:``,v_aaaa:``,v_txt:``,v_cname:G||`www.okx.com`}),setTimeout(()=>{document.getElementById(`rule-pattern`)?.focus()},100)};(0,z.useEffect)(()=>{t&&(k({type:t.type,pattern:t.domain,include_subdomains:!1,v_a:t.recordType===`A`?`0.0.0.0`:``,v_aaaa:t.recordType===`AAAA`?`::`:``,v_txt:t.recordType===`TXT`?`Pre-filled`:``,v_cname:t.recordType===`CNAME`?`target.com`:``}),r?.())},[t,r]);let Z=async()=>{f(!0);try{let[t,n]=await Promise.all([R(e),F(e)]);s(t),u(JSON.parse(n.settings||`{}`))}catch(e){console.error(`Failed to fetch data`,e)}finally{f(!1)}};return(0,z.useEffect)(()=>{Z()},[e]),(0,B.jsxs)(`div`,{className:A(`md:px-8 w-full min-w-0 max-w-5xl mx-auto`,T?`p-1`:`px-8`),children:[(0,B.jsx)(`div`,{className:`mb-8`,children:(0,B.jsxs)(`div`,{className:`flex flex-col md:flex-row justify-between items-start md:items-center gap-4`,children:[(0,B.jsxs)(`div`,{className:`w-full md:w-auto flex-1`,children:[T?(0,B.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,B.jsxs)(O,{minimal:!0,fill:T,className:`flex-1`,children:[(0,B.jsx)(v,{active:!0,onClick:()=>a(`/dash/${e}/rules`),text:w(`rules.title`),large:!0}),(0,B.jsx)(v,{active:!1,onClick:()=>a(`/dash/${e}/filter`),text:w(`filtering.title`),large:!0})]}),d&&(0,B.jsx)(g,{size:16})]}):(0,B.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,B.jsx)(`h1`,{className:`bp6-heading m-0`,children:w(`rules.title`)}),d&&(0,B.jsx)(g,{size:20})]}),(0,B.jsx)(`p`,{className:`bp6-text-muted mt-2!`,children:w(`rules.subtitle`)})]}),!d&&!Y&&(0,B.jsx)(`div`,{className:`flex items-center gap-3 self-start md:self-auto`,children:(0,B.jsx)(h,{isOpen:q,onInteraction:J,placement:`bottom-end`,portalClassName:`z-20000`,content:(0,B.jsxs)(`div`,{className:`p-4 w-72 sm:w-80 space-y-3 text-sm`,children:[(0,B.jsx)(`p`,{className:`text-xs text-gray-700 dark:text-gray-300 leading-relaxed m-0`,children:w(`rules.addSelfRedirectPrompt`,`是否增加指向本站的 CNAME 规则,用于地区网络优化(中国大陆用户推荐)?`)}),(0,B.jsxs)(`div`,{className:`flex justify-end gap-2 pt-1`,children:[(0,B.jsx)(v,{size:`small`,variant:`minimal`,text:w(`common.no`,`否`),onClick:()=>J(!1)}),(0,B.jsx)(v,{size:`small`,intent:_.PRIMARY,text:w(`common.yes`,`是`),onClick:X})]})]}),children:(0,B.jsx)(E,{minimal:!0,interactive:!0,intent:_.PRIMARY,className:`cursor-pointer select-none font-medium`,children:w(`rules.addSelfRedirectTag`,`增加本站重定向?`)})})})]})}),(0,B.jsx)(m,{intent:_.PRIMARY,icon:`info-sign`,className:`mb-6`,children:(0,B.jsx)(`p`,{children:w(`rules.wildcardDisclaimer`,`若要匹配子域名,需使用通配符 *.example.com ,example.com 不会匹配子域名。`)})}),(0,B.jsx)(V,{newRule:D,setNewRule:k,addRule:async()=>{let t=D.pattern.trim();if(!t){i?.current?.show({message:w(`rules.patternEmpty`,`Domain pattern cannot be empty`),intent:_.DANGER});return}let n=t.toLowerCase();if(o.some(e=>e.pattern.trim().toLowerCase()===n)){i?.current?.show({message:w(`rules.duplicatePattern`,`Rule for this domain already exists`),intent:_.DANGER});return}y(!0);try{await I(e,{...D,pattern:t,include_subdomains:0}),i?.current?.show({message:w(`rules.addSuccess`,`Rule added successfully`),intent:_.SUCCESS}),k({type:`BLOCK`,pattern:``,include_subdomains:!1,v_a:``,v_aaaa:``,v_txt:``,v_cname:``}),await Z()}catch(e){i?.current?.show({message:e.message||w(`rules.addFailed`,`Failed to add rule`),intent:_.DANGER})}finally{y(!1)}},loading:p}),d&&o.length===0?(0,B.jsxs)(`div`,{className:`p-16 flex flex-col justify-center items-center gap-3`,children:[(0,B.jsx)(g,{size:32}),(0,B.jsx)(`span`,{className:`text-xs text-gray-500 dark:text-gray-400 font-medium`,children:w(`common.loading`,`加载中...`)})]}):o.length===0?(0,B.jsx)(m,{title:w(`rules.noRulesTitle`),children:w(`rules.noRulesDesc`)}):(0,B.jsxs)(`div`,{className:`relative`,children:[d&&(0,B.jsx)(`div`,{className:`absolute inset-0 bg-white/40 dark:bg-gray-900/40 backdrop-blur-xs flex items-center justify-center z-10 rounded-lg`,children:(0,B.jsx)(g,{size:32})}),(0,B.jsx)(H,{rules:o,startEdit:e=>{W({...e,include_subdomains:e.include_subdomains===1||e.include_subdomains===!0})},getBlockDetail:()=>{if(!l)return w(`rules.detailBlock`);switch(l.block_mode||`NULL_IP`){case`NXDOMAIN`:return`NXDOMAIN`;case`NODATA`:return`NODATA`;case`CUSTOM_IP`:return`${l.custom_block_ipv4||`0.0.0.0`} / ${l.custom_block_ipv6||`::`}`;default:return`0.0.0.0 / ::`}}})]}),(0,B.jsx)(U,{editRule:P,setEditRule:W,saveEditRule:async()=>{if(!P)return;let t=P.pattern.trim();if(!t){i?.current?.show({message:w(`rules.patternEmpty`,`Domain pattern cannot be empty`),intent:_.DANGER});return}let n=t.toLowerCase();if(o.some(e=>e.id!==P.id&&e.pattern.trim().toLowerCase()===n)){i?.current?.show({message:w(`rules.duplicatePattern`,`Rule for this domain already exists`),intent:_.DANGER});return}x(!0);try{await j(e,{...P,pattern:t,include_subdomains:0}),i?.current?.show({message:w(`rules.updateSuccess`,`Rule updated successfully`),intent:_.SUCCESS}),W(null),await Z()}catch(e){i?.current?.show({message:e.message||w(`rules.updateFailed`,`Failed to update rule`),intent:_.DANGER})}finally{x(!1)}},cancelEdit:()=>{W(null)},deleteRule:async t=>{C(!0);try{await N(e,t)}catch(e){console.error(e)}finally{C(!1)}W(null),await Z()},isSaving:b,isDeleting:S})]})};export{W as RulesView};
@@ -0,0 +1 @@
1
+ import{i as e}from"./rolldown-runtime-C4Xdq4VV.js";import{$ as t,F as n,O as r,U as i,X as a,bt as o,ct as s,ht as c,it as l,jt as u,lt as d,mt as f,rn as p,rt as m,ut as h,v as g,w as _,xt as v,y}from"./vendor-react-R4_BUhus.js";import{S as b,b as x}from"./vendor-icons-other-kRhgWBno.js";import"./vendor-i18next-J2aoF7F1.js";import{C as S,D as C,E as w,F as ee,H as T,M as E,N as D,O,P as k,S as A,T as j,U as M,V as N,_ as P,d as F,f as I,h as L,p as R,r as z,v as te,x as ne}from"./vendor-ui-core-CKSrm0Y8.js";import{_t as re}from"./vendor-utils-y3vK_J_u.js";import{Ct as ie,J as ae,K as oe,Ot as se,T as B,c as V,gt as H,ht as U,jt as W,ot as G,yt as K}from"./index-CxK16i2C.js";import{t as q}from"./async-R_IFRE5c.js";var J=e(b(),1),Y=e(x(),1);const ce=({profile:e,isEditingName:t,setIsEditingName:n,editName:r,setEditName:a,updateProfileName:o,exportProfile:s})=>{let{t:c}=p(),[l,u]=(0,J.useState)(!1);return(0,Y.jsxs)(`div`,{className:`mb-6 flex flex-col md:flex-row justify-between items-start md:items-center gap-4`,children:[(0,Y.jsxs)(`div`,{className:`flex flex-col justify-start`,children:[t?(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 mb-1`,children:[(0,Y.jsx)(te,{content:c(`common.profileNameFormatTip`,`Profile Name tip: 1-30 characters, duplicates not allowed`),isOpen:l,position:N.TOP,intent:T.PRIMARY,className:`flex-1`,children:(0,Y.jsx)(`div`,{className:`w-full block`,children:(0,Y.jsx)(I,{value:r,onChange:e=>a(e.target.value),onFocus:()=>u(!0),onBlur:()=>u(!1),autoFocus:!0,onKeyDown:t=>{t.key===`Enter`&&o(),t.key===`Escape`&&(n(!1),a(e?.name||``))}})})}),(0,Y.jsx)(k,{icon:(0,Y.jsx)(v,{size:16}),intent:T.SUCCESS,minimal:!0,onClick:o,disabled:!V.test(r)}),(0,Y.jsx)(k,{icon:(0,Y.jsx)(y,{size:16}),minimal:!0,onClick:()=>{n(!1),a(e?.name||``)}})]}):(0,Y.jsxs)(`div`,{className:`group flex items-center gap-2 mb-1 cursor-pointer`,onClick:()=>n(!0),children:[(0,Y.jsx)(`h2`,{className:`bp6-heading mb-0`,children:e?.name}),(0,Y.jsx)(k,{icon:(0,Y.jsx)(i,{size:14}),minimal:!0,className:`opacity-30 group-hover:opacity-100 transition-opacity`})]}),(0,Y.jsx)(`p`,{className:`bp6-text-muted`,children:c(`settings.subtitle`)})]}),(0,Y.jsx)(`div`,{className:`flex gap-2 items-center`,children:(0,Y.jsx)(k,{size:`large`,icon:(0,Y.jsx)(d,{size:18}),text:c(`settings.export`,`导出配置`),onClick:s})})]})},le=()=>{let{t:e}=p(),[t,n]=(0,J.useState)([]);return(0,J.useEffect)(()=>{ae().then(t=>{t&&Array.isArray(t)&&n(t.map(t=>({label:e(t.label),url:t.url})))}).catch(e=>console.warn(`Failed to fetch preset upstreams from API`,e))},[e]),t},ue=(e,t)=>{let{t:n}=p();return(0,J.useMemo)(()=>{let e=t>0?t:30,r=n(`settings.retentionMaxSuffix`,`(最长)`),i=[{label:n(`settings.retentionDisabled`,`关闭 (隐私需要)`),value:0},{label:n(`settings.retention10m`,`10 分钟`),value:.007},{label:n(`settings.retention1h`,`1 小时`),value:.0416},{label:n(`settings.retention24h`,`24 小时`),value:1},{label:n(`settings.retention3d`,`3 天`),value:3},{label:n(`settings.retention7d`,`7 天`),value:7},{label:n(`settings.retention30d`,`30 天`),value:30},{label:n(`settings.retention90d`,`90 天`),value:90},{label:n(`settings.retention180d`,`180 天`),value:180},{label:n(`settings.retention360d`,`360 天`),value:360}],a=i.filter(t=>t.value<=e);return e>0&&!a.some(t=>t.value===e)&&(a.push({label:`${e} ${n(`settings.daysUnit`,`天`)}`,value:e}),a.sort((e,t)=>e.value-t.value)),a.length===0?[i[0]]:a.map(t=>t.value===e&&t.value>0?{...t,label:`${t.label} ${r}`}:t)},[n,t])},de=({settings:e,setSettings:t})=>{let{t:r}=p(),i=(0,Y.jsx)(C,{className:`min-w-96`,children:le().map((n,r)=>(0,Y.jsx)(j,{text:n.label,onClick:()=>t({...e,upstream:[n.url]}),labelElement:(0,Y.jsx)(`div`,{className:`flex flex-col items-end text-right`,children:(0,Y.jsx)(`span`,{className:`text-[9px] opacity-85 max-w-64 truncate`,title:n.url,children:n.url})})},r))});return(0,Y.jsxs)(A,{elevation:M.ONE,className:`dark:bg-gray-900 dark:border-gray-800`,children:[(0,Y.jsxs)(D,{className:`flex items-center gap-2 mb-4 font-bold`,children:[(0,Y.jsx)(n,{size:18,className:`text-blue-500`}),` `,r(`settings.upstreamTitle`)]}),(0,Y.jsx)(R,{label:`DoH (https://) / DoT (tls://) / DNS Stamp (sdns://) / ${r(`settings.classicDns`)}`,children:(0,Y.jsx)(I,{fill:!0,placeholder:`https://... | tls://... | sdns://... | 1.1.1.1`,value:e.upstream?.[0]||``,onChange:n=>t({...e,upstream:[n.target.value]}),onFocus:e=>e.target.select(),rightElement:(0,Y.jsx)(w,{content:i,placement:`bottom-end`,animation:`minimal`,arrow:!1,children:(0,Y.jsx)(k,{variant:`minimal`,icon:`chevron-down`})})})}),(0,Y.jsx)(`p`,{className:`text-xs opacity-60`,children:r(`settings.upstreamDesc`)})]})},fe=({settings:e,setSettings:t})=>{let{t:n}=p();return(0,Y.jsxs)(A,{elevation:M.ONE,className:`dark:bg-gray-900 dark:border-gray-800`,children:[(0,Y.jsxs)(D,{className:`flex items-center gap-2 mb-4 font-bold`,children:[(0,Y.jsx)(r,{size:18,className:`text-green-500`}),` `,n(`settings.defaultPolicyTitle`)]}),(0,Y.jsxs)(`div`,{className:`space-y-4`,children:[(0,Y.jsx)(R,{label:n(`settings.onNoMatch`),children:(0,Y.jsxs)(F,{fill:!0,value:e.default_policy,onChange:n=>t({...e,default_policy:n.target.value}),children:[(0,Y.jsx)(`option`,{value:`ALLOW`,children:n(`settings.allowAll`)}),(0,Y.jsx)(`option`,{value:`BLOCK`,children:n(`settings.blockAll`)})]})}),(0,Y.jsx)(P,{}),(0,Y.jsx)(R,{label:n(`settings.blockModeTitle`),helperText:n(`settings.blockModeDesc`),children:(0,Y.jsxs)(F,{fill:!0,value:e.block_mode||`NULL_IP`,onChange:n=>t({...e,block_mode:n.target.value}),children:[(0,Y.jsxs)(`option`,{value:`NULL_IP`,children:[`0.0.0.0 / :: (`,n(`settings.default`),`)`]}),(0,Y.jsxs)(`option`,{value:`NXDOMAIN`,children:[`NXDOMAIN (`,n(`settings.NXDOMAIN`),`)`]}),(0,Y.jsxs)(`option`,{value:`NODATA`,children:[`NODATA (`,n(`settings.NODATA`),`)`]}),(0,Y.jsx)(`option`,{value:`CUSTOM_IP`,children:n(`settings.customIP`)})]})}),e.block_mode===`CUSTOM_IP`&&(0,Y.jsxs)(`div`,{className:`space-y-2 animate-in fade-in slide-in-from-top-1`,children:[(0,Y.jsx)(I,{placeholder:`IPv4: 127.0.0.1`,value:e.custom_block_ipv4||``,onChange:n=>t({...e,custom_block_ipv4:n.target.value})}),(0,Y.jsx)(I,{placeholder:`IPv6: ::1`,value:e.custom_block_ipv6||``,onChange:n=>t({...e,custom_block_ipv6:n.target.value})})]})]})]})},pe=({settings:e,setSettings:t,isAdmin:n,maxRetentionDays:r})=>{let{t:i}=p(),a=ue(n,r);J.useEffect(()=>{if(r>0&&e.log_retention_days>r&&a.length>0){let n=a[a.length-1];n&&e.log_retention_days!==n.value&&t({...e,log_retention_days:n.value})}},[r,e.log_retention_days,a,t]);let o=e.log_retention_days===0;return(0,Y.jsxs)(A,{elevation:M.ONE,className:`dark:bg-gray-900 dark:border-gray-800`,children:[(0,Y.jsxs)(D,{className:`flex items-center gap-2 mb-4 font-bold`,children:[(0,Y.jsx)(f,{size:18,className:`text-purple-500`}),` `,i(`settings.logRetentionTitle`)]}),(0,Y.jsxs)(`div`,{className:`space-y-4`,children:[(0,Y.jsx)(R,{label:i(`settings.retentionDuration`),children:(0,Y.jsx)(F,{fill:!0,value:e.log_retention_days,onChange:n=>t({...e,log_retention_days:parseFloat(n.target.value)}),children:a.map(e=>(0,Y.jsx)(`option`,{value:e.value,children:e.label},e.value))})}),(0,Y.jsx)(`p`,{className:`text-xs opacity-60`,children:o?i(`settings.retentionDisabledDesc`,`已关闭日志记录。系统将不会记录任何 DNS 查询日志并立即清空历史日志。`):i(`settings.retentionDesc`)}),(0,Y.jsxs)(`div`,{className:`pt-3 border-t border-gray-100 dark:border-gray-800/80`,children:[(0,Y.jsx)(L,{label:i(`settings.skipLogOnPass`,`不记录放行记录`),checked:!o&&!!e.skip_log_on_pass,disabled:o,onChange:n=>t({...e,skip_log_on_pass:n.currentTarget.checked})}),(0,Y.jsx)(`p`,{className:`text-xs opacity-60 mt-1`,children:i(`settings.skipLogOnPassDesc`,`启用后不记录正常放行的 DNS 查询,仅记录被拦截、重定向或解析失败的记录。可大幅减少存储占用与写操作。`)})]})]})]})},me=({profileId:e,toasterRef:t})=>{let{t:n}=p(),[r,i]=(0,J.useState)(()=>B.getLocalRetentionDays()),[a,o]=(0,J.useState)(!1),[s,c]=(0,J.useState)(null),[l,u]=(0,J.useState)(!1),[d,f]=(0,J.useState)(!1),g=(0,J.useCallback)(async()=>{try{await B.init();let t=await B.getStorageInfo();o(t?.isOpfs??B.getIsOpfs());let n=t.profileStats.find(t=>t.profile_id===e);c(n?n.count:0)}catch(e){console.error(`[LocalRetentionCard] Failed to load storage info:`,e),o(B.getIsOpfs()),c(0)}},[e]);(0,J.useEffect)(()=>{g()},[g]);let v=e=>{i(e),B.setLocalRetentionDays(e),g()};return(0,Y.jsxs)(A,{elevation:M.ONE,className:`dark:bg-gray-900 dark:border-gray-800`,children:[(0,Y.jsxs)(D,{className:`flex items-center gap-2 mb-4 font-bold`,children:[(0,Y.jsx)(h,{size:18,className:`text-cyan-500`}),` `,n(`settings.localRetentionTitle`,`本地存储与留存`)]}),(0,Y.jsxs)(`div`,{className:`space-y-4`,children:[(0,Y.jsx)(R,{label:n(`settings.localRetentionDuration`,`本地保留时长`),children:(0,Y.jsxs)(F,{fill:!0,value:r,onChange:e=>v(parseInt(e.target.value,10)),children:[(0,Y.jsx)(`option`,{value:30,children:n(`settings.localRetention30d`,`30 天`)}),(0,Y.jsx)(`option`,{value:90,children:n(`settings.localRetention90d`,`90 天 (推荐)`)}),(0,Y.jsx)(`option`,{value:180,children:n(`settings.localRetention180d`,`180 天`)}),(0,Y.jsx)(`option`,{value:365,children:n(`settings.localRetention365d`,`365 天 (1 年)`)}),(0,Y.jsx)(`option`,{value:0,children:n(`settings.localRetentionUnlimited`,`永久保留 (直到手动清除)`)})]})}),(0,Y.jsx)(`p`,{className:`text-xs opacity-60`,children:n(`settings.localRetentionDesc`,`日志将持久化保存在当前浏览器本地的 SQLite 数据库 (OPFS) 中,提供秒级本地搜索并节省云端存储费用。超出此时长的本地日志将自动清除。`)}),(0,Y.jsxs)(`div`,{className:`pt-3 border-t border-gray-100 dark:border-gray-800/80 space-y-3`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between text-xs`,children:[(0,Y.jsxs)(`span`,{className:`flex items-center gap-1.5 opacity-70`,children:[(0,Y.jsx)(m,{size:14}),n(`settings.localEngineStorage`,`存储引擎`),`:`]}),(0,Y.jsx)(z,{minimal:!0,intent:a?T.SUCCESS:T.WARNING,className:`text-[11px]`,children:a?n(`settings.localEngineOpfs`,`OPFS 本地持久化`):n(`settings.localEngineMemory`,`内存临时存储 (无痕/私密模式)`)})]}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between text-xs`,children:[(0,Y.jsxs)(`span`,{className:`opacity-70`,children:[n(`settings.localCachedCount`,`本地已缓存日志`),`:`]}),(0,Y.jsx)(`span`,{className:`font-mono font-medium`,children:s===null?`...`:n(`settings.localCachedCountUnit`,`{{count}} 条记录`,{count:s})})]}),(0,Y.jsx)(`div`,{className:`pt-1 flex justify-end`,children:(0,Y.jsx)(k,{minimal:!0,small:!0,intent:T.DANGER,icon:(0,Y.jsx)(_,{size:13}),text:n(`settings.clearLocalData`,`清空本地日志`),disabled:s===0||s===null||d,onClick:()=>u(!0)})})]})]}),(0,Y.jsx)(O,{isOpen:l,confirmButtonText:n(`common.confirm`,`确认清空`),cancelButtonText:n(`common.cancel`,`取消`),intent:T.DANGER,icon:`trash`,onConfirm:async()=>{f(!0);try{await B.clearProfile(e),c(0),t?.current?.show({message:n(`settings.clearLocalDataSuccess`,`本地日志已成功清空`),intent:T.SUCCESS,icon:`tick`})}catch(e){console.error(`[LocalRetentionCard] Failed to clear local profile logs:`,e),t?.current?.show({message:n(`settings.clearLocalDataError`,`清空本地日志失败`),intent:T.DANGER,icon:`error`})}finally{f(!1),u(!1)}},onCancel:()=>u(!1),loading:d,children:(0,Y.jsx)(`p`,{children:n(`settings.clearLocalDataConfirm`,`确定要清空此配置在本地保存的所有日志吗?(云端日志不受影响)`)})})]})},he=({settings:e,setSettings:t})=>{let{t:n}=p();return(0,Y.jsxs)(A,{elevation:M.ONE,className:`dark:bg-gray-900 dark:border-gray-800`,children:[(0,Y.jsxs)(D,{className:`flex items-center gap-2 mb-3 font-bold`,children:[(0,Y.jsx)(l,{size:18,className:`text-orange-500`}),` `,n(`settings.ecsTitle`)]}),(0,Y.jsxs)(`div`,{className:`space-y-4`,children:[(0,Y.jsx)(L,{label:n(`settings.sendEcs`),checked:e.ecs.enabled,onChange:n=>t({...e,ecs:{...e.ecs,enabled:n.currentTarget.checked}})}),(0,Y.jsx)(L,{label:n(`settings.customSubnet`),disabled:!e.ecs.enabled,checked:!e.ecs.use_client_ip,onChange:n=>t({...e,ecs:{...e.ecs,use_client_ip:!n.currentTarget.checked}})}),(0,Y.jsxs)(`div`,{className:`space-y-3 pt-2 border-t border-gray-100 dark:border-gray-800`,children:[(0,Y.jsx)(R,{label:n(`settings.customIpv4`),labelInfo:n(`settings.ipv4Hint`),disabled:!(e.ecs.enabled&&!e.ecs.use_client_ip),children:(0,Y.jsx)(I,{placeholder:`0.0.0.0/0`,value:e.ecs.ipv4_cidr||``,disabled:!(e.ecs.enabled&&!e.ecs.use_client_ip),onChange:n=>t({...e,ecs:{...e.ecs,ipv4_cidr:n.target.value}})})}),(0,Y.jsx)(R,{label:n(`settings.customIpv6`),labelInfo:n(`settings.ipv6Hint`),disabled:!(e.ecs.enabled&&!e.ecs.use_client_ip),children:(0,Y.jsx)(I,{placeholder:`::/0`,value:e.ecs.ipv6_cidr||``,disabled:!(e.ecs.enabled&&!e.ecs.use_client_ip),onChange:n=>t({...e,ecs:{...e.ecs,ipv6_cidr:n.target.value}})})})]}),(0,Y.jsx)(`p`,{className:`text-xs opacity-60`,children:n(`settings.ecsUpstreamHint`)})]})]})};var ge=[{domain:`cloudflare-ech.com`,isPreferred:!0},{domain:`crypto.cloudflare.com`,isPreferred:!1},{domain:`one.one.one.one`,isPreferred:!1},{domain:`www.cloudflare.com`,isPreferred:!1},{domain:`encryptedsni.com`,isPreferred:!1},{domain:`cdnjs.com`,isPreferred:!1}];const _e=({settings:e,setSettings:n})=>{let{t:r}=p(),[i,a]=J.useState(ge);J.useEffect(()=>{oe().then(e=>{Array.isArray(e)&&e.length>0&&a(e.map(e=>typeof e==`string`?{domain:e,isPreferred:e===`cloudflare-ech.com`}:{domain:e.domain,isPreferred:!!e.isPreferred}))}).catch(e=>console.warn(`Failed to fetch preset ECH fronting domains from API`,e))},[]);let o=typeof e.best_effort_ech==`boolean`?e.best_effort_ech:!!e.best_effort_ech?.enabled,c=typeof e.best_effort_ech==`object`&&e.best_effort_ech?.fronting_domain?e.best_effort_ech.fronting_domain:`cloudflare-ech.com`,l=t=>{n({...e,best_effort_ech:{enabled:t,fronting_domain:c||`cloudflare-ech.com`}})},u=t=>{n({...e,best_effort_ech:{enabled:o,fronting_domain:t}})},d=(0,Y.jsx)(C,{className:`min-w-72`,children:i.map(e=>(0,Y.jsx)(j,{text:e.domain,onClick:()=>u(e.domain),labelElement:e.isPreferred?(0,Y.jsx)(z,{minimal:!0,intent:T.PRIMARY,className:`text-[10px]`,children:r(`settings.echPreferred`,`首选`)}):void 0},e.domain))});return(0,Y.jsxs)(A,{elevation:M.ONE,className:`dark:bg-gray-900 dark:border-gray-800`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between mb-3`,children:[(0,Y.jsxs)(D,{className:`flex items-center gap-2 m-0 font-bold text-purple-600 dark:text-purple-400`,children:[(0,Y.jsx)(t,{size:18}),` `,r(`settings.echTitle`)]}),(0,Y.jsx)(w,{placement:`bottom-end`,usePortal:!0,content:(0,Y.jsxs)(`div`,{className:`p-4 max-w-sm`,children:[(0,Y.jsx)(D,{children:r(`settings.whatIsEch`,`何为 ECH (Encrypted Client Hello)?`)}),(0,Y.jsx)(`p`,{className:`text-sm mb-2`,children:r(`settings.echHelpDesc`)}),(0,Y.jsxs)(`ul`,{className:`list-disc list-inside text-sm opacity-80 mb-3 space-y-1`,children:[(0,Y.jsx)(`li`,{children:r(`settings.echHelpBenefit1`)}),(0,Y.jsx)(`li`,{children:r(`settings.echHelpBenefit2`)})]}),(0,Y.jsx)(`div`,{className:`text-xs border-t border-gray-100 dark:border-gray-700 pt-2`,children:(0,Y.jsxs)(`a`,{href:`https://en.wikipedia.org/wiki/Encrypted_Client_Hello`,target:`_blank`,rel:`noreferrer`,className:`flex items-center gap-1 text-blue-500 hover:underline`,children:[(0,Y.jsx)(s,{size:10}),` `,r(`setup.learnMore`,`了解更多`)]})})]}),children:(0,Y.jsx)(k,{icon:`help`,variant:`minimal`,intent:T.NONE})})]}),(0,Y.jsxs)(`div`,{className:`space-y-4`,children:[(0,Y.jsx)(L,{label:r(`settings.enableEch`,`启用重写 ECH`),checked:o,onChange:e=>l(e.currentTarget.checked)}),(0,Y.jsx)(`p`,{className:`text-xs opacity-60 leading-relaxed`,children:r(`settings.echDesc`,`针对由 Cloudflare 代理的域名,当查询 HTTPS (Type 65) 或 SVCB (Type 64) 记录且上游未配置 ECH 时,自动重写注入 ECH 参数以保护 SNI 隐私。`)}),o&&(0,Y.jsx)(`div`,{className:`space-y-3 pt-3 border-t border-gray-100 dark:border-gray-800`,children:(0,Y.jsx)(R,{label:r(`settings.echFrontingTitle`,`表层 SNI (ECH Fronting)`),labelInfo:(0,Y.jsx)(`span`,{className:`text-xs opacity-60`,children:r(`settings.echFrontingDesc`,`TLS 握手外层可见的伪装域名`)}),children:(0,Y.jsx)(I,{fill:!0,placeholder:r(`settings.echFrontingCustomPlaceholder`,`输入自定义表层域名,例如 crypto.cloudflare.com`),value:c,onChange:e=>u(e.target.value),onFocus:e=>e.target.select(),className:`font-mono text-sm`,rightElement:(0,Y.jsx)(w,{content:d,placement:`bottom-end`,animation:`minimal`,arrow:!1,children:(0,Y.jsx)(k,{variant:`minimal`,icon:`chevron-down`})})})})})]})]})};var ve=[{key:`pass`,code:`PASS`,intent:T.SUCCESS,defaultTtl:5,labelKey:`settings.ttlPassLabel`,defaultLabel:`PASS`},{key:`redirect`,code:`REDIRECT`,intent:T.PRIMARY,defaultTtl:5,labelKey:`settings.ttlRedirectLabel`,defaultLabel:`REDIRECT`},{key:`block`,code:`BLOCK`,intent:T.DANGER,defaultTtl:5,labelKey:`settings.ttlBlockLabel`,defaultLabel:`BLOCK`}],X=86400;const ye=({settings:e,setSettings:t})=>{let{t:n}=p(),r=(t,n)=>{let r=e.ttl_override?.[t];return{enabled:!!r?.enabled,ttl:typeof r?.ttl==`number`&&Number.isFinite(r.ttl)&&r.ttl>=0?Math.min(X,Math.floor(r.ttl)):n}},[i,a]=(0,J.useState)(null),[o,s]=(0,J.useState)(``),c=(n,r)=>{t({...e,ttl_override:{...e.ttl_override,[n]:r}})},l=(e,t)=>{let n=r(e.key,e.defaultTtl);c(e.key,{enabled:t,ttl:n.ttl})},u=e=>{let t=r(e.key,e.defaultTtl);a(e.key),s(String(t.ttl))},d=(e,t)=>{if(s(t),t.trim()===``)return;let n=Number(t);if(!Number.isInteger(n)||n<0||n>X)return;let i=r(e.key,e.defaultTtl);c(e.key,{enabled:i.enabled,ttl:n})},m=e=>{let t=o.trim(),n=Number(t),i=r(e.key,e.defaultTtl);if(t!==``&&Number.isFinite(n)){let t=Math.max(0,Math.min(X,Math.floor(n)));t!==i.ttl&&c(e.key,{enabled:i.enabled,ttl:t})}a(null)};return(0,Y.jsxs)(A,{elevation:M.ONE,className:`dark:bg-gray-900 dark:border-gray-800`,children:[(0,Y.jsxs)(D,{className:`flex items-center gap-2 mb-2 font-bold text-amber-600 dark:text-amber-400`,children:[(0,Y.jsx)(f,{size:18}),` `,n(`settings.ttlOverrideTitle`,`TTL 重写`)]}),(0,Y.jsx)(`p`,{className:`text-xs opacity-70 mb-4`,children:n(`settings.ttlOverrideDesc`,`按解析结果类型重写返回的 DNS 记录 TTL(支持 0 - {{max}} 秒,0 表示不缓存)。`,{max:X})}),(0,Y.jsx)(`div`,{className:`space-y-3`,children:ve.map(e=>{let t=r(e.key,e.defaultTtl);return(0,Y.jsxs)(`div`,{className:`p-3 rounded-lg bg-gray-50 dark:bg-gray-800/50 border border-gray-200 dark:border-gray-800 space-y-2.5`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 min-w-0`,children:[(0,Y.jsx)(z,{minimal:!0,intent:e.intent,className:`font-mono text-[11px] font-semibold`,children:e.code}),(0,Y.jsx)(`span`,{className:`text-sm font-medium truncate`,children:n(e.labelKey,e.defaultLabel)})]}),(0,Y.jsx)(L,{className:`m-0 shrink-0`,checked:t.enabled,onChange:t=>l(e,t.target.checked)})]}),(0,Y.jsx)(I,{type:`number`,min:0,max:X,step:1,disabled:!t.enabled,value:i===e.key?o:String(t.ttl),onFocus:()=>u(e),onChange:t=>d(e,t.target.value),onBlur:()=>m(e),placeholder:String(e.defaultTtl),rightElement:(0,Y.jsx)(z,{minimal:!0,className:`mr-1 font-mono text-xs`,children:n(`settings.secondsUnit`,`秒`)})})]},e.key)})})]})};var be=300,Z=99,Q=59;function $(e){let t=Math.max(0,Math.floor(e)),n=Math.floor(t/3600),r=Math.floor(t%3600/60),i=t%60,a=e=>String(e).padStart(2,`0`);return n>0?`${a(n)}:${a(r)}:${a(i)}`:`${a(r)}:${a(i)}`}const xe=({settings:e,setSettings:t})=>{let{t:n}=p(),[r,i]=(0,J.useState)(()=>Math.floor(Date.now()/1e3)),a=e.pause_filtering,o=typeof a?.duration_seconds==`number`&&Number.isFinite(a.duration_seconds)&&a.duration_seconds>=0?Math.floor(a.duration_seconds):be,s=Math.min(Z,Math.floor(o/3600)),l=Math.min(Q,Math.floor(o%3600/60)),u=!!a?.enabled,d=typeof a?.expires_at==`number`?a.expires_at:0,f=u&&!(u&&d>0&&r>=d),m=f&&d>0?Math.max(0,d-r):0;(0,J.useEffect)(()=>{if(!u||d<=0)return;let e=setInterval(()=>{i(Math.floor(Date.now()/1e3))},1e3);return()=>clearInterval(e)},[u,d]);let h=n=>{t({...e,pause_filtering:n})},g=e=>{let t=Math.floor(Date.now()/1e3);i(t),h({enabled:e,duration_seconds:o,expires_at:e&&o>0?t+o:0})},_=(e,t)=>{let n=Math.max(0,Math.min(Z,Math.floor(e))),r=Math.max(0,Math.min(Q,Math.floor(t))),a=n*3600+r*60,o=Math.floor(Date.now()/1e3);i(o),h({enabled:f,duration_seconds:a,expires_at:f&&a>0?o+a:0})};return(0,Y.jsxs)(A,{elevation:M.ONE,className:`dark:bg-gray-900 dark:border-gray-800`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between gap-3 mb-2`,children:[(0,Y.jsxs)(D,{className:`flex items-center gap-2 m-0 font-bold text-orange-600 dark:text-orange-400`,children:[(0,Y.jsx)(c,{size:18}),` `,n(`settings.pauseFilteringTitle`,`停用过滤`)]}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 shrink-0`,children:[f&&(0,Y.jsx)(z,{minimal:!0,intent:T.WARNING,className:`font-mono text-xs`,children:d>0?$(m):n(`settings.pauseIndefiniteBadge`,`持续停用`)}),(0,Y.jsx)(L,{className:`m-0`,checked:f,onChange:e=>g(e.target.checked)})]})]}),(0,Y.jsx)(`p`,{className:`text-xs opacity-70 mb-4`,children:n(`settings.pauseFilteringDesc`,`启用后将停用所有过滤列表、自定义规则与默认拦截策略,DNS 请求直接流向上游服务器。`)}),(0,Y.jsxs)(`div`,{className:`space-y-3`,children:[(0,Y.jsx)(`div`,{className:`text-xs font-medium opacity-80`,children:n(`settings.pauseTimeLimitLabel`,`时间限制(默认 5 分钟)`)}),(0,Y.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,Y.jsxs)(`div`,{className:`p-2.5 rounded-lg bg-gray-50 dark:bg-gray-800/50 border border-gray-200 dark:border-gray-800 space-y-1.5`,children:[(0,Y.jsx)(`div`,{className:`text-xs opacity-70`,children:n(`settings.hoursUnit`,`小时`)}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,Y.jsx)(k,{icon:`minus`,minimal:!0,small:!0,disabled:s<=0,onClick:()=>_(s-1,l)}),(0,Y.jsx)(I,{type:`number`,min:0,max:Z,step:1,small:!0,className:`flex-1 text-center font-mono`,value:String(s),onChange:e=>{let t=Number(e.target.value);Number.isFinite(t)&&_(t,l)}}),(0,Y.jsx)(k,{icon:`plus`,minimal:!0,small:!0,disabled:s>=Z,onClick:()=>_(s+1,l)})]})]}),(0,Y.jsxs)(`div`,{className:`p-2.5 rounded-lg bg-gray-50 dark:bg-gray-800/50 border border-gray-200 dark:border-gray-800 space-y-1.5`,children:[(0,Y.jsx)(`div`,{className:`text-xs opacity-70`,children:n(`settings.minutesUnit`,`分钟`)}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,Y.jsx)(k,{icon:`minus`,minimal:!0,small:!0,disabled:l<=0,onClick:()=>_(s,l-1)}),(0,Y.jsx)(I,{type:`number`,min:0,max:Q,step:1,small:!0,className:`flex-1 text-center font-mono`,value:String(l),onChange:e=>{let t=Number(e.target.value);Number.isFinite(t)&&_(s,t)}}),(0,Y.jsx)(k,{icon:`plus`,minimal:!0,small:!0,disabled:l>=Q,onClick:()=>_(s,l+1)})]})]})]}),f&&(0,Y.jsx)(S,{intent:T.WARNING,className:`text-xs py-2`,children:d>0?n(`settings.pauseActiveCountdown`,`当前已停用所有过滤规则,将在 {{time}} 后自动恢复。`,{time:$(m)}):n(`settings.pauseActiveIndefinite`,`当前已停用所有过滤规则(无时间限制,需手动关闭开关恢复)。`)}),!f&&o===0&&(0,Y.jsx)(`div`,{className:`text-xs opacity-60`,children:n(`settings.pauseZeroDurationHint`,`提示:0 小时 0 分钟表示持续停用,直到手动关闭开关。`)})]})]})},Se=({testInput:e,setTestInput:t,handleDnsTest:n,testing:r,testResult:i})=>{let{t:o}=p();return(0,Y.jsxs)(A,{elevation:M.TWO,className:`dark:bg-gray-900 border-t-2 border-blue-500`,children:[(0,Y.jsxs)(D,{className:`flex items-center gap-2 mb-6 font-bold`,children:[(0,Y.jsx)(g,{size:20,className:`text-yellow-500 fill-yellow-500`}),` `,o(`settings.testToolTitle`)]}),(0,Y.jsxs)(`div`,{className:`flex flex-col space-y-6`,children:[(0,Y.jsx)(R,{label:o(`settings.testDomain`),className:`mb-0`,children:(0,Y.jsx)(I,{fill:!0,large:!0,placeholder:o(`settings.domainPlaceholder`),value:e.domain,onChange:n=>t({...e,domain:n.target.value}),onKeyDown:e=>e.key===`Enter`&&n()})}),(0,Y.jsxs)(`div`,{className:`flex justify-end gap-4 items-end`,children:[(0,Y.jsx)(R,{label:o(`settings.recordType`),className:`w-32 mb-0`,children:(0,Y.jsxs)(F,{fill:!0,large:!0,value:e.type,onChange:n=>t({...e,type:n.target.value}),children:[(0,Y.jsx)(`option`,{value:`A`,children:`A`}),(0,Y.jsx)(`option`,{value:`AAAA`,children:`AAAA`}),(0,Y.jsx)(`option`,{value:`CNAME`,children:`CNAME`}),(0,Y.jsx)(`option`,{value:`TXT`,children:`TXT`})]})}),(0,Y.jsx)(R,{label:`\xA0`,className:`mb-0`,children:(0,Y.jsx)(k,{size:`large`,intent:T.PRIMARY,icon:`search`,text:o(`settings.runTest`),onClick:n,loading:r})})]}),i&&(0,Y.jsxs)(`div`,{className:`bg-gray-50 dark:bg-gray-800/50 p-6 rounded-xl border border-gray-100 dark:border-gray-800 space-y-6 animate-in fade-in slide-in-from-top-4`,children:[(0,Y.jsxs)(`div`,{className:`flex flex-wrap gap-4 items-center`,children:[(0,Y.jsx)(z,{large:!0,round:!0,intent:i.action===`PASS`?T.SUCCESS:i.action===`BLOCK`?T.DANGER:T.WARNING,className:`px-4 font-bold`,children:i.action}),(0,Y.jsxs)(`div`,{className:`flex flex-col`,children:[(0,Y.jsx)(`span`,{className:`text-[10px] uppercase font-bold opacity-40`,children:o(`settings.hitRule`)}),(0,Y.jsx)(`span`,{className:`text-sm font-bold`,children:i.reason||o(`settings.defaultAllow`)})]}),(0,Y.jsxs)(`div`,{className:`flex flex-col border-l border-gray-200 dark:border-gray-700 pl-4`,children:[(0,Y.jsx)(`span`,{className:`text-[10px] uppercase font-bold opacity-40`,children:o(`settings.parseLatency`)}),(0,Y.jsx)(`span`,{className:`text-sm font-mono font-bold`,children:i.latency?`${i.latency}ms`:`-`})]}),i.timings&&(0,Y.jsx)(`div`,{className:`flex flex-wrap gap-x-4 gap-y-1 border-l border-gray-200 dark:border-gray-700 pl-4 max-w-md`,children:Object.entries(i.timings).map(([e,t])=>(0,Y.jsxs)(`div`,{className:`flex gap-1 items-baseline`,children:[(0,Y.jsxs)(`span`,{className:`text-[9px] opacity-40 uppercase font-mono`,children:[e,`:`]}),(0,Y.jsxs)(`span`,{className:`text-[10px] font-mono font-bold`,children:[t,`ms`]})]},e))}),(0,Y.jsx)(P,{}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 bg-white dark:bg-gray-900 px-3 py-1.5 rounded-lg shadow-sm border border-gray-100 dark:border-gray-800`,children:[(0,Y.jsx)(a,{size:14,className:`text-red-500`}),(0,Y.jsxs)(`div`,{className:`flex flex-col`,children:[(0,Y.jsx)(`span`,{className:`text-[10px] uppercase font-bold opacity-40 leading-none`,children:o(`settings.sourceIp`)}),(0,Y.jsxs)(`span`,{className:`text-xs font-mono`,children:[i.client_ip,` (`,i.geo_country,`)`]})]})]})]}),(0,Y.jsxs)(`div`,{className:`space-y-3`,children:[(0,Y.jsxs)(`div`,{className:`text-[10px] uppercase font-bold opacity-40 flex items-center gap-1`,children:[(0,Y.jsx)(u,{size:10}),` `,o(`settings.answerSection`)]}),(0,Y.jsx)(`div`,{className:`font-mono text-sm leading-relaxed bg-white dark:bg-gray-900 p-4 rounded-xl border border-gray-100 dark:border-gray-800 shadow-inner`,children:i.answers&&i.answers.length>0?i.answers.map((e,t)=>(0,Y.jsxs)(`div`,{className:`flex gap-4 py-1 border-b border-gray-50 dark:border-gray-800 last:border-0 hover:bg-blue-50/50 dark:hover:bg-blue-900/10 transition-colors px-2`,children:[(0,Y.jsx)(`span`,{className:`w-16 font-bold text-blue-500`,children:e.type}),(0,Y.jsx)(`span`,{className:`flex-1 dark:text-gray-300`,children:e.data}),(0,Y.jsxs)(`span`,{className:`text-[10px] opacity-30 italic`,children:[`TTL: `,e.ttl,`s`]})]},t)):(0,Y.jsx)(`div`,{className:`p-4 opacity-40 italic text-center`,children:o(`settings.noRecordsReturned`)})})]}),i.diagnostics&&(0,Y.jsx)(S,{minimal:!0,intent:i.action===`FAIL`?T.DANGER:T.NONE,className:`text-xs font-mono`,children:(0,Y.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,Y.jsxs)(`div`,{className:`flex justify-between items-center`,children:[(0,Y.jsx)(`span`,{className:`font-bold uppercase tracking-wider`,children:o(`settings.diagnostics`)}),(0,Y.jsx)(`span`,{className:`font-bold`,children:i.action===`FAIL`?i.diagnostics.status>0?`HTTP ${i.diagnostics.status}${i.diagnostics.status_text?` (${i.diagnostics.status_text})`:``}`:`Network / Connection Error`:i.diagnostics.method===`POST`||i.diagnostics.method===`GET`?`HTTP ${i.diagnostics.status}${i.diagnostics.status_text?` (${i.diagnostics.status_text})`:``}`:`Connected (OK)`})]}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 text-xs opacity-80`,children:[(0,Y.jsx)(`span`,{className:`px-1.5 py-0.5 bg-gray-200 dark:bg-gray-700 rounded text-[10px] font-bold`,children:i.diagnostics.method}),(0,Y.jsx)(`span`,{className:`break-all`,children:i.diagnostics.upstream_url})]}),i.diagnostics.cf_ray&&(0,Y.jsxs)(`div`,{className:`text-[11px] opacity-75`,children:[`CF-Ray: `,(0,Y.jsx)(`span`,{className:`font-bold`,children:i.diagnostics.cf_ray})]}),i.diagnostics.error_detail&&i.action===`FAIL`&&(0,Y.jsxs)(`div`,{className:`p-2 bg-red-50 dark:bg-red-950/40 rounded border border-red-200 dark:border-red-900/50 text-red-700 dark:text-red-300 break-words`,children:[(0,Y.jsxs)(`div`,{className:`font-bold mb-0.5`,children:[o(`settings.errorDetail`),`:`]}),(0,Y.jsx)(`div`,{children:i.diagnostics.error_detail})]}),i.diagnostics.response_body&&(0,Y.jsxs)(`div`,{className:`p-2 bg-gray-100 dark:bg-gray-900 rounded border border-gray-200 dark:border-gray-700 text-gray-700 dark:text-gray-300 break-words text-[11px]`,children:[(0,Y.jsxs)(`div`,{className:`font-bold mb-0.5 opacity-60`,children:[o(`settings.upstreamResponse`),`:`]}),(0,Y.jsx)(`div`,{className:`line-clamp-3`,children:i.diagnostics.response_body})]})]})})]})]})]})},Ce=({profileId:e,toasterRef:t,onLogsCleared:n})=>{let{t:r}=p(),[i,a]=(0,J.useState)(!1),[s,c]=(0,J.useState)(!1),l=async()=>{if(confirm(r(`settings.confirmClearProfileLogs`,`确定要清空当前配置的所有查询日志吗?此操作不可恢复。`))){c(!0);try{await G(e),await B.clearProfile(e).catch(()=>{}),typeof window<`u`&&`caches`in window&&await caches.delete(`dns-worker-logs-v1`).catch(()=>{}),t?.current?.show({message:r(`settings.clearProfileLogsSuccess`,`配置日志已成功清空`),intent:T.SUCCESS,icon:`tick`}),n?.()}catch(e){console.error(`[ProfileDangerZone] Clear profile logs failed:`,e);let n=e instanceof Error?e.message:String(e);t?.current?.show({message:n||r(`common.errorNetwork`,`网络请求失败`),intent:T.DANGER,icon:`error`})}finally{c(!1)}}};return(0,Y.jsxs)(`div`,{className:`space-y-4 pt-4 border-t border-gray-200 dark:border-gray-800`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between cursor-pointer select-none py-1 group`,onClick:()=>a(!i),role:`button`,tabIndex:0,"aria-expanded":i,onKeyDown:e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),a(!i))},children:[(0,Y.jsxs)(E,{className:`text-red-500 flex items-center gap-2 m-0! group-hover:text-red-600 dark:group-hover:text-red-400 transition-colors`,children:[(0,Y.jsx)(_,{size:20}),` `,r(`settings.dangerZone`,`危险区域`)]}),(0,Y.jsx)(k,{variant:`minimal`,icon:(0,Y.jsx)(o,{size:18,className:re(`transition-transform duration-200 text-red-500`,!i&&`-rotate-90`)}),text:i?r(`common.collapse`,`收起`):r(`common.expand`,`展开`),className:`text-red-500 hover:text-red-600 dark:hover:text-red-400`,onClick:e=>{e.stopPropagation(),a(!i)},"aria-label":i?r(`common.collapse`,`收起`):r(`common.expand`,`展开`)})]}),(0,Y.jsx)(ne,{isOpen:i,keepChildrenMounted:!0,children:(0,Y.jsx)(`div`,{className:`space-y-4 pt-3`,children:(0,Y.jsx)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-6`,children:(0,Y.jsxs)(A,{elevation:M.ONE,className:`flex flex-col justify-between dark:bg-gray-900 dark:border-gray-800`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(E,{children:r(`settings.clearProfileLogs`,`清空当前配置所有日志`)}),(0,Y.jsx)(`p`,{className:`text-xs opacity-60 mb-3`,children:r(`settings.clearProfileLogsDesc`,`这将删除当前 DNS 配置生成的所有查询日志(包含服务端日志与本地缓存)。此操作不可恢复。`)})]}),(0,Y.jsx)(k,{fill:!0,intent:T.DANGER,text:r(`settings.clearProfileLogsBtn`,`立即清空配置日志`),icon:`trash`,loading:s,onClick:l})]})})})})]})},we=({profileId:e,toasterRef:t,currentUser:n,onSavingChange:r})=>{let[i,a]=(0,J.useState)(null),[o,s]=(0,J.useState)(null),[c,l]=(0,J.useState)(!0),[u,d]=(0,J.useState)(!1),{t:f}=p();(0,J.useEffect)(()=>(r?.(u),()=>{r?.(!1)}),[u,r]);let m=(0,J.useRef)(!0),h=(0,J.useRef)(null),g=(0,J.useRef)(null),_=(0,J.useRef)(0),v=e=>typeof structuredClone==`function`?structuredClone(e):JSON.parse(JSON.stringify(e)),[y,b]=(0,J.useState)(!1),[x,S]=(0,J.useState)(``),[C,w]=(0,J.useState)({domain:`o-o.myaddr.l.google.com`,type:`TXT`}),[E,D]=(0,J.useState)(null),[O,k]=(0,J.useState)(!1);(0,J.useEffect)(()=>{m.current=!0,h.current&&=(clearTimeout(h.current),null),(async()=>{l(!0);try{let t=await U(e);a(t),S(t.name);let n=JSON.parse(t.settings);return g.current=v(n),s(n),i}catch(e){console.error(e)}finally{l(!1)}})()},[e]),(0,J.useEffect)(()=>{if(!c&&o&&m.current){let e=setTimeout(()=>{m.current=!1,o&&(g.current=v(o))},500);return()=>clearTimeout(e)}},[c,o]),(0,J.useEffect)(()=>()=>{h.current&&clearTimeout(h.current)},[]);let A=async()=>{if(!x||x===i?.name){b(!1);return}let n=i?.name||``;d(!0);try{await q(ie(e,x),1e4),a(e=>e?{...e,name:x}:null),b(!1),t?.current?.show({message:f(`common.saveSuccess`,`保存成功`),intent:T.SUCCESS,icon:`tick`})}catch(e){console.error(e),S(n),b(!1);let r=e.message,i=r;r===`The profile name already exists`?i=f(`common.profileNameExists`,`The profile name already exists`):r===`Invalid Profile Name format`&&(i=f(`common.profileNameFormatError`,`Invalid Profile Name format`)),t?.current?.show({message:i||f(`common.saveFailed`,`保存失败`),intent:T.DANGER,icon:`error`})}finally{d(!1)}},j=(0,J.useCallback)(async n=>{if(!n)return;let r=++_.current;d(!0);try{await q(W(e,n),1e4),r===_.current&&(g.current=v(n),t?.current?.show({message:f(`common.saveSuccess`,`保存成功`),intent:T.SUCCESS,icon:`tick`}))}catch(e){console.error(e),r===_.current&&(h.current&&=(clearTimeout(h.current),null),g.current&&s(v(g.current)),t?.current?.show({message:f(`common.saveFailed`,`保存失败`),intent:T.DANGER,icon:`error`}))}finally{r===_.current&&d(!1)}},[e,t,f]),M=(0,J.useCallback)(e=>{h.current&&clearTimeout(h.current),h.current=setTimeout(()=>{j(e)},600)},[j]),N=(0,J.useCallback)(e=>{s(e),m.current||M(e)},[M]);return c||!o?(0,Y.jsx)(`div`,{className:`p-20 flex justify-center`,children:(0,Y.jsx)(ee,{})}):(0,Y.jsxs)(`div`,{className:`p-0 sm:px-4 lg:px-8 max-w-5xl mx-auto space-y-8 pb-20`,children:[(0,Y.jsx)(ce,{profile:i,isEditingName:y,setIsEditingName:b,editName:x,setEditName:S,updateProfileName:A,exportProfile:async()=>{if(!(!i||!o))try{let[n,r]=await Promise.all([K(e).catch(()=>[]),H(e).catch(()=>[])]),a=new Set,s=(n||[]).filter(e=>{let t=(e.pattern||``).trim().toLowerCase();return!t||a.has(t)?!1:(a.add(t),!0)}),c=new Set,l=(r||[]).filter(e=>{let t=(e.url||``).trim().toLowerCase();return!t||c.has(t)?!1:(c.add(t),!0)}).map(e=>({url:e.url,enabled:!!e.enabled})),u={version:2,name:i.name,settings:o,rules:s,filters:l,exported_at:Math.floor(Date.now()/1e3)},d=new Blob([JSON.stringify(u,null,2)],{type:`application/json`}),p=URL.createObjectURL(d),m=document.createElement(`a`);m.href=p,m.download=`dns-worker-${i.name||e}.json`,document.body.appendChild(m),m.click(),document.body.removeChild(m),URL.revokeObjectURL(p),t?.current?.show({message:f(`settings.exportSuccess`,`配置成功导出`),intent:T.SUCCESS,icon:`download`})}catch(e){console.error(e),t?.current?.show({message:f(`settings.exportError`,`导出失败`),intent:T.DANGER,icon:`error`})}}}),(0,Y.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-6`,children:[(0,Y.jsx)(de,{settings:o,setSettings:N}),(0,Y.jsx)(fe,{settings:o,setSettings:N}),(0,Y.jsx)(pe,{settings:o,setSettings:N,isAdmin:n?.role===`admin`,maxRetentionDays:n?.max_log_retention_days??(n?.role===`admin`?30:7)}),(0,Y.jsx)(me,{profileId:e,toasterRef:t}),(0,Y.jsx)(he,{settings:o,setSettings:N}),(0,Y.jsx)(_e,{settings:o,setSettings:N}),(0,Y.jsx)(ye,{settings:o,setSettings:N}),(0,Y.jsx)(xe,{settings:o,setSettings:N})]}),(0,Y.jsx)(Se,{testInput:C,setTestInput:w,handleDnsTest:async()=>{if(C.domain){k(!0),D(null);try{D(await se(e,C))}catch(e){console.error(e)}finally{k(!1)}}},testing:O,testResult:E}),(0,Y.jsx)(Ce,{profileId:e,toasterRef:t})]})};export{we as SettingsView};