dns-worker 1.1.9 → 1.2.0-alpha.424f4e9

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 (46) hide show
  1. package/README.md +2 -2
  2. package/dist/serverfull.mjs +157 -114
  3. package/dist/serverfull.mjs.map +4 -4
  4. package/migrations/0062_add_adguard_and_subdomain_support.sql +28 -0
  5. package/package.json +10 -6
  6. package/static/assets/{AccountView-C0dEts8s.js → AccountView-BNgRF-rj.js} +4 -4
  7. package/static/assets/{AnalyticsView-C-TaYuBb.js → AnalyticsView-DJY9ri7x.js} +2 -2
  8. package/static/assets/{DestinationMap-DbHF1Arz.js → DestinationMap-DWlNpN6K.js} +1 -1
  9. package/static/assets/FilteringView-CU_xHoI5.js +1 -0
  10. package/static/assets/LogsView-2-DP6djr.js +5 -0
  11. package/static/assets/RulesView-BWmhJEh-.js +1 -0
  12. package/static/assets/{SettingsView-io8JzPRs.js → SettingsView-CeevCptJ.js} +1 -1
  13. package/static/assets/SetupView-DIgR7HlK.js +1 -0
  14. package/static/assets/{TrendChart-BOOREEbk.js → TrendChart-DhRyPg70.js} +1 -1
  15. package/static/assets/date-BdQDuREG.js +1 -0
  16. package/static/assets/de-DE-0CVxrNh9.js +12 -0
  17. package/static/assets/es-ES-BgAgArqq.js +12 -0
  18. package/static/assets/fr-FR-DLdOlPIe.js +12 -0
  19. package/static/assets/index-9kbjmMJz.js +17 -0
  20. package/static/assets/index-DAlgfwkx.css +2 -0
  21. package/static/assets/ja-JP-ooIKy-AJ.js +12 -0
  22. package/static/assets/ko-KR-BP3AjtGW.js +12 -0
  23. package/static/assets/ru-RU-DFivojKh.js +12 -0
  24. package/static/assets/services-DENh_eLA.js +1 -0
  25. package/static/assets/{useLogsE2ee-CNIxI_YE.js → useLogsE2ee-EHtnWVXi.js} +1 -1
  26. package/static/assets/vi-VN-C9hJqcKV.js +12 -0
  27. package/static/assets/zh-CN-DhMpMNgZ.js +12 -0
  28. package/static/assets/zh-TW-Bh9tZPPv.js +12 -0
  29. package/static/index.html +2 -2
  30. package/static/assets/FilteringView-D11w0NhQ.js +0 -1
  31. package/static/assets/LogsView-DqM-S5rp.js +0 -5
  32. package/static/assets/RulesView-sxEwRwdo.js +0 -1
  33. package/static/assets/SetupView-Bwoox4Nx.js +0 -1
  34. package/static/assets/date-CmUIEWrj.js +0 -1
  35. package/static/assets/de-DE-DbbT5Cxx.js +0 -12
  36. package/static/assets/es-ES-BURmloF3.js +0 -12
  37. package/static/assets/fr-FR-CFQh-3E3.js +0 -12
  38. package/static/assets/index-Ps0MlBLt.css +0 -2
  39. package/static/assets/index-Wx4BrrkZ.js +0 -17
  40. package/static/assets/ja-JP-DMwARVKx.js +0 -12
  41. package/static/assets/ko-KR-BLWDY5Fe.js +0 -12
  42. package/static/assets/ru-RU-D39eC2of.js +0 -12
  43. package/static/assets/services-CPaeskFl.js +0 -1
  44. package/static/assets/vi-VN-BOpyUW1f.js +0 -12
  45. package/static/assets/zh-CN-Da_oIx9u.js +0 -12
  46. package/static/assets/zh-TW-BuAII2MX.js +0 -12
@@ -1,2 +1,2 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/TrendChart-BOOREEbk.js","assets/index-Wx4BrrkZ.js","assets/vendor-icons-other-BTYC6Wvz.js","assets/vendor-icons-16-BgwRBCeU.js","assets/rolldown-runtime-C4Xdq4VV.js","assets/vendor-icons-20-X5NPN60g.js","assets/vendor-react-BtC4HVVO.js","assets/vendor-i18next-BC3ewzY3.js","assets/vendor-ui-core-DUyKOLA8.js","assets/vendor-utils-xrsi4rSa.js","assets/index-Ps0MlBLt.css","assets/DestinationMap-DbHF1Arz.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{D as t,J as n,L as r,Z as i,bt as a,en as o,j as s,nt as c,v as l}from"./vendor-react-BtC4HVVO.js";import{S as u,b as d,x as f}from"./vendor-icons-other-BTYC6Wvz.js";import"./vendor-i18next-BC3ewzY3.js";import{C as p,H as m,M as h,N as g,P as _,T as v,V as y,d as b,f as x,o as S,p as C,r as w,u as T,x as E}from"./vendor-ui-core-DUyKOLA8.js";import{_t as D}from"./vendor-utils-xrsi4rSa.js";import{E as O,at as k,b as A,it as j,ot as M,sn as N}from"./index-Wx4BrrkZ.js";import{t as P}from"./getFlagEmoji-Cd2A891A.js";import{i as F,n as I,r as L,t as R}from"./useLogsE2ee-CNIxI_YE.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:t,intent:n})=>{let{t:r}=o(),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)(i,{size:14,className:`text-amber-500 shrink-0`}),(0,V.jsx)(`span`,{children:r(`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)(i,{size:14,className:`text-red-500 shrink-0`}),(0,V.jsx)(`span`,{children:r(`logs.decryptionFailed`,`[解密失败]`)})]}):e.domain},{key:`count`,cellClassName:`text-right`,render:e=>(0,V.jsx)(w,{minimal:!0,intent:n,className:`font-bold`,children:e.count})}];return(0,V.jsxs)(E,{elevation:m.ZERO,className:`dark:bg-gray-900 dark:border-gray-800 border border-gray-100 shadow-sm`,children:[(0,V.jsx)(h,{className:`mb-4 font-bold`,children:e}),(0,V.jsx)(T,{striped:!0,className:`w-full`,children:(0,V.jsxs)(`tbody`,{children:[t.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)),t.length===0&&(0,V.jsx)(`tr`,{children:(0,V.jsx)(`td`,{colSpan:a.length,className:`text-center py-8 opacity-50`,children:r(`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,t,n){return e?{...e,destinations:n.serverHasDestinations?e.destinations:t.destinations.length>0?t.destinations:e.destinations,top_allowed:n.serverHasValidTopAllowed?e.top_allowed:t.top_allowed.length>0?t.top_allowed:e.top_allowed,top_blocked:n.serverHasValidTopBlocked?e.top_blocked:t.top_blocked.length>0?t.top_blocked:e.top_blocked,clients:n.serverHasValidClients?e.clients:t.clients.length>0?t.clients:e.clients}:t}function Z(e){let[t,n]=(0,z.useState)([]),[r,i]=(0,z.useState)(30);return(0,z.useEffect)(()=>{let t=!0;return j(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 M(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 Q({profileId:e,range:t,customRange:n,accessPointIdFilter:r,toasterRef:i,onRefreshLocal:a}){let{t:s}=o(),[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 o=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)&&o-u.completedAt<30){i?.current?.show({message:s(`analytics.syncAlreadyUpToDate`,`本地记录已是最新`),intent:y.PRIMARY,icon:`tick`});return}l(!0),d(.05),f.current?.abort();let m=new AbortController;f.current=m;let h=m.signal,g=W(t,n.start,n.end,o);try{let o=await A.syncTargetInterval(e,g.since,g.until,h,e=>{h.aborted||(d(e),a(g))});h.aborted||(p.current={range:t,customStart:n.start,customEnd:n.end,accessPointId:r,completedAt:Math.floor(Date.now()/1e3)},U.invalidateProfile(e),o===0?i?.current?.show({message:s(`analytics.syncAlreadyUpToDate`,`本地记录已是最新`),intent:y.PRIMARY,icon:`tick`}):(d(1),await a(g),i?.current?.show({message:s(`analytics.syncSuccess`,`本地记录同步完成`),intent:y.SUCCESS,icon:`tick`}),await new Promise(e=>setTimeout(e,600))))}catch(e){e?.name!==`AbortError`&&!h.aborted&&(console.error(`[useAnalyticsSync] Manual sync error:`,e),i?.current?.show({message:s(`analytics.syncFailed`,`本地记录同步失败`),intent:y.DANGER,icon:`error`}))}finally{l(!1),d(0)}},[e,t,n,r,c,i,s,a]),stopSync:(0,z.useCallback)(()=>{f.current&&=(f.current.abort(),null),l(!1),d(0),i?.current?.show({message:s(`analytics.syncStopped`,`同步已停止`),intent:y.WARNING,icon:`stop`})},[i,s])}}function ee(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}=Z(e);(0,z.useEffect)(()=>()=>{f.current?.abort()},[]);let{syncing:g,syncProgress:_,syncTargetRange:v,stopSync:y}=Q({profileId:e,range:o,customRange:c,accessPointIdFilter:u,toasterRef:t,onRefreshLocal:(0,z.useCallback)(async t=>{try{let n=await A.queryAnalytics({profileId:e,since:t.since,until:t.until,bucketSec:t.bucketSec,accessPointId:u||void 0});r(e=>X(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{(O.isProfileUnlocked(e)||O.isUnlocked())&&await A.reDecryptLocalLogs(e)}catch{}try{if(await A.init()&&!l.aborted){let t=await A.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)}try{let n=G(t,d,o),a=null;try{a=await k(e,``,n)}catch{if(l.aborted)return;let[t,r,i,o,s,c]=await Promise.all([k(e,`summary`,n),k(e,`trend`,n),k(e,`top_allowed`,n),k(e,`top_blocked`,n),k(e,`clients`,n),k(e,`destinations`,n)]);a={summary:t,trend:r,top_allowed:i,top_blocked:o,clients:s,destinations:c}}if(a&&!l.aborted){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=O.isProfileUnlocked(e)||O.isUnlocked(),a=async()=>{if(!l.aborted)try{let n=await A.queryAnalytics({profileId:e,since:d.since,until:d.until,bucketSec:d.bucketSec,accessPointId:o||void 0});l.aborted||r(e=>{let r=X(e,n,p.current);return U.set(u,r,t,i),r})}catch{}},s=await A.syncMissingIntervals(e,d.since,d.until,l,()=>{a()});!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 te=[{key:`10m`,days:.007},{key:`1h`,days:.0416},{key:`24h`,days:1},{key:`7d`,days:7},{key:`30d`,days:30}];const ne=({range:e,setRange:t,customRange:n,setCustomRange:r,logRetentionDays:i,accessPoints:s,accessPointIdFilter:c,setAccessPointIdFilter:l,loading:u,onApplyCustom:d})=>{let{t:f}=o(),m=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)(p,{variant:`minimal`,children:[te.filter(e=>e.days<=i).map(e=>e.key).map(n=>(0,V.jsx)(g,{active:e===n,onClick:()=>t(n),text:n.toUpperCase()},n)),(0,V.jsx)(v,{content:(0,V.jsxs)(`div`,{className:`p-4 space-y-4 w-64`,children:[(0,V.jsx)(h,{children:f(`analytics.customRange`)}),(0,V.jsx)(C,{label:f(`analytics.startTime`),children:(0,V.jsx)(x,{type:`datetime-local`,max:n.end||m,value:n.start,onChange:e=>r({...n,start:e.target.value})})}),(0,V.jsx)(C,{label:f(`analytics.endTime`),children:(0,V.jsx)(x,{type:`datetime-local`,min:n.start,max:m,value:n.end,onChange:e=>r({...n,end:e.target.value})})}),(0,V.jsx)(g,{fill:!0,intent:y.PRIMARY,text:f(`analytics.apply`),onClick:d})]}),children:(0,V.jsx)(g,{active:e===`custom`,icon:(0,V.jsx)(a,{size:14,className:`mr-1`}),text:f(`analytics.custom`)})})]}),(0,V.jsxs)(`div`,{className:`flex items-center gap-2`,children:[s.length>0&&(0,V.jsx)(b,{value:c||``,onChange:e=>l(e.target.value||null),options:[{label:`${f(`logs.allAccessPoint`)}`,value:``},...s.map(e=>({label:e.name,value:e.id}))],minimal:!0}),u&&(0,V.jsx)(_,{size:16})]})]})},re=({title:e,value:t,icon:n})=>(0,V.jsxs)(E,{elevation:m.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})]})]}),ie=({data:e})=>{let{t:n}=o(),i=e?.summary.reduce((e,t)=>e+t.count,0)||0,a=e?.summary.find(e=>e.action===`BLOCK`)?.count||0,u=e?.summary.find(e=>e.action===`REDIRECT`)?.count||0,d=i>0?(a/i*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:n(`analytics.totalQueries`),value:i.toLocaleString(),icon:(0,V.jsx)(l,{className:`text-blue-500`,size:20})},{title:n(`analytics.blocked`),value:a.toLocaleString(),icon:(0,V.jsx)(s,{className:`text-red-500`,size:20})},{title:n(`analytics.redirected`),value:u.toLocaleString(),icon:(0,V.jsx)(r,{className:`text-amber-500`,size:20})},{title:n(`analytics.blockRate`),value:`${d}%`,icon:(0,V.jsx)(t,{className:`text-green-500`,size:20})},{title:n(`analytics.activeIPs`),value:e?.clients.length.toString()||`0`,icon:(0,V.jsx)(c,{className:`text-purple-500`,size:20})}].map((e,t)=>(0,V.jsx)(re,{title:e.title,value:e.value,icon:e.icon},t))})},ae=({clients:e})=>{let{t}=o();return(0,V.jsx)(S,{title:t(`analytics.clientActivity`),icon:(0,V.jsx)(c,{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:t(`analytics.ipAddress`)}),(0,V.jsx)(`th`,{className:`text-xs uppercase opacity-60`,children:t(`analytics.location`)}),(0,V.jsx)(`th`,{className:`text-xs uppercase opacity-60 text-right`,children:t(`analytics.queries`)})]})}),(0,V.jsxs)(`tbody`,{children:[e?.map((e,n)=>(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)(i,{size:12,className:`text-amber-500 shrink-0`}),(0,V.jsx)(`span`,{children:t(`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)(i,{size:12,className:`text-red-500 shrink-0`}),(0,V.jsx)(`span`,{children:t(`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})]},n)),(!e||e.length===0)&&(0,V.jsx)(`tr`,{children:(0,V.jsx)(`td`,{colSpan:3,className:`text-center py-8 opacity-50`,children:t(`analytics.noData`)})})]})]})})};var oe=(0,z.lazy)(()=>f(()=>import(`./TrendChart-BOOREEbk.js`),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10])).then(e=>({default:e.TrendChart}))),se=(0,z.lazy)(()=>f(()=>import(`./DestinationMap-DbHF1Arz.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)(_,{size:30})});const ce=({profileId:e,toasterRef:t})=>{let{t:r}=o(),i=N(),{data:a,loading:s,range:c,setRange:l,customRange:u,setCustomRange:d,accessPointIdFilter:f,setAccessPointIdFilter:p,accessPoints:g,logRetentionDays:v,fetchData:b}=ee(e,t),{isE2eeEnabled:x,isE2eeUnlocked:C,unlocking:T,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:()=>{b(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(s&&!a)return(0,V.jsx)(`div`,{className:`p-20 flex justify-center`,children:(0,V.jsx)(_,{size:50})});let X=B(a,c,u);return(0,V.jsxs)(`div`,{className:D(`max-w-7xl mx-auto space-y-6`,i?`p-0`:`p-6`),children:[(0,V.jsx)(ne,{range:c,setRange:l,customRange:u,setCustomRange:d,logRetentionDays:v,accessPoints:g,accessPointIdFilter:f,setAccessPointIdFilter:p,loading:s,onApplyCustom:()=>{l(`custom`),b(`custom`,u.start,u.end,f)}}),(x||Y)&&!C&&(0,V.jsx)(F,{isMobile:i,unlocking:T,onUnlockPasskey:q,onOpenRecoveryDialog:()=>{P(``),j(``),k(!0)}}),(0,V.jsx)(ie,{data:a}),(0,V.jsxs)(E,{elevation:m.ONE,className:`dark:bg-gray-900 dark:border-gray-800 relative`,children:[(0,V.jsxs)(h,{className:`mb-4 font-bold flex items-center gap-2`,children:[r(`analytics.queryTrend`),(0,V.jsx)(w,{minimal:!0,round:!0,children:c===`custom`?r(`analytics.custom`):c.toUpperCase()})]}),(0,V.jsx)(z.Suspense,{fallback:(0,V.jsx)($,{}),children:(0,V.jsx)(oe,{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:r(`analytics.topAllowed`),data:a?.top_allowed||[],intent:y.SUCCESS}),(0,V.jsx)(H,{title:r(`analytics.topBlocked`),data:a?.top_blocked||[],intent:y.DANGER})]}),(0,V.jsxs)(`div`,{className:`grid gap-6 grid-cols-1`,children:[(0,V.jsx)(S,{title:r(`analytics.destinationDistribution`),icon:(0,V.jsx)(n,{size:16}),children:(0,V.jsx)(z.Suspense,{fallback:(0,V.jsx)($,{}),children:(0,V.jsx)(se,{destinations:a?.destinations||[],profileId:e||``,range:c,customRange:u,accessPointId:f||void 0})})}),(0,V.jsx)(ae,{clients:a?.clients})]}),(0,V.jsx)(L,{isOpen:O,onClose:()=>k(!1),recoveryKeyInput:A,setRecoveryKeyInput:j,recoveryError:M,unlocking:T,onSubmit:J}),(0,V.jsx)(I,{rotatedKey:U,onClose:()=>W(null),copiedKey:G,onCopyKey:K})]})};export{ce as AnalyticsView};
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/TrendChart-DhRyPg70.js","assets/index-9kbjmMJz.js","assets/vendor-icons-other-BTYC6Wvz.js","assets/vendor-icons-16-BgwRBCeU.js","assets/rolldown-runtime-C4Xdq4VV.js","assets/vendor-icons-20-X5NPN60g.js","assets/vendor-react-BtC4HVVO.js","assets/vendor-i18next-BC3ewzY3.js","assets/vendor-ui-core-DUyKOLA8.js","assets/vendor-utils-xrsi4rSa.js","assets/index-DAlgfwkx.css","assets/DestinationMap-DWlNpN6K.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{D as t,J as n,L as r,Z as i,bt as a,en as o,j as s,nt as c,v as l}from"./vendor-react-BtC4HVVO.js";import{S as u,b as d,x as f}from"./vendor-icons-other-BTYC6Wvz.js";import"./vendor-i18next-BC3ewzY3.js";import{C as p,H as m,M as h,N as g,P as _,T as v,V as y,d as b,f as x,o as S,p as C,r as w,u as T,x as E}from"./vendor-ui-core-DUyKOLA8.js";import{_t as D}from"./vendor-utils-xrsi4rSa.js";import{E as O,at as k,b as A,cn as j,it as M,ot as N}from"./index-9kbjmMJz.js";import{t as P}from"./getFlagEmoji-Cd2A891A.js";import{i as F,n as I,r as L,t as R}from"./useLogsE2ee-EHtnWVXi.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:t,intent:n})=>{let{t:r}=o(),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)(i,{size:14,className:`text-amber-500 shrink-0`}),(0,V.jsx)(`span`,{children:r(`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)(i,{size:14,className:`text-red-500 shrink-0`}),(0,V.jsx)(`span`,{children:r(`logs.decryptionFailed`,`[解密失败]`)})]}):e.domain},{key:`count`,cellClassName:`text-right`,render:e=>(0,V.jsx)(w,{minimal:!0,intent:n,className:`font-bold`,children:e.count})}];return(0,V.jsxs)(E,{elevation:m.ZERO,className:`dark:bg-gray-900 dark:border-gray-800 border border-gray-100 shadow-sm`,children:[(0,V.jsx)(h,{className:`mb-4 font-bold`,children:e}),(0,V.jsx)(T,{striped:!0,className:`w-full`,children:(0,V.jsxs)(`tbody`,{children:[t.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)),t.length===0&&(0,V.jsx)(`tr`,{children:(0,V.jsx)(`td`,{colSpan:a.length,className:`text-center py-8 opacity-50`,children:r(`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,t,n){return e?{...e,destinations:n.serverHasDestinations?e.destinations:t.destinations.length>0?t.destinations:e.destinations,top_allowed:n.serverHasValidTopAllowed?e.top_allowed:t.top_allowed.length>0?t.top_allowed:e.top_allowed,top_blocked:n.serverHasValidTopBlocked?e.top_blocked:t.top_blocked.length>0?t.top_blocked:e.top_blocked,clients:n.serverHasValidClients?e.clients:t.clients.length>0?t.clients:e.clients}:t}function Z(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 N(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 Q({profileId:e,range:t,customRange:n,accessPointIdFilter:r,toasterRef:i,onRefreshLocal:a}){let{t:s}=o(),[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 o=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)&&o-u.completedAt<30){i?.current?.show({message:s(`analytics.syncAlreadyUpToDate`,`本地记录已是最新`),intent:y.PRIMARY,icon:`tick`});return}l(!0),d(.05),f.current?.abort();let m=new AbortController;f.current=m;let h=m.signal,g=W(t,n.start,n.end,o);try{let o=await A.syncTargetInterval(e,g.since,g.until,h,e=>{h.aborted||(d(e),a(g))});h.aborted||(p.current={range:t,customStart:n.start,customEnd:n.end,accessPointId:r,completedAt:Math.floor(Date.now()/1e3)},U.invalidateProfile(e),o===0?i?.current?.show({message:s(`analytics.syncAlreadyUpToDate`,`本地记录已是最新`),intent:y.PRIMARY,icon:`tick`}):(d(1),await a(g),i?.current?.show({message:s(`analytics.syncSuccess`,`本地记录同步完成`),intent:y.SUCCESS,icon:`tick`}),await new Promise(e=>setTimeout(e,600))))}catch(e){e?.name!==`AbortError`&&!h.aborted&&(console.error(`[useAnalyticsSync] Manual sync error:`,e),i?.current?.show({message:s(`analytics.syncFailed`,`本地记录同步失败`),intent:y.DANGER,icon:`error`}))}finally{l(!1),d(0)}},[e,t,n,r,c,i,s,a]),stopSync:(0,z.useCallback)(()=>{f.current&&=(f.current.abort(),null),l(!1),d(0),i?.current?.show({message:s(`analytics.syncStopped`,`同步已停止`),intent:y.WARNING,icon:`stop`})},[i,s])}}function ee(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}=Z(e);(0,z.useEffect)(()=>()=>{f.current?.abort()},[]);let{syncing:g,syncProgress:_,syncTargetRange:v,stopSync:y}=Q({profileId:e,range:o,customRange:c,accessPointIdFilter:u,toasterRef:t,onRefreshLocal:(0,z.useCallback)(async t=>{try{let n=await A.queryAnalytics({profileId:e,since:t.since,until:t.until,bucketSec:t.bucketSec,accessPointId:u||void 0});r(e=>X(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{(O.isProfileUnlocked(e)||O.isUnlocked())&&await A.reDecryptLocalLogs(e)}catch{}try{if(await A.init()&&!l.aborted){let t=await A.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)}try{let n=G(t,d,o),a=null;try{a=await k(e,``,n)}catch{if(l.aborted)return;let[t,r,i,o,s,c]=await Promise.all([k(e,`summary`,n),k(e,`trend`,n),k(e,`top_allowed`,n),k(e,`top_blocked`,n),k(e,`clients`,n),k(e,`destinations`,n)]);a={summary:t,trend:r,top_allowed:i,top_blocked:o,clients:s,destinations:c}}if(a&&!l.aborted){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=O.isProfileUnlocked(e)||O.isUnlocked(),a=async()=>{if(!l.aborted)try{let n=await A.queryAnalytics({profileId:e,since:d.since,until:d.until,bucketSec:d.bucketSec,accessPointId:o||void 0});l.aborted||r(e=>{let r=X(e,n,p.current);return U.set(u,r,t,i),r})}catch{}},s=await A.syncMissingIntervals(e,d.since,d.until,l,()=>{a()});!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 te=[{key:`10m`,days:.007},{key:`1h`,days:.0416},{key:`24h`,days:1},{key:`7d`,days:7},{key:`30d`,days:30}];const ne=({range:e,setRange:t,customRange:n,setCustomRange:r,logRetentionDays:i,accessPoints:s,accessPointIdFilter:c,setAccessPointIdFilter:l,loading:u,onApplyCustom:d})=>{let{t:f}=o(),m=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)(p,{variant:`minimal`,children:[te.filter(e=>e.days<=i).map(e=>e.key).map(n=>(0,V.jsx)(g,{active:e===n,onClick:()=>t(n),text:n.toUpperCase()},n)),(0,V.jsx)(v,{content:(0,V.jsxs)(`div`,{className:`p-4 space-y-4 w-64`,children:[(0,V.jsx)(h,{children:f(`analytics.customRange`)}),(0,V.jsx)(C,{label:f(`analytics.startTime`),children:(0,V.jsx)(x,{type:`datetime-local`,max:n.end||m,value:n.start,onChange:e=>r({...n,start:e.target.value})})}),(0,V.jsx)(C,{label:f(`analytics.endTime`),children:(0,V.jsx)(x,{type:`datetime-local`,min:n.start,max:m,value:n.end,onChange:e=>r({...n,end:e.target.value})})}),(0,V.jsx)(g,{fill:!0,intent:y.PRIMARY,text:f(`analytics.apply`),onClick:d})]}),children:(0,V.jsx)(g,{active:e===`custom`,icon:(0,V.jsx)(a,{size:14,className:`mr-1`}),text:f(`analytics.custom`)})})]}),(0,V.jsxs)(`div`,{className:`flex items-center gap-2`,children:[s.length>0&&(0,V.jsx)(b,{value:c||``,onChange:e=>l(e.target.value||null),options:[{label:`${f(`logs.allAccessPoint`)}`,value:``},...s.map(e=>({label:e.name,value:e.id}))],minimal:!0}),u&&(0,V.jsx)(_,{size:16})]})]})},re=({title:e,value:t,icon:n})=>(0,V.jsxs)(E,{elevation:m.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})]})]}),ie=({data:e})=>{let{t:n}=o(),i=e?.summary.reduce((e,t)=>e+t.count,0)||0,a=e?.summary.find(e=>e.action===`BLOCK`)?.count||0,u=e?.summary.find(e=>e.action===`REDIRECT`)?.count||0,d=i>0?(a/i*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:n(`analytics.totalQueries`),value:i.toLocaleString(),icon:(0,V.jsx)(l,{className:`text-blue-500`,size:20})},{title:n(`analytics.blocked`),value:a.toLocaleString(),icon:(0,V.jsx)(s,{className:`text-red-500`,size:20})},{title:n(`analytics.redirected`),value:u.toLocaleString(),icon:(0,V.jsx)(r,{className:`text-amber-500`,size:20})},{title:n(`analytics.blockRate`),value:`${d}%`,icon:(0,V.jsx)(t,{className:`text-green-500`,size:20})},{title:n(`analytics.activeIPs`),value:e?.clients.length.toString()||`0`,icon:(0,V.jsx)(c,{className:`text-purple-500`,size:20})}].map((e,t)=>(0,V.jsx)(re,{title:e.title,value:e.value,icon:e.icon},t))})},ae=({clients:e})=>{let{t}=o();return(0,V.jsx)(S,{title:t(`analytics.clientActivity`),icon:(0,V.jsx)(c,{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:t(`analytics.ipAddress`)}),(0,V.jsx)(`th`,{className:`text-xs uppercase opacity-60`,children:t(`analytics.location`)}),(0,V.jsx)(`th`,{className:`text-xs uppercase opacity-60 text-right`,children:t(`analytics.queries`)})]})}),(0,V.jsxs)(`tbody`,{children:[e?.map((e,n)=>(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)(i,{size:12,className:`text-amber-500 shrink-0`}),(0,V.jsx)(`span`,{children:t(`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)(i,{size:12,className:`text-red-500 shrink-0`}),(0,V.jsx)(`span`,{children:t(`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})]},n)),(!e||e.length===0)&&(0,V.jsx)(`tr`,{children:(0,V.jsx)(`td`,{colSpan:3,className:`text-center py-8 opacity-50`,children:t(`analytics.noData`)})})]})]})})};var oe=(0,z.lazy)(()=>f(()=>import(`./TrendChart-DhRyPg70.js`),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10])).then(e=>({default:e.TrendChart}))),se=(0,z.lazy)(()=>f(()=>import(`./DestinationMap-DWlNpN6K.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)(_,{size:30})});const ce=({profileId:e,toasterRef:t})=>{let{t:r}=o(),i=j(),{data:a,loading:s,range:c,setRange:l,customRange:u,setCustomRange:d,accessPointIdFilter:f,setAccessPointIdFilter:p,accessPoints:g,logRetentionDays:v,fetchData:b}=ee(e,t),{isE2eeEnabled:x,isE2eeUnlocked:C,unlocking:T,recoveryDialogOpen:O,setRecoveryDialogOpen:k,recoveryKeyInput:A,setRecoveryKeyInput:M,recoveryError:N,setRecoveryError:P,rotatedKey:U,setRotatedKey:W,copiedKey:G,handleCopyRotatedKey:K,handleUnlockPasskey:q,handleUnlockRecoveryKey:J}=R({profileId:e,range:c,onUnlocked:()=>{b(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(s&&!a)return(0,V.jsx)(`div`,{className:`p-20 flex justify-center`,children:(0,V.jsx)(_,{size:50})});let X=B(a,c,u);return(0,V.jsxs)(`div`,{className:D(`max-w-7xl mx-auto space-y-6`,i?`p-0`:`p-6`),children:[(0,V.jsx)(ne,{range:c,setRange:l,customRange:u,setCustomRange:d,logRetentionDays:v,accessPoints:g,accessPointIdFilter:f,setAccessPointIdFilter:p,loading:s,onApplyCustom:()=>{l(`custom`),b(`custom`,u.start,u.end,f)}}),(x||Y)&&!C&&(0,V.jsx)(F,{isMobile:i,unlocking:T,onUnlockPasskey:q,onOpenRecoveryDialog:()=>{P(``),M(``),k(!0)}}),(0,V.jsx)(ie,{data:a}),(0,V.jsxs)(E,{elevation:m.ONE,className:`dark:bg-gray-900 dark:border-gray-800 relative`,children:[(0,V.jsxs)(h,{className:`mb-4 font-bold flex items-center gap-2`,children:[r(`analytics.queryTrend`),(0,V.jsx)(w,{minimal:!0,round:!0,children:c===`custom`?r(`analytics.custom`):c.toUpperCase()})]}),(0,V.jsx)(z.Suspense,{fallback:(0,V.jsx)($,{}),children:(0,V.jsx)(oe,{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:r(`analytics.topAllowed`),data:a?.top_allowed||[],intent:y.SUCCESS}),(0,V.jsx)(H,{title:r(`analytics.topBlocked`),data:a?.top_blocked||[],intent:y.DANGER})]}),(0,V.jsxs)(`div`,{className:`grid gap-6 grid-cols-1`,children:[(0,V.jsx)(S,{title:r(`analytics.destinationDistribution`),icon:(0,V.jsx)(n,{size:16}),children:(0,V.jsx)(z.Suspense,{fallback:(0,V.jsx)($,{}),children:(0,V.jsx)(se,{destinations:a?.destinations||[],profileId:e||``,range:c,customRange:u,accessPointId:f||void 0})})}),(0,V.jsx)(ae,{clients:a?.clients})]}),(0,V.jsx)(L,{isOpen:O,onClose:()=>k(!1),recoveryKeyInput:A,setRecoveryKeyInput:M,recoveryError:N,unlocking:T,onSubmit:J}),(0,V.jsx)(I,{rotatedKey:U,onClose:()=>W(null),copiedKey:G,onCopyKey:K})]})};export{ce as AnalyticsView};
@@ -1 +1 @@
1
- import{i as e}from"./rolldown-runtime-C4Xdq4VV.js";import{L as t,_ as n,d as r,en as i,f as a,g as o,i as s,m as c,p as l,r as u,u as d,y as f}from"./vendor-react-BtC4HVVO.js";import{S as p,b as m}from"./vendor-icons-other-BTYC6Wvz.js";import"./vendor-i18next-BC3ewzY3.js";import"./vendor-utils-xrsi4rSa.js";import{L as h,at as g,b as _}from"./index-Wx4BrrkZ.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:r,onReset:i})=>(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)(n,{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:`Zoom Out`,children:(0,C.jsx)(o,{size:16})}),(0,C.jsx)(`button`,{type:`button`,onClick:i,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)(t,{size:16})})]}),T=({maxThreshold:e,formatNumber:t})=>{let{t:n}=i();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:a,countryCode:o,profileId:s,range:c,customRange:l,accessPointId:u,ispCache:d,onCacheIsp:p,isPinned:m,onClose:h})=>{let{t:v}=i(),y=(0,x.useRef)(null),[b,S]=(0,x.useState)({left:r,top:a-10,alignBottom:!1}),[w,T]=(0,x.useState)([]),[E,D]=(0,x.useState)(!1),O=(0,x.useRef)(d);O.current=d;let k=(0,x.useRef)(p);return k.current=p,(0,x.useEffect)(()=>{if(!o||!s)return;if(t<=0){T([]),D(!1);return}let e=O.current[o];if(e){T(e),D(!1);return}D(!0);let n=Math.floor(Date.now()/1e3),r,i=n,a=`?country_code=${o}&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),a+=`&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&&(a+=`&access_point_id=${u}`);let d=!0,f=setTimeout(async()=>{try{let e=await g(s,`isps`,a),t=Array.isArray(e)?e:[];if(t.length>0){k.current(o,t),d&&(T(t),D(!1));return}}catch(e){console.debug(`[MapTooltip] Server ISP fetch failed, trying local DB fallback:`,e)}try{let e=await _.queryISPs({profileId:s,countryCode:o,since:r,until:i,accessPointId:u||void 0});e&&e.length>0&&(k.current(o,e),d&&T(e))}catch(e){console.warn(`[MapTooltip] Local SQLite ISP query failed:`,e)}finally{d&&D(!1)}},150);return()=>{d=!1,clearTimeout(f)}},[o,s,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(),i=r,o=e.width/2;r-o<4?i=o+4:r+o>n.width-4&&(i=n.width-o-4);let s=a-10,c=!1;a-e.height-15<4&&(s=a+15,c=!0),S({left:i,top:s,alignBottom:c})},[r,a,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)(f,{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:n,containerRef:a,hoveredCountry:o,setHoveredCountry:s})=>{let{i18n:c}=i();return e?(0,C.jsx)(r,{geography:e,children:({geographies:e})=>e.map(e=>{let r=e.id==null?void 0:v[String(e.id)],i=r?t[r]:null,l=i?.count||0,u=n(l);return(0,C.jsx)(d,{geography:e,onMouseEnter:e=>{if(!r||o?.isPinned)return;let t=y(r,c.language)||i?.name||r,n=b(r),u=a.current?.getBoundingClientRect();s({name:t,code:r,count:l,flag:n,x:e.clientX-(u?.left||0),y:e.clientY-(u?.top||0)-15})},onMouseMove:e=>{s(t=>{if(t?.isPinned)return t;let n=a.current?.getBoundingClientRect(),r=e.clientX-(n?.left||0),i=e.clientY-(n?.top||0)-15;return t?{...t,x:r,y:i}:null})},onMouseLeave:()=>{s(e=>e?.isPinned?e:null)},onClick:e=>{if(e.stopPropagation(),!r)return;let t=y(r,c.language)||i?.name||r,n=b(r),o=a.current?.getBoundingClientRect(),u=e.clientX-(o?.left||0),d=e.clientY-(o?.top||0)-15;s(e=>e?.code===r&&e?.isPinned?null:{name:t,code:r,count:l,flag:n,x:u,y:d,isPinned:!0})},style:{default:{fill:`var(--map-color-${u})`,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:a})=>{let{i18n:o}=i();return(0,C.jsx)(C.Fragment,{children:Object.entries(O).map(([i,s])=>{let l=e[i],d=l?.count||0,f=t(d),p=d>0,m=p?4:1.5;return(0,C.jsx)(u,{coordinates:c(s.coordinates[0],s.coordinates[1]),onMouseEnter:e=>{if(r?.isPinned)return;let t=y(i,o.language)||l?.name||i,s=b(i),c=n.current?.getBoundingClientRect();a({name:t,code:i,count:d,flag:s,x:e.clientX-(c?.left||0),y:e.clientY-(c?.top||0)-15})},onMouseMove:e=>{a(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:()=>{a(e=>e?.isPinned?e:null)},onClick:e=>{e.stopPropagation();let t=y(i,o.language)||l?.name||i,r=b(i),s=n.current?.getBoundingClientRect(),c=e.clientX-(s?.left||0),u=e.clientY-(s?.top||0)-15;a(e=>e?.code===i&&e?.isPinned?null:{name:t,code:i,count:d,flag:r,x:c,y:u,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`}})},i)})})},A=({destinations:e,profileId:t,range:n,customRange:r,accessPointId:i})=>{let{geographyData:o,destinationMap:u,scaleConfig:d,getLevel:f,formatNumber:p}=S(e),[m,h]=(0,x.useState)({coordinates:c(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,r,i]);let M=x.useCallback((e,t)=>{O(n=>({...n,[e]:t}))},[]),N=x.useMemo(()=>l(c(-100,-50),c(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)(a,{projection:`geoEqualEarth`,width:800,height:566,style:{width:`100%`,height:`100%`},children:(0,C.jsxs)(s,{zoom:m.zoom,center:m.coordinates,onMoveEnd:e=>h({coordinates:c(e.coordinates[0],e.coordinates[1]),zoom:e.zoom}),maxZoom:8,minZoom:1,enablePan:!0,translateExtent:N,children:[(0,C.jsx)(D,{geographyData:o,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:r,accessPointId:i,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:c(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{L as t,_ as n,d as r,en as i,f as a,g as o,i as s,m as c,p as l,r as u,u as d,y as f}from"./vendor-react-BtC4HVVO.js";import{S as p,b as m}from"./vendor-icons-other-BTYC6Wvz.js";import"./vendor-i18next-BC3ewzY3.js";import"./vendor-utils-xrsi4rSa.js";import{L as h,at as g,b as _}from"./index-9kbjmMJz.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:r,onReset:i})=>(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)(n,{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:`Zoom Out`,children:(0,C.jsx)(o,{size:16})}),(0,C.jsx)(`button`,{type:`button`,onClick:i,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)(t,{size:16})})]}),T=({maxThreshold:e,formatNumber:t})=>{let{t:n}=i();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:a,countryCode:o,profileId:s,range:c,customRange:l,accessPointId:u,ispCache:d,onCacheIsp:p,isPinned:m,onClose:h})=>{let{t:v}=i(),y=(0,x.useRef)(null),[b,S]=(0,x.useState)({left:r,top:a-10,alignBottom:!1}),[w,T]=(0,x.useState)([]),[E,D]=(0,x.useState)(!1),O=(0,x.useRef)(d);O.current=d;let k=(0,x.useRef)(p);return k.current=p,(0,x.useEffect)(()=>{if(!o||!s)return;if(t<=0){T([]),D(!1);return}let e=O.current[o];if(e){T(e),D(!1);return}D(!0);let n=Math.floor(Date.now()/1e3),r,i=n,a=`?country_code=${o}&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),a+=`&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&&(a+=`&access_point_id=${u}`);let d=!0,f=setTimeout(async()=>{try{let e=await g(s,`isps`,a),t=Array.isArray(e)?e:[];if(t.length>0){k.current(o,t),d&&(T(t),D(!1));return}}catch(e){console.debug(`[MapTooltip] Server ISP fetch failed, trying local DB fallback:`,e)}try{let e=await _.queryISPs({profileId:s,countryCode:o,since:r,until:i,accessPointId:u||void 0});e&&e.length>0&&(k.current(o,e),d&&T(e))}catch(e){console.warn(`[MapTooltip] Local SQLite ISP query failed:`,e)}finally{d&&D(!1)}},150);return()=>{d=!1,clearTimeout(f)}},[o,s,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(),i=r,o=e.width/2;r-o<4?i=o+4:r+o>n.width-4&&(i=n.width-o-4);let s=a-10,c=!1;a-e.height-15<4&&(s=a+15,c=!0),S({left:i,top:s,alignBottom:c})},[r,a,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)(f,{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:n,containerRef:a,hoveredCountry:o,setHoveredCountry:s})=>{let{i18n:c}=i();return e?(0,C.jsx)(r,{geography:e,children:({geographies:e})=>e.map(e=>{let r=e.id==null?void 0:v[String(e.id)],i=r?t[r]:null,l=i?.count||0,u=n(l);return(0,C.jsx)(d,{geography:e,onMouseEnter:e=>{if(!r||o?.isPinned)return;let t=y(r,c.language)||i?.name||r,n=b(r),u=a.current?.getBoundingClientRect();s({name:t,code:r,count:l,flag:n,x:e.clientX-(u?.left||0),y:e.clientY-(u?.top||0)-15})},onMouseMove:e=>{s(t=>{if(t?.isPinned)return t;let n=a.current?.getBoundingClientRect(),r=e.clientX-(n?.left||0),i=e.clientY-(n?.top||0)-15;return t?{...t,x:r,y:i}:null})},onMouseLeave:()=>{s(e=>e?.isPinned?e:null)},onClick:e=>{if(e.stopPropagation(),!r)return;let t=y(r,c.language)||i?.name||r,n=b(r),o=a.current?.getBoundingClientRect(),u=e.clientX-(o?.left||0),d=e.clientY-(o?.top||0)-15;s(e=>e?.code===r&&e?.isPinned?null:{name:t,code:r,count:l,flag:n,x:u,y:d,isPinned:!0})},style:{default:{fill:`var(--map-color-${u})`,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:a})=>{let{i18n:o}=i();return(0,C.jsx)(C.Fragment,{children:Object.entries(O).map(([i,s])=>{let l=e[i],d=l?.count||0,f=t(d),p=d>0,m=p?4:1.5;return(0,C.jsx)(u,{coordinates:c(s.coordinates[0],s.coordinates[1]),onMouseEnter:e=>{if(r?.isPinned)return;let t=y(i,o.language)||l?.name||i,s=b(i),c=n.current?.getBoundingClientRect();a({name:t,code:i,count:d,flag:s,x:e.clientX-(c?.left||0),y:e.clientY-(c?.top||0)-15})},onMouseMove:e=>{a(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:()=>{a(e=>e?.isPinned?e:null)},onClick:e=>{e.stopPropagation();let t=y(i,o.language)||l?.name||i,r=b(i),s=n.current?.getBoundingClientRect(),c=e.clientX-(s?.left||0),u=e.clientY-(s?.top||0)-15;a(e=>e?.code===i&&e?.isPinned?null:{name:t,code:i,count:d,flag:r,x:c,y:u,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`}})},i)})})},A=({destinations:e,profileId:t,range:n,customRange:r,accessPointId:i})=>{let{geographyData:o,destinationMap:u,scaleConfig:d,getLevel:f,formatNumber:p}=S(e),[m,h]=(0,x.useState)({coordinates:c(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,r,i]);let M=x.useCallback((e,t)=>{O(n=>({...n,[e]:t}))},[]),N=x.useMemo(()=>l(c(-100,-50),c(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)(a,{projection:`geoEqualEarth`,width:800,height:566,style:{width:`100%`,height:`100%`},children:(0,C.jsxs)(s,{zoom:m.zoom,center:m.coordinates,onMoveEnd:e=>h({coordinates:c(e.coordinates[0],e.coordinates[1]),zoom:e.zoom}),maxZoom:8,minZoom:1,enablePan:!0,translateExtent:N,children:[(0,C.jsx)(D,{geographyData:o,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:r,accessPointId:i,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:c(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{C as t,F as n,Pt as r,R as i,en as a,k as o,ot as s,ut as c}from"./vendor-react-BtC4HVVO.js";import{S as l,b as u}from"./vendor-icons-other-BTYC6Wvz.js";import"./vendor-i18next-BC3ewzY3.js";import{C as d,E as f,H as p,N as m,O as h,S as g,T as _,V as v,f as y,h as b,r as x,u as S,w as C,x as w}from"./vendor-ui-core-DUyKOLA8.js";import{_t as T}from"./vendor-utils-xrsi4rSa.js";import{$ as E,K as D,Y as O,Z as k,_t as A,cn as j,gt as M,h as N,st as P,yt as F,z as I}from"./index-9kbjmMJz.js";var L=e(l(),1);const R=()=>{let{t:e}=a(),[t,n]=(0,L.useState)([]);return(0,L.useEffect)(()=>{I().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 z=e(u(),1);const B=({newUrl:e,setNewUrl:t,onAddList:n,syncing:r,loading:i,lists:o})=>{let{t:s}=a(),c=(0,z.jsx)(f,{className:`min-w-96`,children:R().map((e,t)=>(0,z.jsx)(C,{text:e.label,onClick:()=>n(e.url),disabled:o.some(t=>t.url===e.url),labelElement:(0,z.jsx)(`div`,{className:`flex flex-col items-end text-right`,children:(0,z.jsx)(`span`,{className:`text-[9px] opacity-85 max-w-xl truncate`,title:e.url,children:e.url})})},t))});return(0,z.jsx)(w,{elevation:p.ONE,className:`mb-6`,children:(0,z.jsxs)(`div`,{className:`flex gap-2 flex-col sm:flex-row`,children:[(0,z.jsx)(y,{fill:!0,size:`large`,placeholder:s(`filtering.urlPlaceholder`),value:e,onChange:e=>t(e.target.value),leftIcon:`globe`,rightElement:(0,z.jsx)(_,{content:c,placement:`bottom-end`,animation:`minimal`,arrow:!1,usePortal:!0,children:(0,z.jsx)(m,{variant:`minimal`,icon:`chevron-down`})})}),(0,z.jsx)(m,{intent:v.PRIMARY,size:`large`,icon:`plus`,onClick:()=>n(),className:`shrink-0`,loading:r||i,disabled:r||i,children:s(`filtering.addSubscription`)})]})})},V=({lists:e,onSelect:t})=>{let{t:n}=a(),r=[{key:`url`,header:n(`filtering.tableUrl`),cellClassName:`font-mono text-sm max-w-md truncate`,render:e=>e.url},{key:`lastSync`,header:n(`filtering.tableLastSync`),cellClassName:`text-xs opacity-60`,render:e=>e.last_synced_at?N(new Date(e.last_synced_at*1e3)):n(`filtering.neverSynced`)},{key:`status`,header:n(`filtering.tableStatus`),render:e=>{if(!e.enabled)return(0,z.jsx)(x,{intent:v.NONE,minimal:!0,children:n(`filtering.statusDisabled`,`Disabled`)});let t=!!e.sync_error,r=!!e.last_synced_at,i=n(`filtering.statusNormal`,`Active`),a=v.SUCCESS;return t&&(r?(i=n(`filtering.statusOutdated`,`Outdated`),a=v.WARNING):(i=n(`filtering.statusMissing`,`Missing`),a=v.DANGER)),(0,z.jsx)(x,{intent:a,minimal:!0,children:i})}}];return(0,z.jsx)(`div`,{className:`w-full max-w-full overflow-x-auto pb-4`,children:(0,z.jsxs)(S,{interactive:!0,striped:!0,className:`w-full min-w-max whitespace-nowrap`,children:[(0,z.jsx)(`thead`,{children:(0,z.jsx)(`tr`,{children:r.map(e=>(0,z.jsx)(`th`,{className:e.headerClassName,children:e.header},e.key))})}),(0,z.jsx)(`tbody`,{children:e.map(e=>(0,z.jsx)(`tr`,{onClick:()=>t(e),className:`cursor-pointer`,children:r.map(t=>(0,z.jsx)(`td`,{className:t.cellClassName,children:t.render(e)},t.key))},e.id))})]})})},H=({profileId:e,selectedList:r,onClose:l,onCopy:u,onDelete:d,onToggleEnabled:f,onAllowDomain:p,onSyncSingle:S})=>{let{t:C}=a(),[w,T]=(0,L.useState)(``),[E,D]=(0,L.useState)(!1),[O,A]=(0,L.useState)(null),[j,M]=(0,L.useState)(null),[P,F]=(0,L.useState)(!1),[I,R]=(0,L.useState)(!1),[B,V]=(0,L.useState)(!1),[H,U]=(0,L.useState)(!1),[W,G]=(0,L.useState)(!1),K=(0,L.useRef)(0),q=()=>{K.current++,D(!1),T(``),A(null),M(null),R(!1),G(!1)},J=async()=>{let t=w.trim().toLowerCase();if(!t||!r||(t=t.replace(/^https?:\/\//,``).split(`/`)[0].split(`:`)[0].replace(/\.+$/,``),!t))return;T(t);let n=++K.current,i=r.id;D(!0),M(null),A(null),R(!1);try{let r=await k(e,i,t);K.current===n&&A(r)}catch(e){K.current===n&&M(e instanceof Error?e.message:String(e))}finally{K.current===n&&D(!1)}},Y=async e=>{if(r){V(!0);try{await f(r.id,e)}finally{V(!1)}}},X=async()=>{if(O?.matchedEntry){F(!0);try{await p(O.domain),R(!0)}catch(e){M(e instanceof Error?e.message:String(e))}finally{F(!1)}}},Z=async()=>{if(!(!r||!S)){U(!0);try{await S(r.id)}finally{U(!1)}}};return(0,z.jsxs)(h,{isOpen:r!==null,onClose:()=>{q(),l()},title:C(`filtering.listDetails`,`List Details`),icon:`info-sign`,children:[(0,z.jsxs)(`div`,{className:`p-6 space-y-4`,children:[r?.sync_error&&(0,z.jsx)(g,{intent:v.WARNING,title:C(`filtering.syncError`),icon:`warning-sign`,children:r.sync_error}),(0,z.jsx)(`div`,{className:`bg-gray-50 dark:bg-gray-800 p-4 rounded-lg border border-gray-200 dark:border-gray-700 break-all font-mono text-sm`,children:r?.url}),(0,z.jsxs)(`div`,{className:`flex items-center justify-between border border-gray-200 dark:border-gray-700 rounded-lg p-3`,children:[(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`div`,{className:`text-sm font-bold`,children:C(`filtering.listEnabled`,`List active`)}),(0,z.jsx)(`div`,{className:`text-xs opacity-60`,children:C(`filtering.listEnabledHint`,`Disable to stop filtering with this list without deleting it. Its subscription and sync history are kept.`)})]}),(0,z.jsx)(b,{large:!0,checked:!!r?.enabled,disabled:B,onChange:e=>Y(e.target.checked)})]}),(0,z.jsxs)(`div`,{className:`border border-gray-200 dark:border-gray-700 rounded-lg p-3 space-y-3`,children:[(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`div`,{className:`text-sm font-bold`,children:C(`filtering.checkDomain`,`Check a domain`)}),(0,z.jsx)(`div`,{className:`text-xs opacity-60`,children:C(`filtering.checkDomainHint`,`Lists are stored as compact filters, so their entries cannot be browsed. You can test any domain against this list instantly.`)})]}),(0,z.jsxs)(`div`,{className:`flex gap-2 items-center`,children:[(0,z.jsx)(y,{fill:!0,className:`flex-1 min-w-0`,placeholder:`example.com`,value:w,disabled:E,leftIcon:`globe-network`,onChange:e=>{T(e.target.value),A(null)},onKeyDown:e=>{e.key===`Enter`&&J()}}),(0,z.jsx)(m,{className:`shrink-0 whitespace-nowrap min-w-fit w-auto`,icon:(0,z.jsx)(n,{size:14}),text:C(`filtering.check`,`Check`),loading:E,disabled:!w.trim(),onClick:()=>void J()})]}),j&&(0,z.jsx)(g,{intent:v.DANGER,className:`text-xs`,children:j}),O&&!O.synced&&(0,z.jsx)(g,{intent:v.WARNING,className:`text-xs`,children:C(`filtering.checkNotSynced`,`This list has not finished syncing yet, so there is nothing to check against.`)}),O?.synced&&O.enabled===!1&&(0,z.jsx)(g,{intent:v.NONE,className:`text-xs`,children:C(`filtering.checkListDisabled`,`This list is currently disabled, so it is not filtering anything right now.`)}),O?.synced&&(0,z.jsx)(g,{intent:O.blocked?v.WARNING:v.SUCCESS,className:`text-xs`,icon:O.blocked?`ban-circle`:`tick-circle`,children:O.blocked?(0,z.jsxs)(`div`,{className:`space-y-2`,children:[(0,z.jsxs)(`div`,{children:[C(`filtering.checkBlocked`,`Blocked by this list`),O.matchedEntry&&O.matchedEntry!==O.domain&&(0,z.jsxs)(z.Fragment,{children:[` `,(0,z.jsx)(x,{minimal:!0,className:`font-mono`,children:O.matchedEntry}),` `,O.matchedEntry.includes(`*`)||O.matchedEntry.startsWith(`/`)?C(`filtering.checkViaPattern`,`(匹配到通配规则)`):C(`filtering.checkViaParent`,`(matched a parent domain)`)]})]}),I?(0,z.jsx)(x,{intent:v.SUCCESS,minimal:!0,children:C(`filtering.checkAllowed`,`Exception added - this domain now resolves`)}):(0,z.jsx)(m,{small:!0,icon:(0,z.jsx)(o,{size:12}),intent:v.PRIMARY,loading:P,text:C(`filtering.checkAllowAction`,`Allow anyway`),onClick:()=>void X()})]}):O.whitelisted?(0,z.jsxs)(`div`,{className:`space-y-1`,children:[(0,z.jsxs)(`div`,{className:`font-medium text-emerald-700 dark:text-emerald-400`,children:[C(`filtering.checkWhitelisted`,`被该列表放行`),O.matchedEntry&&(0,z.jsxs)(z.Fragment,{children:[` `,(0,z.jsx)(x,{minimal:!0,intent:v.SUCCESS,className:`font-mono`,children:O.matchedEntry})]})]}),(0,z.jsx)(`div`,{className:`opacity-75`,children:C(`filtering.checkWhitelistedDesc`,`命中该订阅列表中的白名单/例外规则 (@@),即使被其他黑名单规则命中也会优先放行。`)})]}):C(`filtering.checkNotBlocked`,`Not blocked by this list`)})]}),(0,z.jsxs)(`div`,{className:`flex justify-between items-center gap-3`,children:[(0,z.jsxs)(`span`,{className:`text-xs opacity-50 truncate min-w-0`,children:[C(`filtering.tableLastSync`),`:`,` `,r?.last_synced_at?N(new Date(r.last_synced_at*1e3)):`-`]}),(0,z.jsxs)(`div`,{className:`flex gap-2 shrink-0`,children:[(0,z.jsx)(m,{className:`shrink-0 whitespace-nowrap min-w-fit w-auto`,icon:(0,z.jsx)(c,{size:14}),text:C(`setup.copyUrl`,`Copy link`),onClick:()=>{r&&u(r.url)}}),(0,z.jsx)(m,{className:`shrink-0 whitespace-nowrap min-w-fit w-auto`,icon:(0,z.jsx)(s,{size:14}),text:C(`setup.learnMore`,`Open link`),onClick:()=>{r&&window.open(r.url,`_blank`)}})]})]})]}),(0,z.jsxs)(`div`,{className:`p-4 border-t border-gray-100 dark:border-gray-800 flex justify-between items-center`,children:[(0,z.jsx)(_,{isOpen:W,onInteraction:G,placement:`top-start`,portalClassName:`z-20000`,content:(0,z.jsxs)(`div`,{className:`p-3 space-y-3 max-w-xs`,children:[(0,z.jsx)(`p`,{className:`text-xs font-semibold leading-relaxed m-0 text-gray-800 dark:text-gray-200`,children:C(`filtering.deleteConfirm`,`Are you sure you want to delete this list? This action cannot be undone.`)}),(0,z.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,z.jsx)(m,{small:!0,variant:`minimal`,text:C(`common.cancel`,`Cancel`),onClick:()=>G(!1)}),(0,z.jsx)(m,{small:!0,intent:v.DANGER,text:C(`common.confirm`,`Confirm`),onClick:()=>{if(!r)return;let e=r.id;G(!1),q(),d(e)}})]})]}),children:(0,z.jsx)(m,{icon:(0,z.jsx)(t,{size:14}),intent:v.DANGER,text:C(`rules.delete`,`Delete`),onClick:()=>G(!0)})}),(0,z.jsxs)(`div`,{className:`flex gap-2`,children:[S&&(0,z.jsx)(m,{icon:(0,z.jsx)(i,{size:14,className:H?`animate-spin`:``}),intent:v.PRIMARY,loading:H,disabled:H,text:C(`filtering.syncSingle`,`同步此列表`),onClick:()=>void Z()}),(0,z.jsx)(m,{onClick:()=>{q(),l()},text:C(`rules.close`,`Close`)})]})]})]})},U=({profileId:e,toasterRef:t})=>{let n=r(),o=j(),[s,c]=(0,L.useState)([]),[l,u]=(0,L.useState)(``),[f,p]=(0,L.useState)(!0),[h,_]=(0,L.useState)(!1),{t:y}=a(),[b,x]=(0,L.useState)(null),S=async()=>{p(!0);try{c(await P(e))}catch(e){console.error(`Failed to fetch filters`,e)}finally{p(!1)}},C=e=>{navigator.clipboard.writeText(e),t?.current?.show({message:y(`setup.copied`,`已复制到剪贴板`),intent:v.SUCCESS,icon:`duplicate`})},w=async t=>{let n=new Map(t.map(e=>[e.id,e.last_synced_at])),r=0;for(;r<15;){await new Promise(e=>setTimeout(e,2e3));try{let t=await P(e),r=!0;for(let e of t){if(n.has(e.id)&&e.last_synced_at===n.get(e.id)){r=!1;break}if(!n.has(e.id)&&!e.last_synced_at){r=!1;break}}if(r&&t.length>0)return c(t),!0}catch{}r++}return await S(),!1},k=async(t,n)=>{let r=0;for(;r<15;){await new Promise(e=>setTimeout(e,2e3));try{let r=await P(e),i=r.find(e=>e.id===t);if(i&&(i.last_synced_at??0)!==(n??0))return c(r),x(i),!0}catch{}r++}return await S(),!1};return(0,L.useEffect)(()=>{S()},[e]),(0,z.jsxs)(`div`,{className:T(`md:px-8 w-full min-w-0 max-w-5xl mx-auto`,o?`p-1`:`px-8`),children:[(0,z.jsxs)(`div`,{className:`mb-8 flex flex-col md:flex-row justify-between items-start md:items-end gap-4`,children:[(0,z.jsxs)(`div`,{className:`w-full md:w-auto flex-1`,children:[o?(0,z.jsxs)(d,{minimal:!0,fill:o,children:[(0,z.jsx)(m,{active:!1,onClick:()=>n(`/dash/${e}/rules`),text:y(`rules.title`),large:!0}),(0,z.jsx)(m,{active:!0,onClick:()=>n(`/dash/${e}/filter`),text:y(`filtering.title`),large:!0})]}):(0,z.jsx)(`h1`,{className:`bp6-heading`,children:y(`filtering.title`)}),(0,z.jsx)(`p`,{className:`bp6-text-muted mt-2!`,children:y(`filtering.subtitle`)})]}),(0,z.jsx)(m,{icon:(0,z.jsx)(i,{size:16}),text:y(`filtering.syncAll`),onClick:async()=>{_(!0);try{await M(e),t?.current?.show({message:y(`filtering.syncTaskStarted`),intent:v.PRIMARY,icon:`cloud-download`}),await w(s)&&t?.current?.show({message:y(`filtering.syncCheckComplete`),intent:v.SUCCESS,icon:`tick`})}catch(e){console.error(e)}finally{_(!1)}},loading:h||f,disabled:h||f||s.length===0,className:o?`w-full`:``})]}),(0,z.jsx)(g,{intent:v.WARNING,icon:`info-sign`,className:`mb-6`,children:(0,z.jsx)(`p`,{children:y(`filtering.formatDisclaimer`)})}),(0,z.jsx)(B,{newUrl:l,setNewUrl:u,onAddList:async n=>{let r=n||l;if(r){_(!0);try{let n=await D(e,r);t?.current?.show({message:y(`filtering.addSuccess`),intent:v.SUCCESS,icon:`tick`}),u(``),t?.current?.show({message:y(`filtering.singleSyncStarted`,`列表同步任务已开始`),intent:v.PRIMARY,icon:`cloud-download`});let i=n?.id;if(!i){let t=await P(e);i=t.find(e=>e.url.trim().toLowerCase()===r.trim().toLowerCase())?.id,c(t)}i?await k(i,0)&&t?.current?.show({message:y(`filtering.syncCheckComplete`),intent:v.SUCCESS,icon:`tick`}):await S()}catch(e){console.error(e),t?.current?.show({message:e instanceof Error?e.message:String(e),intent:v.DANGER,icon:`error`})}finally{_(!1)}}},syncing:h,loading:f,lists:s}),(0,z.jsx)(V,{lists:s,onSelect:x}),(0,z.jsx)(H,{profileId:e,selectedList:b,onClose:()=>x(null),onCopy:C,onDelete:async n=>{try{await E(e,n),t?.current?.show({message:y(`filtering.deleteSuccess`),intent:v.PRIMARY,icon:`trash`}),x(null),await S()}catch(e){console.error(e)}},onToggleEnabled:async(n,r)=>{try{await F(e,n,r),x(e=>e&&e.id===n?{...e,enabled:r}:e),t?.current?.show({message:r?y(`filtering.listEnabledToast`,`List enabled - rebuilding filter`):y(`filtering.listDisabledToast`,`List disabled - rebuilding filter`),intent:v.PRIMARY,icon:r?`tick`:`disable`}),await S()}catch(e){console.error(e),t?.current?.show({message:e instanceof Error?e.message:String(e),intent:v.DANGER,icon:`error`})}},onAllowDomain:async n=>{await O(e,{type:`ALLOW`,pattern:n}),t?.current?.show({message:y(`filtering.allowRuleAdded`,`Exception added for {{domain}}`,{domain:n}),intent:v.SUCCESS,icon:`tick`})},onSyncSingle:async n=>{try{let r=s.find(e=>e.id===n)?.last_synced_at;await A(e,n),t?.current?.show({message:y(`filtering.singleSyncStarted`,`列表同步任务已开始`),intent:v.PRIMARY,icon:`cloud-download`}),await k(n,r)&&t?.current?.show({message:y(`filtering.syncCheckComplete`),intent:v.SUCCESS,icon:`tick`})}catch(e){console.error(e),t?.current?.show({message:e instanceof Error?e.message:String(e),intent:v.DANGER,icon:`error`})}}})]})};export{U as FilteringView};
@@ -0,0 +1,5 @@
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/services-DENh_eLA.js","assets/index-9kbjmMJz.js","assets/vendor-icons-other-BTYC6Wvz.js","assets/vendor-icons-16-BgwRBCeU.js","assets/rolldown-runtime-C4Xdq4VV.js","assets/vendor-icons-20-X5NPN60g.js","assets/vendor-react-BtC4HVVO.js","assets/vendor-i18next-BC3ewzY3.js","assets/vendor-ui-core-DUyKOLA8.js","assets/vendor-utils-xrsi4rSa.js","assets/index-DAlgfwkx.css"])))=>i.map(i=>d[i]);
2
+ import{i as e}from"./rolldown-runtime-C4Xdq4VV.js";import{A as t,Ct as n,H as r,J as i,K as a,Ot as o,U as s,Z as c,b as l,bt as u,en as d,j as f,nt as p,rt as m,xt as h}from"./vendor-react-BtC4HVVO.js";import{S as g,b as _,x as v}from"./vendor-icons-other-BTYC6Wvz.js";import"./vendor-i18next-BC3ewzY3.js";import{C as y,E as b,M as x,N as S,P as C,S as w,T,V as E,a as D,f as O,h as k,l as A,o as j,p as M,r as N,u as P,w as F,x as I}from"./vendor-ui-core-DUyKOLA8.js";import{_t as L}from"./vendor-utils-xrsi4rSa.js";import{E as R,at as z,b as B,cn as ee,ct as V,h as te,it as H,lt as ne,ot as U,v as W}from"./index-9kbjmMJz.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-EHtnWVXi.js";import{t as J}from"./SwipeableDrawer-B1CCYC-Y.js";var Y=e(g(),1),X=e(_(),1);const se=({range:e,setRange:t,customRange:n,setCustomRange:r,nowStr:i,fetchLogs:a,isMobile:o,logRetentionDays:s})=>{let{t:c}=d(),l=[{key:`10m`,days:.007},{key:`1h`,days:.0416},{key:`24h`,days:1},{key:`7d`,days:7},{key:`30d`,days:30}].filter(e=>e.days<=s).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)(y,{minimal:o,variant:o?void 0:`minimal`,children:[l.map(n=>(0,X.jsx)(S,{active:e===n,onClick:()=>t(n),text:n.toUpperCase(),small:o},n)),(0,X.jsx)(T,{content:(0,X.jsxs)(`div`,{className:`p-4 space-y-2 w-64`,children:[(0,X.jsx)(x,{children:c(`analytics.customRange`)}),(0,X.jsx)(M,{label:c(`analytics.startTime`),children:(0,X.jsx)(O,{type:`datetime-local`,max:n.end||i,value:n.start,onChange:e=>r({...n,start:e.target.value})})}),(0,X.jsx)(M,{label:c(`analytics.endTime`),children:(0,X.jsx)(O,{type:`datetime-local`,min:n.start,max:i,value:n.end,onChange:e=>r({...n,end:e.target.value})})}),(0,X.jsx)(S,{fill:!0,intent:E.PRIMARY,text:c(`analytics.apply`),onClick:()=>{t(`custom`),a(`custom`,!0)}})]}),children:(0,X.jsx)(S,{active:e===`custom`,icon:(0,X.jsx)(u,{size:14}),text:o?``:c(`analytics.custom`),small:o})})]})})},ce=({statusFilter:e,setStatusFilter:t,isMobile:n})=>{let{t:r}=d(),i=(0,X.jsxs)(b,{children:[(0,X.jsx)(F,{icon:e===null?`tick`:void 0,text:r(`logs.allStatus`),onClick:()=>t(null)}),(0,X.jsx)(A,{}),(0,X.jsx)(F,{icon:e===`PASS`?`tick`:void 0,intent:E.SUCCESS,text:r(`logs.onlyPass`),onClick:()=>t(`PASS`)}),(0,X.jsx)(F,{icon:e===`BLOCK`?`tick`:void 0,intent:E.DANGER,text:r(`logs.onlyBlock`),onClick:()=>t(`BLOCK`)}),(0,X.jsx)(F,{icon:e===`REDIRECT`?`tick`:void 0,intent:E.WARNING,text:r(`logs.onlyRedirect`),onClick:()=>t(`REDIRECT`)})]}),a=(()=>{switch(e){case`PASS`:return{text:r(`logs.statusPass`),intent:E.SUCCESS};case`BLOCK`:return{text:r(`logs.statusBlock`),intent:E.DANGER};case`REDIRECT`:return{text:r(`logs.statusRedirect`),intent:E.WARNING};default:return{text:r(`logs.allStatus`),intent:E.NONE}}})();return(0,X.jsx)(T,{content:i,placement:`bottom-start`,children:(0,X.jsx)(S,{icon:(0,X.jsx)(m,{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}=d(),o=(0,X.jsxs)(b,{children:[(0,X.jsx)(F,{icon:e===null?`tick`:void 0,text:i(`logs.allAccessPoint`),onClick:()=>t(null)}),(0,X.jsx)(A,{}),n.map(n=>(0,X.jsx)(F,{icon:e===n.id?`tick`:void 0,text:n.name,onClick:()=>t(n.id)},n.id))]}),s=e&&n.find(t=>t.id===e)?.name||i(`logs.allAccessPoint`);return(0,X.jsx)(T,{content:o,placement:`bottom-start`,children:(0,X.jsx)(S,{icon:(0,X.jsx)(a,{size:14}),rightIcon:`caret-down`,intent:e?E.PRIMARY:E.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}=d(),[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)(O,{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)(S,{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)(F,{icon:e===null?`tick`:void 0,text:r(`logs.allCountry`),onClick:()=>{t(null),o(!1)}}),(0,X.jsx)(A,{})]}),u.length===0?(0,X.jsx)(F,{disabled:!0,text:r(`logs.noMatchingCountries`,`No matching countries found`)}):u.map(n=>(0,X.jsx)(F,{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))]})]}),m=e?`${q(e)} ${K(e,i.language)||e} (${e})`:r(`logs.allCountry`);return(0,X.jsx)(T,{content:f,placement:`bottom-start`,isOpen:a,onInteraction:e=>{o(e),e||c(``)},children:(0,X.jsx)(S,{icon:(0,X.jsx)(p,{size:14}),rightIcon:`caret-down`,intent:e?E.PRIMARY:E.NONE,text:m,variant:`outlined`,fill:n})})},fe=({profileId:e,range:t,customRange:n,destCountryFilter:r,accessPointIdFilter:i,ispFilter:a,setIspFilter:o,isMobile:c})=>{let{t:l}=d(),[u,f]=(0,Y.useState)(!1),[p,m]=(0,Y.useState)([]),[h,g]=(0,Y.useState)(!1),[_,v]=(0,Y.useState)(``),y=(0,Y.useRef)(``),x=`${e}:${t}:${n.start?Math.floor(new Date(n.start).getTime()/1e3):``}:${n.end?Math.floor(new Date(n.end).getTime()/1e3):``}:${r||``}:${i||``}`,w=async()=>{g(!0);try{let a=Math.floor(Date.now()/1e3),o,s=a,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=a-600;break;case`1h`:o=a-3600;break;case`24h`:o=a-86400;break;case`7d`:o=a-604800;break;case`30d`:o=a-2592e3;break;default:o=a-3600;break}c.set(`range`,t)}r&&c.set(`country_code`,r),i&&c.set(`access_point_id`,i);try{let t=await z(e,`isps`,c.toString());if(Array.isArray(t)&&t.length>0){m(t),y.current=x,g(!1);return}}catch(e){console.debug(`[IspFilter] Server ISP fetch failed, falling back to local DB:`,e)}try{let t=await B.queryISPs({profileId:e,countryCode:r||void 0,since:o,until:s,accessPointId:i||void 0});t&&t.length>0?m(t):m([])}catch(e){console.warn(`[IspFilter] Local SQLite query failed:`,e),m([])}y.current=x}catch(e){console.error(`Failed to fetch ISPs for filter`,e)}finally{g(!1)}},D=e=>{f(e),e?y.current!==x&&w():v(``)},k=(0,Y.useMemo)(()=>{let e=_.trim().toLowerCase();return e?p.filter(t=>t.name.toLowerCase().includes(e)):p},[p,_]),j=(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)(O,{leftIcon:`search`,placeholder:l(`logs.searchIsp`,`Search ISP...`),value:_,onChange:e=>v(e.target.value),small:!0,autoFocus:!0,rightElement:_?(0,X.jsx)(S,{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)(C,{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)(F,{icon:a===null?`tick`:void 0,text:l(`logs.allIsp`),onClick:()=>{o(null),f(!1)}}),(0,X.jsx)(A,{})]}),k.length===0?(0,X.jsx)(F,{disabled:!0,text:l(`logs.noMatchingIsps`,`No matching ISPs found`)}):k.map(e=>(0,X.jsx)(F,{icon:a===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:()=>{o(e.name),f(!1)}},e.name))]})})]}),M=a||l(`logs.allIsp`);return(0,X.jsx)(T,{content:j,placement:`bottom-start`,isOpen:u,onInteraction:D,children:(0,X.jsx)(S,{icon:(0,X.jsx)(s,{size:14}),rightIcon:`caret-down`,intent:a?E.PRIMARY:E.NONE,text:M,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:f,accessPointIdFilter:p,setAccessPointIdFilter:m,accessPoints:h,destCountryFilter:g,setDestCountryFilter:_,ispFilter:v,setIspFilter:y,searchQuery:b,setSearchQuery:x,stats:C,logRetentionDays:w,onExport:T,exporting:D,loading:A=!1,syncing:j=!1})=>{let{t:M}=d(),[P,F]=(0,Y.useState)(!0),I=u!==null||p!==null||g!==null||v!==null;return(0,X.jsxs)(`div`,{className:`p-4 ${s&&P?`space-y-0`:`space-y-4`} shrink-0 bg-white/50 dark:bg-gray-900/50 backdrop-blur-sm border-b border-gray-100 dark:border-gray-800`,children:[(0,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||!P)&&(0,X.jsx)(N,{minimal:!0,round:!0,children:t===`custom`?M(`analytics.custom`):t.toUpperCase()}),C&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(N,{minimal:!0,round:!0,children:C.total.toLocaleString()}),(0,X.jsx)(N,{minimal:!0,round:!0,intent:E.SUCCESS,children:C.pass.toLocaleString()}),(0,X.jsx)(N,{minimal:!0,round:!0,intent:E.DANGER,children:C.block.toLocaleString()}),(0,X.jsx)(N,{minimal:!0,round:!0,intent:E.WARNING,children:C.redirect.toLocaleString()})]})]}),!s&&(0,X.jsx)(`p`,{className:`bp6-text-muted mt-1`,children:M(`logs.subtitle`)})]}),s&&(0,X.jsx)(S,{icon:P?`chevron-down`:`chevron-up`,variant:`minimal`,onClick:()=>F(!P)})]}),(!s||!P)&&(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)(S,{icon:`download`,onClick:T,loading:D,title:M(`logs.export`,`Export Logs`),text:s?void 0:M(`logs.export`,`Export Logs`)}),(0,X.jsx)(k,{label:M(`logs.realtime`),checked:c,onChange:e=>l(e.target.checked),className:`mb-0!`}),(0,X.jsx)(S,{icon:`refresh`,onClick:()=>o(t,!0,!1,!0),loading:A||j,variant:`minimal`,small:s})]})]})]}),(!s||!P)&&(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)(S,{icon:`filter-remove`,onClick:()=>{f(null),m(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:f,isMobile:s}),h.length>0&&(0,X.jsx)(le,{accessPointIdFilter:p,setAccessPointIdFilter:m,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:p,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)(O,{leftIcon:`search`,placeholder:M(`logs.searchPlaceholder`),value:b,onChange:e=>x(e.target.value),rightElement:b?(0,X.jsx)(S,{icon:`cross`,minimal:!0,onClick:()=>x(``)}):void 0,fill:!0})})})]})]})},me=({logs:e,setSelectedLog:t,setIsDrawerOpen:n,lastLogElementRef:r,prevLatestTimestamp:i,realtimeRefresh:a})=>{let{t:o}=d();return(0,X.jsx)(`div`,{className:`space-y-3 py-4`,children:e.map((s,l)=>{let u=a&&i!==null&&s.timestamp>i,d=(s.encrypt_version??0)>0||!!(s.kem_key_id||s.encrypted_payload),f=d&&(!s.domain||s.domain===`[Encrypted]`),p=d&&!!(s.domain&&s.domain!==`[Encrypted]`);return(0,X.jsxs)(I,{interactive:!0,onClick:()=>{t(s),n(!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?r: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)(c,{size:14,className:`text-amber-500 shrink-0`}):(0,X.jsx)(`img`,{src:`/api/icon/${s.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?o(`logs.encryptedRecord`,`[加密记录]`):s.domain}),p&&(0,X.jsx)(c,{size:12,className:`text-emerald-500 shrink-0 opacity-80`})]}),(0,X.jsx)(N,{minimal:!0,round:!0,intent:s.action===`PASS`?E.SUCCESS:s.action===`BLOCK`?E.DANGER:E.WARNING,className:`text-[10px] shrink-0`,children:s.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(s.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:s.record_type}),s.access_point_name&&(0,X.jsx)(`span`,{className:`text-[10px] opacity-50 truncate max-w-25`,children:s.access_point_name})]}),(0,X.jsx)(`div`,{className:`text-[10px] opacity-40 font-mono italic`,children:s.latency?`${s.latency}ms`:``})]})]},s.id)})})},he=({logs:e,setSelectedLog:t,setIsDrawerOpen:n,lastLogElementRef:r,prevLatestTimestamp:i,realtimeRefresh:a})=>{let{t:o}=d(),s=[{key:`time`,header:o(`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:o(`logs.tableDomain`),headerClassName:`w-1/4`,render:e=>{let t=(e.encrypt_version??0)>0||!!(e.kem_key_id||e.encrypted_payload),n=t&&(!e.domain||e.domain===`[Encrypted]`),r=t&&!!(e.domain&&e.domain!==`[Encrypted]`);return(0,X.jsxs)(`div`,{className:`flex items-center gap-2 truncate`,children:[n?(0,X.jsx)(c,{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":n}),children:n?o(`logs.encryptedRecord`,`[加密记录]`):e.domain}),r&&(0,X.jsx)(`span`,{title:o(`settings.e2eeEnabled`,`已加密`),className:`inline-flex items-center`,children:(0,X.jsx)(c,{size:12,className:`text-emerald-500 shrink-0 opacity-80`})})]})}},{key:`answer`,header:o(`logs.tableAnswer`),headerClassName:`w-1/4`,cellClassName:`truncate font-mono text-[11px] opacity-70`,render:e=>e.answer||`-`},{key:`source`,header:o(`logs.tableSource`),headerClassName:`w-32`,render:e=>(0,X.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,X.jsx)(N,{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:o(`logs.tableType`),headerClassName:`w-20`,cellClassName:`text-center`,render:e=>(0,X.jsx)(`code`,{className:`text-[10px]`,children:e.record_type})},{key:`status`,header:o(`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:o(`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)(P,{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:s.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((o,c)=>{let l=a&&i!==null&&o.timestamp>i;return(0,X.jsx)(`tr`,{onClick:()=>{t(o),n(!0)},className:L(`cursor-pointer`,{"animate-row-glow":l}),ref:c===e.length-1?r:null,children:s.map(e=>(0,X.jsx)(`td`,{className:L(`px-4 py-3`,e.cellClassName),children:e.render(o,c)},e.key))},o.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:f,logRetentionDays:p})=>{let{t:m}=d(),[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)(w,{title:p===0?m(`logs.loggingDisabledTitle`,`日志记录已关闭`):m(o?`logs.noResults`:`logs.noRecords`),icon:p===0?`disable`:o?`search`:`outdated`,intent:p===0?E.WARNING:E.NONE,children:p===0?m(`logs.loggingDisabledDesc`,`当前配置的日志留存已设置为“关闭”,系统不记录任何查询日志。如需查看,请在设置中启用日志留存。`):o?m(`logs.noResultsDesc`,{query:o}):m(`logs.noRecordsDesc`)})}):a?(0,X.jsx)(me,{logs:e,setSelectedLog:u,setIsDrawerOpen:f,lastLogElementRef:c,prevLatestTimestamp:l,realtimeRefresh:i}):(0,X.jsx)(he,{logs:e,setSelectedLog:u,setIsDrawerOpen:f,lastLogElementRef:c,prevLatestTimestamp:l,realtimeRefresh:i}),(0,X.jsx)(`div`,{className:`p-6 flex flex-col items-center`,children:n?(0,X.jsx)(C,{size:16}):i?e.length>0&&(0,X.jsx)(`span`,{className:`text-[10px] opacity-30 italic`,children:m(`logs.realtimeLoadMoreTip`)}):!r&&e.length>0&&(0,X.jsx)(`span`,{className:`text-[10px] opacity-30 italic`,children:m(`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":m(`logs.scrollToTop`),title:m(`logs.scrollToTop`),className:L(`pointer-events-auto group inline-flex items-center gap-1.5 rounded-full select-none`,`backdrop-blur-md bg-white/70 dark:bg-gray-900/70 hover:bg-white/90 dark:hover:bg-gray-800/90`,`border border-gray-200/80 dark:border-gray-700/80 hover:border-gray-300 dark:hover:border-gray-600`,`text-gray-700 dark:text-gray-200 hover:text-gray-950 dark:hover:text-white`,`shadow-sm hover:shadow active:scale-95 transition-all duration-200 cursor-pointer`,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 V(n,t.id,t.timestamp,{signal:e.signal}).then(async r=>{if(!e.signal.aborted)try{let e=r?.encrypt_version??t.encrypt_version,a=await R.decryptLogEntry(n,r);i(n=>({...n||t,...a,encrypt_version:e??a.encrypt_version}))}catch{i(e=>({...e||t,...r}))}}).catch(e=>{e.name!==`AbortError`&&(console.error(e),i(e=>e||t))}).finally(()=>{e.signal.aborted||o(!1)}),()=>{e.abort()}}else i(null)},[e,t?.id,n]),{detailedLog:r,loading:a}}const 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:t,loading:n})=>{let{t:r}=d(),i=t?.encrypt_version??e.encrypt_version??(t?.kem_key_id||e.kem_key_id?2:0),a=i>0||!!(e.kem_key_id||e.encrypted_payload||t?.kem_key_id||t?.encrypted_payload),s=i===2||!!(e.kem_key_id||t?.kem_key_id),l=a&&(!e.domain||e.domain===`[Encrypted]`);return(0,X.jsx)(j,{title:r(`logs.basicInfo`),icon:(0,X.jsx)(o,{size:16}),className:`shadow-none! rounded-lg!`,children:(0,X.jsx)(D,{children:(0,X.jsxs)(`div`,{className:`space-y-3`,children:[(0,X.jsx)(Z,{label:r(`logs.detailDomain`),value:(0,X.jsxs)(`div`,{className:`flex items-center gap-2 justify-end font-bold`,children:[l?(0,X.jsx)(c,{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":l}),children:l?r(`logs.encryptedRecord`,`[加密记录]`):e.domain})]}),bold:!0}),(0,X.jsx)(Z,{label:r(`logs.detailType`),value:e.record_type}),(0,X.jsx)(Z,{label:r(`logs.detailLatency`),value:e.latency?`${e.latency} ms`:`-`}),(0,X.jsx)(Z,{label:r(`logs.detailAccessPoint`),value:(()=>{let r=t?.access_point_name||e.access_point_name,i=t?.access_point_id||e.access_point_id;return r?i&&i!==r?(0,X.jsx)(`span`,{title:i,className:`cursor-help`,children:r}):r:i?(0,X.jsx)(`span`,{className:`font-mono text-xs`,children:i}):n?(0,X.jsx)(C,{size:12}):`-`})()}),(0,X.jsx)(Z,{label:r(`logs.detailProfile`),value:t?.profile_name||t?.client_ip||e.client_ip||(n?(0,X.jsx)(C,{size:12}):`-`)}),(0,X.jsx)(Z,{label:r(`logs.detailTime`),value:te(new Date(e.timestamp*1e3))}),(0,X.jsx)(Z,{label:r(`logs.detailStatus`),value:(0,X.jsx)(N,{minimal:!0,intent:e.action===`PASS`?E.SUCCESS:e.action===`BLOCK`?E.DANGER:E.WARNING,children:e.action})}),(0,X.jsx)(Z,{label:r(`logs.detailUpstream`),value:t?.upstream||e.upstream||(n?(0,X.jsx)(C,{size:12}):`-`)}),(0,X.jsx)(Z,{label:r(`logs.detailReason`),value:e.reason||r(`logs.detailNoReason`),italic:!0}),(0,X.jsx)(Z,{label:r(`logs.detailECS`),value:t?.ecs||e.ecs||(n?(0,X.jsx)(C,{size:12}):`-`),italic:!0}),(0,X.jsx)(Z,{label:r(`logs.detailIsClientEncrypted`,`是否用户端加密`),value:a?(0,X.jsxs)(`div`,{className:`flex items-center gap-1.5 justify-end`,children:[(0,X.jsx)(c,{size:13,className:l?`text-amber-500`:`text-emerald-500`}),(0,X.jsxs)(`span`,{className:L(`text-xs font-medium`,l?`text-amber-600 dark:text-amber-400`:`text-emerald-600 dark:text-emerald-400`),children:[l?r(`logs.encryptedLocked`,`是 (未解锁)`):r(`logs.encryptedYes`,`是`),s?` (PQC)`:``]})]}):(0,X.jsx)(`span`,{className:`text-xs text-gray-400 dark:text-gray-500`,children:r(`logs.notEncrypted`,`否`)})})]})})})},ye=({selectedLog:e})=>{let{t}=d(),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)(j,{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)(N,{minimal:!0,intent:E.PRIMARY,className:`text-xs`,children:t(`logs.rewritten`,`已重写`)})]}),icon:(0,X.jsx)(p,{size:16}),className:`shadow-none! rounded-lg!`,children:(0,X.jsx)(D,{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)(N,{minimal:!0,intent:E.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)(N,{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)(N,{minimal:!0,intent:E.SUCCESS,className:`font-mono break-all max-w-full select-all text-left whitespace-normal h-auto py-1 inline-block`,title:i,children:[(0,X.jsx)(`span`,{className:`font-bold`,children:`ech:`}),` `,i]},t):r===`alpn`?(0,X.jsxs)(N,{minimal:!0,intent:E.WARNING,className:`font-mono`,children:[(0,X.jsx)(`span`,{className:`font-bold`,children:`alpn:`}),` `,i]},t):(0,X.jsxs)(N,{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:a}=d(),o=t?.client_ip||e.client_ip,s=t?.geo_country||e.geo_country,c=`Unknown`;if(s){let e=s.toUpperCase().trim();c=e===`LAN`||e===`LOCAL`||e===`PRIVATE`||e===`PRIVATE NETWORK`?r(`setup.privateNetwork`,`Private Network`):e===`UN`||e===`UNKNOWN`||e===`XX`?r(`common.unknown`,`Unknown`):K(s,a.language)||s}let u=t?.dest_country_code||e.dest_country_code,f=t?.dest_country||e.dest_country,p=t?.dest_isp||e.dest_isp,m=null,h=t?.dest_geoip||e.dest_geoip;if(h)try{let e=JSON.parse(h);!u&&e.country_code&&(u=e.country_code);let t=[e.city,e.region,e.country].filter(Boolean),n=f||u||void 0;m={locationTitle:t.length>0?t.join(`, `):n,isp:e.isp||p||void 0,as:e.as||void 0}}catch{}return!m&&(f||u||p)&&(m={locationTitle:f||u||void 0,isp:p||void 0}),(0,X.jsx)(j,{title:r(`logs.networkDetails`),icon:(0,X.jsx)(l,{size:16}),className:`shadow-none! rounded-lg!`,children:(0,X.jsx)(D,{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:o||(n?(0,X.jsx)(C,{size:12}):`-`)}),(s||n)&&(0,X.jsx)(N,{minimal:!0,title:c,children:s?q(s):`-`})]})]}),(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`)}),(u||n)&&(0,X.jsx)(N,{minimal:!0,title:f||u||`Unknown`,children:u?q(u):`-`})]}),n&&!m?(0,X.jsx)(`div`,{className:`flex items-center justify-center py-2`,children:(0,X.jsx)(C,{size:16})}):m?(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)(i,{size:16,className:`oklch(60.9% 0.126 221.723) mt-1 shrink-0`}),(0,X.jsxs)(`div`,{children:[m.locationTitle&&(0,X.jsx)(`div`,{className:`font-bold text-sm`,children:m.locationTitle}),(m.isp||m.as)&&(0,X.jsxs)(`div`,{className:`text-xs opacity-70 mt-1`,children:[m.isp,m.as&&(0,X.jsx)(`span`,{className:`opacity-60 block mt-0.5`,children:m.as})]})]})]})}):(0,X.jsx)(`div`,{className:`text-xs opacity-50 py-1`,children:`-`})]})]})})})},xe=({selectedLog:e,onQuickAction:i})=>{let{t:a}=d(),o=(e.encrypt_version??0)>0&&(!e.domain||e.domain===`[Encrypted]`);return(0,X.jsx)(j,{title:a(`logs.quickActions`),icon:(0,X.jsx)(r,{size:16}),className:`shadow-none! rounded-lg!`,children:(0,X.jsx)(D,{children:o?(0,X.jsx)(`p`,{className:`text-xs text-center text-gray-500 italic py-2 m-0`,children:a(`settings.e2eeUnlockPrompt`,`此记录已加密,请先解锁私钥后再进行操作。`)}):(0,X.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,X.jsx)(S,{fill:!0,intent:E.SUCCESS,icon:(0,X.jsx)(t,{size:16}),text:a(`logs.actionAllow`),onClick:()=>i?.(e.domain,`ALLOW`)}),(0,X.jsx)(S,{fill:!0,intent:E.DANGER,icon:(0,X.jsx)(f,{size:16}),text:a(`logs.actionBlock`),onClick:()=>i?.(e.domain,`BLOCK`)}),(0,X.jsx)(S,{fill:!0,icon:(0,X.jsx)(n,{size:16}),text:a(`logs.actionRedirect`),onClick:()=>i?.(e.domain,`REDIRECT`,e.record_type)})]})})})},Se=({isDrawerOpen:e,setIsDrawerOpen:t,selectedLog:n,profileId:r,isMobile:i,onQuickAction:a})=>{let{t:s}=d(),{detailedLog:c,loading:l}=_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)(o,{size:18}),(0,X.jsx)(`span`,{children:s(`logs.logDetails`)})]}),icon:`info-sign`,size:i?`100%`:`450px`,children:n&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(ve,{selectedLog:n,detailedLog:c,loading:l}),(0,X.jsx)(ye,{selectedLog:n}),(0,X.jsx)(be,{selectedLog:n,detailedLog:c,loading:l}),(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)(()=>{H(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)(()=>{U(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=ne(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),_=z(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 B.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 B.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 B.syncProfileLogs(i,void 0,u,t,n);if(!t.aborted&&(e>0||p.rows.length===0)&&(p=await B.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 B.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 B.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 B.backfillLogs(r,t,l,d,n);if(n.aborted)return{success:!1};if(e.length>0){let f=await B.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),z(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&&W.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&&W.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&&W.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 W.onNewLogs(e=>{if(!e||e.length===0)return;let d=e.filter(e=>{if(t&&e.action!==t||n&&e.access_point_id!==n||r&&(e.dest_country_code||e.dest_country)!==r||i&&e.dest_isp!==i)return!1;if(a){let t=a.toLowerCase(),n=e.domain?.toLowerCase().includes(t),r=e.client_ip?.toLowerCase().includes(t),i=e.reason?.toLowerCase().includes(t);if(!n&&!r&&!i)return!1}return!0});d.length!==0&&(u(s.current.length>0?s.current[0].timestamp:null),c(e=>{let t=new Set(e.map(e=>`${e.timestamp}-${e.id}`)),n=d.filter(e=>!t.has(`${e.timestamp}-${e.id}`));return n.length===0?e:[...n,...e].slice(0,o)}),l(t=>{if(!t)return t;let n=0,r=0,i=0;for(let t of e)t.action===`PASS`?n++:t.action===`BLOCK`?r++:t.action===`REDIRECT`&&i++;return{total:t.total+e.length,pass:t.pass+n,block:t.block+r,redirect:t.redirect+i}}))})},[e,t,n,r,i,a,o,s,c,l,u])}function 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){W.disconnect();return}let t=!1,n=null,o=()=>{n||=setInterval(()=>{let{range:e,searchQuery:n,fetchLogs:r}=c.current;!t&&document.visibilityState===`visible`&&i.current&&i.current.scrollTop<50&&!a.current&&!n&&e!==`custom`&&r(e,!0,!0)},8e3)},s=()=>{n&&=(clearInterval(n),null)},l=W.onStatusChange(e=>{t=e,e?s():o()}),u=c.current.logsRef.current,d=u.length>0?u[0]:null,f=d?d.timestamp:Math.floor(Date.now()/1e3)-60,p=d?d.id:0;W.connect(e,f,p);let m=setTimeout(()=>{t||o()},2500),h=()=>{if(document.visibilityState===`visible`)if(t){let e=c.current.logsRef.current,t=e.length>0?e[0]:null;t&&W.updateCursor(t.timestamp,t.id)}else{let{range:e,fetchLogs:t}=c.current;t(e,!0,!0)}};return document.addEventListener(`visibilitychange`,h),()=>{clearTimeout(m),s(),l(),W.disconnect(),document.removeEventListener(`visibilitychange`,h)}},[e,r])}function $(e){let t=new Date(e*1e3),n=-t.getTimezoneOffset(),r=n>=0?`+`:`-`,i=e=>String(e).padStart(2,`0`);return t.getFullYear()+`-`+i(t.getMonth()+1)+`-`+i(t.getDate())+`T`+i(t.getHours())+`:`+i(t.getMinutes())+`:`+i(t.getSeconds())+`.`+(e=>String(e).padStart(3,`0`))(t.getMilliseconds())+(n===0?`Z`:r+i(Math.floor(Math.abs(n)/60))+`:`+i(Math.abs(n)%60))}function Ne(e){let t=[`profile_id`,`access_point_id`,`time`,`client_ip`,`geo_country`,`domain`,`record_type`,`action`,`reason`,`answer`,`dest_geoip`,`ecs`,`upstream`,`latency`],n=[t.join(`,`)];for(let r of e){let e=t.map(e=>{let t=``;if(e===`time`)t=$(r.timestamp);else{let n=r[e];t=n==null?e===`dest_geoip`&&(r.dest_country_code||r.dest_country||r.dest_isp)?JSON.stringify({country_code:r.dest_country_code||``,country:r.dest_country||``,isp:r.dest_isp||``}):``:typeof n==`object`?JSON.stringify(n):String(n)}let n=t.replace(/"/g,`""`);return n.includes(`,`)||n.includes(`
4
+ `)||n.includes(`\r`)||n.includes(`"`)?`"${n}"`:n});n.push(e.join(`,`))}return n.join(`
5
+ `)}function Pe(e,t){let n=new Blob([e],{type:`text/csv;charset=utf-8;`}),r=URL.createObjectURL(n),i=document.createElement(`a`);i.setAttribute(`href`,r),i.setAttribute(`download`,t),document.body.appendChild(i),i.click(),document.body.removeChild(i),URL.revokeObjectURL(r)}function Fe(e,t,n,r){let i=e=>e.replace(/[:*?"<>|]/g,`-`),a=i($(t)),o=i($(n)),s=i(r.toString());return`query_logs_${e}_${a}_${o}${s?`_${s}`:``}.csv`}function Ie({profileId:e,range:t,customRange:n,statusFilter:r,accessPointIdFilter:i,destCountryFilter:a,ispFilter:o,searchQuery:s,toasterRef:c}){let{t:l}=d(),[u,f]=(0,Y.useState)(!1);return{exporting:u,handleExportLogs:async()=>{f(!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 B.init()){let t=await B.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-DENh_eLA.js`);return{exportProfileLogs:e}},__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10])),n=await t(e,f.toString());n&&Array.isArray(n)&&(p=n)}if(!p||p.length===0){c?.current?.show({message:l(`logs.noResults`,`No logs found to export`),intent:E.WARNING});return}if(p.some(e=>(e.encrypt_version??(e.encrypted_payload?1:0))>0)){if(!R.isProfileUnlocked(e))try{await R.unlockProfile(e)}catch(e){console.warn(`[LogExport] Auto-unlock attempt failed or was cancelled:`,e)}p=await R.decryptLogsBatch(e,p),p.some(e=>(e.encrypt_version??(e.encrypted_payload?1:0))>0||e.domain===`[Encrypted]`)&&c?.current?.show({message:l(`logs.e2eeLockedExportWarning`,`部分日志处于加密状态且未解锁,导出的数据可能包含未解密内容。`),intent:E.WARNING,icon:`lock`})}m&&p.length>0&&B.batchInsertLogs(e,p).catch(e=>{console.warn(`[LogExport] Failed to cache exported logs into local SQLite:`,e)}),Pe(Ne(p),Fe(e,p[0].timestamp,p[p.length-1].timestamp,f)),c?.current?.show({message:l(`logs.exportSuccess`,`Logs exported successfully`),intent:E.SUCCESS})}catch(e){console.error(`Failed to export logs`,e),c?.current?.show({message:l(`logs.exportError`,`Failed to export logs`),intent:E.DANGER})}finally{f(!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=ee(),[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:S,searchQuery:w,setSearchQuery:T,logs:E,loading:D,loadingMore:O,syncing:k,hasMore:A,stats:j,logRetentionDays:M,prevLatestTimestamp:N,scrollContainerRef:P,lastLogElementRef:F,fetchLogs:I,exporting:L,handleExportLogs:R}=Le({profileId:e,toasterRef:n}),{isE2eeEnabled:z,isE2eeUnlocked:B,unlocking:V,recoveryDialogOpen:te,setRecoveryDialogOpen:H,recoveryKeyInput:ne,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)(C,{})}):(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:S,searchQuery:w,setSearchQuery:T,stats:j,logRetentionDays:M,onExport:R,exporting:L,loading:D,syncing:k}),z&&!B&&(0,X.jsx)(re,{isMobile:r,unlocking:V,onUnlockPasskey:ce,onOpenRecoveryDialog:()=>{G(``),U(``),H(!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:()=>H(!1),recoveryKeyInput:ne,setRecoveryKeyInput:U,recoveryError:W,unlocking:V,onSubmit:le}),(0,X.jsx)(ie,{rotatedKey:K,onClose:()=>q(null),copiedKey:J,onCopyKey:se})]})};export{Re as LogsView};
@@ -0,0 +1 @@
1
+ import{i as e}from"./rolldown-runtime-C4Xdq4VV.js";import{C as t,Et as n,O as r,Pt as i,St as a,en as o,mt as s,nt as c,wt as l,xt as u,z as d}from"./vendor-react-BtC4HVVO.js";import{S as f,b as p}from"./vendor-icons-other-BTYC6Wvz.js";import"./vendor-i18next-BC3ewzY3.js";import{C as m,H as h,N as g,O as _,P as v,S as y,T as b,V as x,b as S,d as C,f as w,p as T,r as E,u as D,x as O,y as k}from"./vendor-ui-core-DUyKOLA8.js";import{_t as A}from"./vendor-utils-xrsi4rSa.js";import{F as j,Y as M,bt as N,cn as P,h as F,nt as I,ot as L,ut as R}from"./index-9kbjmMJz.js";var z=e(f(),1),B=e(p(),1);const V=({newRule:e,setNewRule:t,addRule:n,loading:r})=>{let{t:i}=o();return(0,B.jsx)(O,{elevation:h.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)(C,{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)(w,{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)(g,{intent:x.PRIMARY,size:`large`,icon:(0,B.jsx)(d,{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)(c,{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)(w,{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)(w,{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)(w,{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)(w,{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)(g,{intent:x.PRIMARY,large:!0,icon:(0,B.jsx)(d,{size:18}),onClick:n,text:i(`rules.saveRedirectRule`),loading:r,disabled:r})})]})]})})},H=({rules:e,startEdit:t,getBlockDetail:i})=>{let{t:c}=o(),[d,f]=(0,z.useState)(`created_at`),[p,m]=(0,z.useState)(`desc`),h=e=>{d===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():c(`rules.detailAllow`,`Forward to upstream`),_=(0,z.useMemo)(()=>[...e].sort((e,t)=>{let n=0;switch(d){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,d,p,i,c]),v=[{key:`action`,header:c(`rules.tableAction`),headerClassName:`w-32`,render:e=>(0,B.jsxs)(B.Fragment,{children:[e.type===`BLOCK`&&(0,B.jsx)(E,{intent:x.DANGER,minimal:!0,icon:(0,B.jsx)(r,{size:12,className:`mr-1`}),children:c(`rules.labelBlock`)}),e.type===`ALLOW`&&(0,B.jsx)(E,{intent:x.SUCCESS,minimal:!0,icon:(0,B.jsx)(s,{size:12,className:`mr-1`}),children:c(`rules.labelAllow`)}),e.type===`REDIRECT`&&(0,B.jsx)(E,{intent:x.WARNING,minimal:!0,icon:(0,B.jsx)(l,{size:12,className:`mr-1`}),children:c(`rules.labelRedirect`)})]})},{key:`pattern`,header:c(`rules.tablePattern`),headerClassName:`w-1/4`,cellClassName:`font-mono font-bold`,render:e=>(0,B.jsx)(`span`,{children:e.pattern})},{key:`details`,header:c(`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:c(`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:c(`rules.detailAllow`)})})},{key:`created_at`,header:c(`rules.tableCreatedAt`,`添加时间`),headerClassName:`w-44`,cellClassName:`text-xs text-gray-500 align-middle`,render:e=>e.created_at?F(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:v.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:c(`rules.clickToSort`,`点击排序`),children:(0,B.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,B.jsx)(`span`,{children:e.header}),d===e.key?p===`asc`?(0,B.jsx)(u,{size:13,className:`text-blue-500 shrink-0`}):(0,B.jsx)(n,{size:13,className:`text-blue-500 shrink-0`}):(0,B.jsx)(a,{size:12,className:`opacity-30 hover:opacity-75 shrink-0`})]})},e.key))})}),(0,B.jsx)(`tbody`,{children:_.map(e=>(0,B.jsx)(`tr`,{onClick:()=>t(e),className:`cursor-pointer`,children:v.map(t=>(0,B.jsx)(`td`,{className:t.cellClassName,children:t.render(e)},t.key))},e.id))})]})})},U=({editRule:e,setEditRule:n,saveEditRule:r,cancelEdit:i,deleteRule:a,isSaving:s,isDeleting:l})=>{let{t:u}=o();return(0,B.jsxs)(_,{isOpen:!!e,onClose:i,title:u(`rules.editRule`,`Edit Rule`),style:{width:`600px`},children:[(0,B.jsx)(S,{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:u(`rules.action`),className:`w-40 mb-0`,children:(0,B.jsx)(C,{fill:!0,value:e.type,onChange:t=>n({...e,type:t.target.value}),options:[{label:u(`rules.typeBlock`),value:`BLOCK`},{label:u(`rules.typeAllow`),value:`ALLOW`},{label:u(`rules.typeRedirect`),value:`REDIRECT`}]})}),(0,B.jsx)(T,{label:u(`rules.pattern`),className:`flex-1 mb-0`,children:(0,B.jsx)(w,{placeholder:u(`rules.patternPlaceholder`),value:e.pattern,onChange:t=>n({...e,pattern:t.target.value})})})]}),(0,B.jsx)(`div`,{className:`text-xs text-gray-500 dark:text-gray-400`,children:u(`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)(c,{size:14}),(0,B.jsx)(`span`,{className:`text-xs font-bold uppercase tracking-wider`,children:u(`rules.redirectSettings`)})]}),(0,B.jsxs)(`div`,{className:`grid grid-cols-2 gap-4`,children:[(0,B.jsx)(T,{label:u(`rules.aRecord`),className:`mb-0`,children:(0,B.jsx)(w,{placeholder:u(`rules.ipv4Placeholder`),value:e.v_a||``,onChange:t=>n({...e,v_a:t.target.value})})}),(0,B.jsx)(T,{label:u(`rules.aaaaRecord`),className:`mb-0`,children:(0,B.jsx)(w,{placeholder:u(`rules.ipv6Placeholder`),value:e.v_aaaa||``,onChange:t=>n({...e,v_aaaa:t.target.value})})}),(0,B.jsx)(T,{label:u(`rules.cnameRecord`),className:`mb-0`,children:(0,B.jsx)(w,{placeholder:u(`rules.cnamePlaceholder`),value:e.v_cname||``,onChange:t=>n({...e,v_cname:t.target.value})})}),(0,B.jsx)(T,{label:u(`rules.txtRecord`),className:`mb-0`,children:(0,B.jsx)(w,{placeholder:u(`rules.txtPlaceholder`),value:e.v_txt||``,onChange:t=>n({...e,v_txt:t.target.value})})})]})]})]})}),(0,B.jsx)(k,{actions:(0,B.jsxs)(`div`,{className:`flex gap-2`,children:[(0,B.jsx)(g,{onClick:i,disabled:s||l,children:u(`rules.cancel`,`Cancel`)}),(0,B.jsx)(g,{intent:x.PRIMARY,onClick:r,loading:s,disabled:s||l,children:u(`rules.saveChanges`,`Save Changes`)})]}),children:(0,B.jsx)(g,{icon:(0,B.jsx)(t,{size:14}),intent:x.DANGER,text:u(`rules.delete`,`Delete`),onClick:()=>{e&&a(e.id)},loading:l,disabled:s||l})})]})},W=({profileId:e,prefill:t,onPrefillUsed:n,toasterRef:r})=>{let a=i(),[s,c]=(0,z.useState)([]),[l,u]=(0,z.useState)(null),[d,f]=(0,z.useState)(!0),[p,h]=(0,z.useState)(!1),[_,S]=(0,z.useState)(!1),[C,w]=(0,z.useState)(!1),{t:T}=o(),D=P(),[O,k]=(0,z.useState)({type:`BLOCK`,pattern:``,include_subdomains:!1,v_a:``,v_aaaa:``,v_txt:``,v_cname:``}),[F,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?s.some(t=>{if(t.type!==`REDIRECT`)return!1;let n=t.pattern.trim().toLowerCase();return n===e||n===`*.${e}`}):!1},[s]),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),L(e)]);c(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`,D?`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:[D?(0,B.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,B.jsxs)(m,{minimal:!0,fill:D,className:`flex-1`,children:[(0,B.jsx)(g,{active:!0,onClick:()=>a(`/dash/${e}/rules`),text:T(`rules.title`),large:!0}),(0,B.jsx)(g,{active:!1,onClick:()=>a(`/dash/${e}/filter`),text:T(`filtering.title`),large:!0})]}),d&&(0,B.jsx)(v,{size:16})]}):(0,B.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,B.jsx)(`h1`,{className:`bp6-heading m-0`,children:T(`rules.title`)}),d&&(0,B.jsx)(v,{size:20})]}),(0,B.jsx)(`p`,{className:`bp6-text-muted mt-2!`,children:T(`rules.subtitle`)})]}),!d&&!Y&&(0,B.jsx)(`div`,{className:`flex items-center gap-3 self-start md:self-auto`,children:(0,B.jsx)(b,{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:T(`rules.addSelfRedirectPrompt`,`是否增加指向本站的 CNAME 规则,用于地区网络优化(中国大陆用户推荐)?`)}),(0,B.jsxs)(`div`,{className:`flex justify-end gap-2 pt-1`,children:[(0,B.jsx)(g,{size:`small`,variant:`minimal`,text:T(`common.no`,`否`),onClick:()=>J(!1)}),(0,B.jsx)(g,{size:`small`,intent:x.PRIMARY,text:T(`common.yes`,`是`),onClick:X})]})]}),children:(0,B.jsx)(E,{minimal:!0,interactive:!0,intent:x.PRIMARY,className:`cursor-pointer select-none font-medium`,children:T(`rules.addSelfRedirectTag`,`增加本站重定向?`)})})})]})}),(0,B.jsx)(y,{intent:x.PRIMARY,icon:`info-sign`,className:`mb-6`,children:(0,B.jsx)(`p`,{children:T(`rules.wildcardDisclaimer`,`若要匹配子域名,需使用通配符 *.example.com ,example.com 不会匹配子域名。`)})}),(0,B.jsx)(V,{newRule:O,setNewRule:k,addRule:async()=>{let t=O.pattern.trim();if(!t){r?.current?.show({message:T(`rules.patternEmpty`,`Domain pattern cannot be empty`),intent:x.DANGER});return}let n=t.toLowerCase();if(s.some(e=>e.pattern.trim().toLowerCase()===n)){r?.current?.show({message:T(`rules.duplicatePattern`,`Rule for this domain already exists`),intent:x.DANGER});return}h(!0);try{await M(e,{...O,pattern:t,include_subdomains:0}),r?.current?.show({message:T(`rules.addSuccess`,`Rule added successfully`),intent:x.SUCCESS}),k({type:`BLOCK`,pattern:``,include_subdomains:!1,v_a:``,v_aaaa:``,v_txt:``,v_cname:``}),await Z()}catch(e){r?.current?.show({message:e.message||T(`rules.addFailed`,`Failed to add rule`),intent:x.DANGER})}finally{h(!1)}},loading:p}),d&&s.length===0?(0,B.jsxs)(`div`,{className:`p-16 flex flex-col justify-center items-center gap-3`,children:[(0,B.jsx)(v,{size:32}),(0,B.jsx)(`span`,{className:`text-xs text-gray-500 dark:text-gray-400 font-medium`,children:T(`common.loading`,`加载中...`)})]}):s.length===0?(0,B.jsx)(y,{title:T(`rules.noRulesTitle`),children:T(`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)(v,{size:32})}),(0,B.jsx)(H,{rules:s,startEdit:e=>{W({...e,include_subdomains:e.include_subdomains===1||e.include_subdomains===!0})},getBlockDetail:()=>{if(!l)return T(`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:F,setEditRule:W,saveEditRule:async()=>{if(!F)return;let t=F.pattern.trim();if(!t){r?.current?.show({message:T(`rules.patternEmpty`,`Domain pattern cannot be empty`),intent:x.DANGER});return}let n=t.toLowerCase();if(s.some(e=>e.id!==F.id&&e.pattern.trim().toLowerCase()===n)){r?.current?.show({message:T(`rules.duplicatePattern`,`Rule for this domain already exists`),intent:x.DANGER});return}S(!0);try{await N(e,{...F,pattern:t,include_subdomains:0}),r?.current?.show({message:T(`rules.updateSuccess`,`Rule updated successfully`),intent:x.SUCCESS}),W(null),await Z()}catch(e){r?.current?.show({message:e.message||T(`rules.updateFailed`,`Failed to update rule`),intent:x.DANGER})}finally{S(!1)}},cancelEdit:()=>{W(null)},deleteRule:async t=>{w(!0);try{await I(e,t)}catch(e){console.error(e)}finally{w(!1)}W(null),await Z()},isSaving:_,isDeleting:C})]})};export{W as RulesView};
@@ -1 +1 @@
1
- import{i as e}from"./rolldown-runtime-C4Xdq4VV.js";import{C as t,D as n,J as r,Ot as i,P as a,V as o,Z as s,ct as c,en as l,ft as u,nt as d,ot as f,st as p,tt as m,v as h,vt as g,y as _}from"./vendor-react-BtC4HVVO.js";import{S as v,b as y}from"./vendor-icons-other-BTYC6Wvz.js";import"./vendor-i18next-BC3ewzY3.js";import{B as b,D as x,E as S,H as C,M as w,N as T,P as E,S as D,T as O,V as k,_ as A,d as j,f as M,h as N,p as P,r as F,v as I,w as L,x as R}from"./vendor-ui-core-DUyKOLA8.js";import"./vendor-utils-xrsi4rSa.js";import{B as z,R as B,_t as ee,b as V,bt as H,c as U,ot as W,pt as G,st as K,ut as q}from"./index-Wx4BrrkZ.js";import{t as J}from"./async-R_IFRE5c.js";var Y=e(v(),1),X=e(y(),1);const Z=({profile:e,isEditingName:t,setIsEditingName:n,editName:r,setEditName:i,updateProfileName:a,exportProfile:s})=>{let{t:c}=l(),[u,d]=(0,Y.useState)(!1);return(0,X.jsxs)(`div`,{className:`mb-6 flex flex-col md:flex-row justify-between items-start md:items-center gap-4`,children:[(0,X.jsxs)(`div`,{className:`flex flex-col justify-start`,children:[t?(0,X.jsxs)(`div`,{className:`flex items-center gap-2 mb-1`,children:[(0,X.jsx)(I,{content:c(`common.profileNameFormatTip`,`Profile Name tip: 1-30 characters, duplicates not allowed`),isOpen:u,position:b.TOP,intent:k.PRIMARY,className:`flex-1`,children:(0,X.jsx)(`div`,{className:`w-full block`,children:(0,X.jsx)(M,{value:r,onChange:e=>i(e.target.value),onFocus:()=>d(!0),onBlur:()=>d(!1),autoFocus:!0,onKeyDown:t=>{t.key===`Enter`&&a(),t.key===`Escape`&&(n(!1),i(e?.name||``))}})})}),(0,X.jsx)(T,{icon:(0,X.jsx)(g,{size:16}),intent:k.SUCCESS,minimal:!0,onClick:a,disabled:!U.test(r)}),(0,X.jsx)(T,{icon:(0,X.jsx)(_,{size:16}),minimal:!0,onClick:()=>{n(!1),i(e?.name||``)}})]}):(0,X.jsxs)(`div`,{className:`group flex items-center gap-2 mb-1 cursor-pointer`,onClick:()=>n(!0),children:[(0,X.jsx)(`h2`,{className:`bp6-heading mb-0`,children:e?.name}),(0,X.jsx)(T,{icon:(0,X.jsx)(o,{size:14}),minimal:!0,className:`opacity-30 group-hover:opacity-100 transition-opacity`})]}),(0,X.jsx)(`p`,{className:`bp6-text-muted`,children:c(`settings.subtitle`)})]}),(0,X.jsx)(`div`,{className:`flex gap-2 items-center`,children:(0,X.jsx)(T,{size:`large`,icon:(0,X.jsx)(p,{size:18}),text:c(`settings.export`,`导出配置`),onClick:s})})]})},Q=()=>{let{t:e}=l(),[t,n]=(0,Y.useState)([]);return(0,Y.useEffect)(()=>{z().then(t=>{t&&Array.isArray(t)&&n(t.map(t=>({label:e(t.label),url:t.url})))}).catch(e=>console.warn(`Failed to fetch preset upstreams from API`,e))},[e]),t},te=(e,t)=>{let{t:n}=l();return(0,Y.useMemo)(()=>{let e=t>0?t:30,r=n(`settings.retentionMaxSuffix`,`(最长)`),i=[{label:n(`settings.retentionDisabled`,`关闭 (隐私需要)`),value:0},{label:n(`settings.retention10m`,`10 分钟`),value:.007},{label:n(`settings.retention1h`,`1 小时`),value:.0416},{label:n(`settings.retention24h`,`24 小时`),value:1},{label:n(`settings.retention7d`,`7 天`),value:7},{label:n(`settings.retention30d`,`30 天`),value:30},{label:n(`settings.retention90d`,`90 天`),value:90},{label:n(`settings.retention180d`,`180 天`),value:180},{label:n(`settings.retention360d`,`360 天`),value:360}],a=i.filter(t=>t.value<=e);return e>0&&!a.some(t=>t.value===e)&&(a.push({label:`${e} ${n(`settings.daysUnit`,`天`)}`,value:e}),a.sort((e,t)=>e.value-t.value)),a.length===0?[i[0]]:a.map(t=>t.value===e&&t.value>0?{...t,label:`${t.label} ${r}`}:t)},[n,t])},ne=({settings:e,setSettings:t})=>{let{t:n}=l(),r=(0,X.jsx)(S,{className:`min-w-96`,children:Q().map((n,r)=>(0,X.jsx)(L,{text:n.label,onClick:()=>t({...e,upstream:[n.url]}),labelElement:(0,X.jsx)(`div`,{className:`flex flex-col items-end text-right`,children:(0,X.jsx)(`span`,{className:`text-[9px] opacity-85 max-w-64 truncate`,title:n.url,children:n.url})})},r))});return(0,X.jsxs)(R,{elevation:C.ONE,className:`dark:bg-gray-900 dark:border-gray-800`,children:[(0,X.jsxs)(w,{className:`flex items-center gap-2 mb-4 font-bold`,children:[(0,X.jsx)(a,{size:18,className:`text-blue-500`}),` `,n(`settings.upstreamTitle`)]}),(0,X.jsx)(P,{label:`DoH (https://) / DoT (tls://) / DNS Stamp (sdns://) / ${n(`settings.classicDns`)}`,children:(0,X.jsx)(M,{fill:!0,placeholder:`https://... | tls://... | sdns://... | 1.1.1.1`,value:e.upstream?.[0]||``,onChange:n=>t({...e,upstream:[n.target.value]}),onFocus:e=>e.target.select(),rightElement:(0,X.jsx)(O,{content:r,placement:`bottom-end`,animation:`minimal`,arrow:!1,children:(0,X.jsx)(T,{variant:`minimal`,icon:`chevron-down`})})})}),(0,X.jsx)(`p`,{className:`text-xs opacity-60`,children:n(`settings.upstreamDesc`)})]})},re=({settings:e,setSettings:t})=>{let{t:r}=l();return(0,X.jsxs)(R,{elevation:C.ONE,className:`dark:bg-gray-900 dark:border-gray-800`,children:[(0,X.jsxs)(w,{className:`flex items-center gap-2 mb-4 font-bold`,children:[(0,X.jsx)(n,{size:18,className:`text-green-500`}),` `,r(`settings.defaultPolicyTitle`)]}),(0,X.jsxs)(`div`,{className:`space-y-4`,children:[(0,X.jsx)(P,{label:r(`settings.onNoMatch`),children:(0,X.jsxs)(j,{fill:!0,value:e.default_policy,onChange:n=>t({...e,default_policy:n.target.value}),children:[(0,X.jsx)(`option`,{value:`ALLOW`,children:r(`settings.allowAll`)}),(0,X.jsx)(`option`,{value:`BLOCK`,children:r(`settings.blockAll`)})]})}),(0,X.jsx)(A,{}),(0,X.jsx)(P,{label:r(`settings.blockModeTitle`),helperText:r(`settings.blockModeDesc`),children:(0,X.jsxs)(j,{fill:!0,value:e.block_mode||`NULL_IP`,onChange:n=>t({...e,block_mode:n.target.value}),children:[(0,X.jsxs)(`option`,{value:`NULL_IP`,children:[`0.0.0.0 / :: (`,r(`settings.default`),`)`]}),(0,X.jsxs)(`option`,{value:`NXDOMAIN`,children:[`NXDOMAIN (`,r(`settings.NXDOMAIN`),`)`]}),(0,X.jsxs)(`option`,{value:`NODATA`,children:[`NODATA (`,r(`settings.NODATA`),`)`]}),(0,X.jsx)(`option`,{value:`CUSTOM_IP`,children:r(`settings.customIP`)})]})}),e.block_mode===`CUSTOM_IP`&&(0,X.jsxs)(`div`,{className:`space-y-2 animate-in fade-in slide-in-from-top-1`,children:[(0,X.jsx)(M,{placeholder:`IPv4: 127.0.0.1`,value:e.custom_block_ipv4||``,onChange:n=>t({...e,custom_block_ipv4:n.target.value})}),(0,X.jsx)(M,{placeholder:`IPv6: ::1`,value:e.custom_block_ipv6||``,onChange:n=>t({...e,custom_block_ipv6:n.target.value})})]})]})]})},ie=({settings:e,setSettings:t,isAdmin:n,maxRetentionDays:r})=>{let{t:i}=l(),a=te(n,r);Y.useEffect(()=>{if(r>0&&e.log_retention_days>r&&a.length>0){let n=a[a.length-1];n&&e.log_retention_days!==n.value&&t({...e,log_retention_days:n.value})}},[r,e.log_retention_days,a,t]);let o=e.log_retention_days===0;return(0,X.jsxs)(R,{elevation:C.ONE,className:`dark:bg-gray-900 dark:border-gray-800`,children:[(0,X.jsxs)(w,{className:`flex items-center gap-2 mb-4 font-bold`,children:[(0,X.jsx)(u,{size:18,className:`text-purple-500`}),` `,i(`settings.logRetentionTitle`)]}),(0,X.jsxs)(`div`,{className:`space-y-4`,children:[(0,X.jsx)(P,{label:i(`settings.retentionDuration`),children:(0,X.jsx)(j,{fill:!0,value:e.log_retention_days,onChange:n=>t({...e,log_retention_days:parseFloat(n.target.value)}),children:a.map(e=>(0,X.jsx)(`option`,{value:e.value,children:e.label},e.value))})}),(0,X.jsx)(`p`,{className:`text-xs opacity-60`,children:o?i(`settings.retentionDisabledDesc`,`已关闭日志记录。系统将不会记录任何 DNS 查询日志并立即清空历史日志。`):i(`settings.retentionDesc`)}),(0,X.jsxs)(`div`,{className:`pt-3 border-t border-gray-100 dark:border-gray-800/80`,children:[(0,X.jsx)(N,{label:i(`settings.skipLogOnPass`,`不记录放行记录`),checked:!o&&!!e.skip_log_on_pass,disabled:o,onChange:n=>t({...e,skip_log_on_pass:n.currentTarget.checked})}),(0,X.jsx)(`p`,{className:`text-xs opacity-60 mt-1`,children:i(`settings.skipLogOnPassDesc`,`启用后不记录正常放行的 DNS 查询,仅记录被拦截、重定向或解析失败的记录。可大幅减少存储占用与写操作。`)})]})]})]})},ae=({profileId:e,toasterRef:n})=>{let{t:r}=l(),[i,a]=(0,Y.useState)(()=>V.getLocalRetentionDays()),[o,s]=(0,Y.useState)(!1),[u,d]=(0,Y.useState)(null),[f,p]=(0,Y.useState)(!1),[h,g]=(0,Y.useState)(!1),_=(0,Y.useCallback)(async()=>{try{await V.init();let t=await V.getStorageInfo();s(t?.isOpfs??V.getIsOpfs());let n=t.profileStats.find(t=>t.profile_id===e);d(n?n.count:0)}catch(e){console.error(`[LocalRetentionCard] Failed to load storage info:`,e),s(V.getIsOpfs()),d(0)}},[e]);(0,Y.useEffect)(()=>{_()},[_]);let v=e=>{a(e),V.setLocalRetentionDays(e),_()};return(0,X.jsxs)(R,{elevation:C.ONE,className:`dark:bg-gray-900 dark:border-gray-800`,children:[(0,X.jsxs)(w,{className:`flex items-center gap-2 mb-4 font-bold`,children:[(0,X.jsx)(c,{size:18,className:`text-cyan-500`}),` `,r(`settings.localRetentionTitle`,`本地存储与留存`)]}),(0,X.jsxs)(`div`,{className:`space-y-4`,children:[(0,X.jsx)(P,{label:r(`settings.localRetentionDuration`,`本地保留时长`),children:(0,X.jsxs)(j,{fill:!0,value:i,onChange:e=>v(parseInt(e.target.value,10)),children:[(0,X.jsx)(`option`,{value:30,children:r(`settings.localRetention30d`,`30 天`)}),(0,X.jsx)(`option`,{value:90,children:r(`settings.localRetention90d`,`90 天 (推荐)`)}),(0,X.jsx)(`option`,{value:180,children:r(`settings.localRetention180d`,`180 天`)}),(0,X.jsx)(`option`,{value:365,children:r(`settings.localRetention365d`,`365 天 (1 年)`)}),(0,X.jsx)(`option`,{value:0,children:r(`settings.localRetentionUnlimited`,`永久保留 (直到手动清除)`)})]})}),(0,X.jsx)(`p`,{className:`text-xs opacity-60`,children:r(`settings.localRetentionDesc`,`日志将持久化保存在当前浏览器本地的 SQLite 数据库 (OPFS) 中,提供秒级本地搜索并节省云端存储费用。超出此时长的本地日志将自动清除。`)}),(0,X.jsxs)(`div`,{className:`pt-3 border-t border-gray-100 dark:border-gray-800/80 space-y-3`,children:[(0,X.jsxs)(`div`,{className:`flex items-center justify-between text-xs`,children:[(0,X.jsxs)(`span`,{className:`flex items-center gap-1.5 opacity-70`,children:[(0,X.jsx)(m,{size:14}),r(`settings.localEngineStorage`,`存储引擎`),`:`]}),(0,X.jsx)(F,{minimal:!0,intent:o?k.SUCCESS:k.WARNING,className:`text-[11px]`,children:o?r(`settings.localEngineOpfs`,`OPFS 本地持久化`):r(`settings.localEngineMemory`,`内存临时存储 (无痕/私密模式)`)})]}),(0,X.jsxs)(`div`,{className:`flex items-center justify-between text-xs`,children:[(0,X.jsxs)(`span`,{className:`opacity-70`,children:[r(`settings.localCachedCount`,`本地已缓存日志`),`:`]}),(0,X.jsx)(`span`,{className:`font-mono font-medium`,children:u===null?`...`:r(`settings.localCachedCountUnit`,`{{count}} 条记录`,{count:u})})]}),(0,X.jsx)(`div`,{className:`pt-1 flex justify-end`,children:(0,X.jsx)(T,{minimal:!0,small:!0,intent:k.DANGER,icon:(0,X.jsx)(t,{size:13}),text:r(`settings.clearLocalData`,`清空本地日志`),disabled:u===0||u===null||h,onClick:()=>p(!0)})})]})]}),(0,X.jsx)(x,{isOpen:f,confirmButtonText:r(`common.confirm`,`确认清空`),cancelButtonText:r(`common.cancel`,`取消`),intent:k.DANGER,icon:`trash`,onConfirm:async()=>{g(!0);try{await V.clearProfile(e),d(0),n?.current?.show({message:r(`settings.clearLocalDataSuccess`,`本地日志已成功清空`),intent:k.SUCCESS,icon:`tick`})}catch(e){console.error(`[LocalRetentionCard] Failed to clear local profile logs:`,e),n?.current?.show({message:r(`settings.clearLocalDataError`,`清空本地日志失败`),intent:k.DANGER,icon:`error`})}finally{g(!1),p(!1)}},onCancel:()=>p(!1),loading:h,children:(0,X.jsx)(`p`,{children:r(`settings.clearLocalDataConfirm`,`确定要清空此配置在本地保存的所有日志吗?(云端日志不受影响)`)})})]})},oe=({settings:e,setSettings:t})=>{let{t:n}=l();return(0,X.jsxs)(R,{elevation:C.ONE,className:`dark:bg-gray-900 dark:border-gray-800`,children:[(0,X.jsxs)(w,{className:`flex items-center gap-2 mb-3 font-bold`,children:[(0,X.jsx)(d,{size:18,className:`text-orange-500`}),` `,n(`settings.ecsTitle`)]}),(0,X.jsxs)(`div`,{className:`space-y-4`,children:[(0,X.jsx)(N,{label:n(`settings.sendEcs`),checked:e.ecs.enabled,onChange:n=>t({...e,ecs:{...e.ecs,enabled:n.currentTarget.checked}})}),(0,X.jsx)(N,{label:n(`settings.customSubnet`),disabled:!e.ecs.enabled,checked:!e.ecs.use_client_ip,onChange:n=>t({...e,ecs:{...e.ecs,use_client_ip:!n.currentTarget.checked}})}),(0,X.jsxs)(`div`,{className:`space-y-3 pt-2 border-t border-gray-100 dark:border-gray-800`,children:[(0,X.jsx)(P,{label:n(`settings.customIpv4`),labelInfo:n(`settings.ipv4Hint`),disabled:!(e.ecs.enabled&&!e.ecs.use_client_ip),children:(0,X.jsx)(M,{placeholder:`0.0.0.0/0`,value:e.ecs.ipv4_cidr||``,disabled:!(e.ecs.enabled&&!e.ecs.use_client_ip),onChange:n=>t({...e,ecs:{...e.ecs,ipv4_cidr:n.target.value}})})}),(0,X.jsx)(P,{label:n(`settings.customIpv6`),labelInfo:n(`settings.ipv6Hint`),disabled:!(e.ecs.enabled&&!e.ecs.use_client_ip),children:(0,X.jsx)(M,{placeholder:`::/0`,value:e.ecs.ipv6_cidr||``,disabled:!(e.ecs.enabled&&!e.ecs.use_client_ip),onChange:n=>t({...e,ecs:{...e.ecs,ipv6_cidr:n.target.value}})})})]}),(0,X.jsx)(`p`,{className:`text-xs opacity-60`,children:n(`settings.ecsUpstreamHint`)})]})]})};var $=[{domain:`cloudflare-ech.com`,isPreferred:!0},{domain:`crypto.cloudflare.com`,isPreferred:!1},{domain:`one.one.one.one`,isPreferred:!1},{domain:`www.cloudflare.com`,isPreferred:!1},{domain:`encryptedsni.com`,isPreferred:!1},{domain:`cdnjs.com`,isPreferred:!1}];const se=({settings:e,setSettings:t})=>{let{t:n}=l(),[r,i]=Y.useState($);Y.useEffect(()=>{B().then(e=>{Array.isArray(e)&&e.length>0&&i(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 a=typeof e.best_effort_ech==`boolean`?e.best_effort_ech:!!e.best_effort_ech?.enabled,o=typeof e.best_effort_ech==`object`&&e.best_effort_ech?.fronting_domain?e.best_effort_ech.fronting_domain:`cloudflare-ech.com`,c=n=>{t({...e,best_effort_ech:{enabled:n,fronting_domain:o||`cloudflare-ech.com`}})},u=n=>{t({...e,best_effort_ech:{enabled:a,fronting_domain:n}})},d=(0,X.jsx)(S,{className:`min-w-72`,children:r.map(e=>(0,X.jsx)(L,{text:e.domain,onClick:()=>u(e.domain),labelElement:e.isPreferred?(0,X.jsx)(F,{minimal:!0,intent:k.PRIMARY,className:`text-[10px]`,children:n(`settings.echPreferred`,`首选`)}):void 0},e.domain))});return(0,X.jsxs)(R,{elevation:C.ONE,className:`dark:bg-gray-900 dark:border-gray-800`,children:[(0,X.jsxs)(`div`,{className:`flex items-center justify-between mb-3`,children:[(0,X.jsxs)(w,{className:`flex items-center gap-2 m-0 font-bold text-purple-600 dark:text-purple-400`,children:[(0,X.jsx)(s,{size:18}),` `,n(`settings.echTitle`)]}),(0,X.jsx)(O,{placement:`bottom-end`,usePortal:!0,content:(0,X.jsxs)(`div`,{className:`p-4 max-w-sm`,children:[(0,X.jsx)(w,{children:n(`settings.whatIsEch`,`何为 ECH (Encrypted Client Hello)?`)}),(0,X.jsx)(`p`,{className:`text-sm mb-2`,children:n(`settings.echHelpDesc`)}),(0,X.jsxs)(`ul`,{className:`list-disc list-inside text-sm opacity-80 mb-3 space-y-1`,children:[(0,X.jsx)(`li`,{children:n(`settings.echHelpBenefit1`)}),(0,X.jsx)(`li`,{children:n(`settings.echHelpBenefit2`)})]}),(0,X.jsx)(`div`,{className:`text-xs border-t border-gray-100 dark:border-gray-700 pt-2`,children:(0,X.jsxs)(`a`,{href:`https://en.wikipedia.org/wiki/Encrypted_Client_Hello`,target:`_blank`,rel:`noreferrer`,className:`flex items-center gap-1 text-blue-500 hover:underline`,children:[(0,X.jsx)(f,{size:10}),` `,n(`setup.learnMore`,`了解更多`)]})})]}),children:(0,X.jsx)(T,{icon:`help`,variant:`minimal`,intent:k.NONE})})]}),(0,X.jsxs)(`div`,{className:`space-y-4`,children:[(0,X.jsx)(N,{label:n(`settings.enableEch`,`启用重写 ECH`),checked:a,onChange:e=>c(e.currentTarget.checked)}),(0,X.jsx)(`p`,{className:`text-xs opacity-60 leading-relaxed`,children:n(`settings.echDesc`,`针对由 Cloudflare 代理的域名,当查询 HTTPS (Type 65) 或 SVCB (Type 64) 记录且上游未配置 ECH 时,自动重写注入 ECH 参数以保护 SNI 隐私。`)}),a&&(0,X.jsx)(`div`,{className:`space-y-3 pt-3 border-t border-gray-100 dark:border-gray-800`,children:(0,X.jsx)(P,{label:n(`settings.echFrontingTitle`,`表层 SNI (ECH Fronting)`),labelInfo:(0,X.jsx)(`span`,{className:`text-xs opacity-60`,children:n(`settings.echFrontingDesc`,`TLS 握手外层可见的伪装域名`)}),children:(0,X.jsx)(M,{fill:!0,placeholder:n(`settings.echFrontingCustomPlaceholder`,`输入自定义表层域名,例如 crypto.cloudflare.com`),value:o,onChange:e=>u(e.target.value),onFocus:e=>e.target.select(),className:`font-mono text-sm`,rightElement:(0,X.jsx)(O,{content:d,placement:`bottom-end`,animation:`minimal`,arrow:!1,children:(0,X.jsx)(T,{variant:`minimal`,icon:`chevron-down`})})})})})]})]})},ce=({testInput:e,setTestInput:t,handleDnsTest:n,testing:a,testResult:o})=>{let{t:s}=l();return(0,X.jsxs)(R,{elevation:C.TWO,className:`dark:bg-gray-900 border-t-2 border-blue-500`,children:[(0,X.jsxs)(w,{className:`flex items-center gap-2 mb-6 font-bold`,children:[(0,X.jsx)(h,{size:20,className:`text-yellow-500 fill-yellow-500`}),` `,s(`settings.testToolTitle`)]}),(0,X.jsxs)(`div`,{className:`flex flex-col space-y-6`,children:[(0,X.jsx)(P,{label:s(`settings.testDomain`),className:`mb-0`,children:(0,X.jsx)(M,{fill:!0,large:!0,placeholder:s(`settings.domainPlaceholder`),value:e.domain,onChange:n=>t({...e,domain:n.target.value}),onKeyDown:e=>e.key===`Enter`&&n()})}),(0,X.jsxs)(`div`,{className:`flex justify-end gap-4 items-end`,children:[(0,X.jsx)(P,{label:s(`settings.recordType`),className:`w-32 mb-0`,children:(0,X.jsxs)(j,{fill:!0,large:!0,value:e.type,onChange:n=>t({...e,type:n.target.value}),children:[(0,X.jsx)(`option`,{value:`A`,children:`A`}),(0,X.jsx)(`option`,{value:`AAAA`,children:`AAAA`}),(0,X.jsx)(`option`,{value:`CNAME`,children:`CNAME`}),(0,X.jsx)(`option`,{value:`TXT`,children:`TXT`})]})}),(0,X.jsx)(P,{label:`\xA0`,className:`mb-0`,children:(0,X.jsx)(T,{size:`large`,intent:k.PRIMARY,icon:`search`,text:s(`settings.runTest`),onClick:n,loading:a})})]}),o&&(0,X.jsxs)(`div`,{className:`bg-gray-50 dark:bg-gray-800/50 p-6 rounded-xl border border-gray-100 dark:border-gray-800 space-y-6 animate-in fade-in slide-in-from-top-4`,children:[(0,X.jsxs)(`div`,{className:`flex flex-wrap gap-4 items-center`,children:[(0,X.jsx)(F,{large:!0,round:!0,intent:o.action===`PASS`?k.SUCCESS:o.action===`BLOCK`?k.DANGER:k.WARNING,className:`px-4 font-bold`,children:o.action}),(0,X.jsxs)(`div`,{className:`flex flex-col`,children:[(0,X.jsx)(`span`,{className:`text-[10px] uppercase font-bold opacity-40`,children:s(`settings.hitRule`)}),(0,X.jsx)(`span`,{className:`text-sm font-bold`,children:o.reason||s(`settings.defaultAllow`)})]}),(0,X.jsxs)(`div`,{className:`flex flex-col border-l border-gray-200 dark:border-gray-700 pl-4`,children:[(0,X.jsx)(`span`,{className:`text-[10px] uppercase font-bold opacity-40`,children:s(`settings.parseLatency`)}),(0,X.jsx)(`span`,{className:`text-sm font-mono font-bold`,children:o.latency?`${o.latency}ms`:`-`})]}),o.timings&&(0,X.jsx)(`div`,{className:`flex flex-wrap gap-x-4 gap-y-1 border-l border-gray-200 dark:border-gray-700 pl-4 max-w-md`,children:Object.entries(o.timings).map(([e,t])=>(0,X.jsxs)(`div`,{className:`flex gap-1 items-baseline`,children:[(0,X.jsxs)(`span`,{className:`text-[9px] opacity-40 uppercase font-mono`,children:[e,`:`]}),(0,X.jsxs)(`span`,{className:`text-[10px] font-mono font-bold`,children:[t,`ms`]})]},e))}),(0,X.jsx)(A,{}),(0,X.jsxs)(`div`,{className:`flex items-center gap-2 bg-white dark:bg-gray-900 px-3 py-1.5 rounded-lg shadow-sm border border-gray-100 dark:border-gray-800`,children:[(0,X.jsx)(r,{size:14,className:`text-red-500`}),(0,X.jsxs)(`div`,{className:`flex flex-col`,children:[(0,X.jsx)(`span`,{className:`text-[10px] uppercase font-bold opacity-40 leading-none`,children:s(`settings.sourceIp`)}),(0,X.jsxs)(`span`,{className:`text-xs font-mono`,children:[o.client_ip,` (`,o.geo_country,`)`]})]})]})]}),(0,X.jsxs)(`div`,{className:`space-y-3`,children:[(0,X.jsxs)(`div`,{className:`text-[10px] uppercase font-bold opacity-40 flex items-center gap-1`,children:[(0,X.jsx)(i,{size:10}),` `,s(`settings.answerSection`)]}),(0,X.jsx)(`div`,{className:`font-mono text-sm leading-relaxed bg-white dark:bg-gray-900 p-4 rounded-xl border border-gray-100 dark:border-gray-800 shadow-inner`,children:o.answers&&o.answers.length>0?o.answers.map((e,t)=>(0,X.jsxs)(`div`,{className:`flex gap-4 py-1 border-b border-gray-50 dark:border-gray-800 last:border-0 hover:bg-blue-50/50 dark:hover:bg-blue-900/10 transition-colors px-2`,children:[(0,X.jsx)(`span`,{className:`w-16 font-bold text-blue-500`,children:e.type}),(0,X.jsx)(`span`,{className:`flex-1 dark:text-gray-300`,children:e.data}),(0,X.jsxs)(`span`,{className:`text-[10px] opacity-30 italic`,children:[`TTL: `,e.ttl,`s`]})]},t)):(0,X.jsx)(`div`,{className:`p-4 opacity-40 italic text-center`,children:s(`settings.noRecordsReturned`)})})]}),o.diagnostics&&(0,X.jsx)(D,{minimal:!0,intent:o.action===`FAIL`?k.DANGER:k.NONE,className:`text-xs font-mono`,children:(0,X.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,X.jsxs)(`div`,{className:`flex justify-between items-center`,children:[(0,X.jsx)(`span`,{className:`font-bold uppercase tracking-wider`,children:s(`settings.diagnostics`)}),(0,X.jsx)(`span`,{className:`font-bold`,children:o.action===`FAIL`?o.diagnostics.status>0?`HTTP ${o.diagnostics.status}${o.diagnostics.status_text?` (${o.diagnostics.status_text})`:``}`:`Network / Connection Error`:o.diagnostics.method===`POST`||o.diagnostics.method===`GET`?`HTTP ${o.diagnostics.status}${o.diagnostics.status_text?` (${o.diagnostics.status_text})`:``}`:`Connected (OK)`})]}),(0,X.jsxs)(`div`,{className:`flex items-center gap-2 text-xs opacity-80`,children:[(0,X.jsx)(`span`,{className:`px-1.5 py-0.5 bg-gray-200 dark:bg-gray-700 rounded text-[10px] font-bold`,children:o.diagnostics.method}),(0,X.jsx)(`span`,{className:`break-all`,children:o.diagnostics.upstream_url})]}),o.diagnostics.cf_ray&&(0,X.jsxs)(`div`,{className:`text-[11px] opacity-75`,children:[`CF-Ray: `,(0,X.jsx)(`span`,{className:`font-bold`,children:o.diagnostics.cf_ray})]}),o.diagnostics.error_detail&&o.action===`FAIL`&&(0,X.jsxs)(`div`,{className:`p-2 bg-red-50 dark:bg-red-950/40 rounded border border-red-200 dark:border-red-900/50 text-red-700 dark:text-red-300 break-words`,children:[(0,X.jsxs)(`div`,{className:`font-bold mb-0.5`,children:[s(`settings.errorDetail`),`:`]}),(0,X.jsx)(`div`,{children:o.diagnostics.error_detail})]}),o.diagnostics.response_body&&(0,X.jsxs)(`div`,{className:`p-2 bg-gray-100 dark:bg-gray-900 rounded border border-gray-200 dark:border-gray-700 text-gray-700 dark:text-gray-300 break-words text-[11px]`,children:[(0,X.jsxs)(`div`,{className:`font-bold mb-0.5 opacity-60`,children:[s(`settings.upstreamResponse`),`:`]}),(0,X.jsx)(`div`,{className:`line-clamp-3`,children:o.diagnostics.response_body})]})]})})]})]})]})},le=({profileId:e,toasterRef:t,currentUser:n,onSavingChange:r})=>{let[i,a]=(0,Y.useState)(null),[o,s]=(0,Y.useState)(null),[c,u]=(0,Y.useState)(!0),[d,f]=(0,Y.useState)(!1),{t:p}=l();(0,Y.useEffect)(()=>(r?.(d),()=>{r?.(!1)}),[d,r]);let m=(0,Y.useRef)(!0),h=(0,Y.useRef)(null),g=(0,Y.useRef)(null),_=(0,Y.useRef)(0),v=e=>typeof structuredClone==`function`?structuredClone(e):JSON.parse(JSON.stringify(e)),[y,b]=(0,Y.useState)(!1),[x,S]=(0,Y.useState)(``),[C,w]=(0,Y.useState)({domain:`o-o.myaddr.l.google.com`,type:`TXT`}),[T,D]=(0,Y.useState)(null),[O,A]=(0,Y.useState)(!1);(0,Y.useEffect)(()=>{m.current=!0,h.current&&=(clearTimeout(h.current),null),(async()=>{u(!0);try{let t=await W(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{u(!1)}})()},[e]),(0,Y.useEffect)(()=>{if(!c&&o&&m.current){let e=setTimeout(()=>{m.current=!1,o&&(g.current=v(o))},500);return()=>clearTimeout(e)}},[c,o]),(0,Y.useEffect)(()=>()=>{h.current&&clearTimeout(h.current)},[]);let j=async()=>{if(!x||x===i?.name){b(!1);return}let n=i?.name||``;f(!0);try{await J(G(e,x),1e4),a(e=>e?{...e,name:x}:null),b(!1),t?.current?.show({message:p(`common.saveSuccess`,`保存成功`),intent:k.SUCCESS,icon:`tick`})}catch(e){console.error(e),S(n),b(!1);let r=e.message,i=r;r===`The profile name already exists`?i=p(`common.profileNameExists`,`The profile name already exists`):r===`Invalid Profile Name format`&&(i=p(`common.profileNameFormatError`,`Invalid Profile Name format`)),t?.current?.show({message:i||p(`common.saveFailed`,`保存失败`),intent:k.DANGER,icon:`error`})}finally{f(!1)}},M=(0,Y.useCallback)(async n=>{if(!n)return;let r=++_.current;f(!0);try{await J(H(e,n),1e4),r===_.current&&(g.current=v(n),t?.current?.show({message:p(`common.saveSuccess`,`保存成功`),intent:k.SUCCESS,icon:`tick`}))}catch(e){console.error(e),r===_.current&&(h.current&&=(clearTimeout(h.current),null),g.current&&s(v(g.current)),t?.current?.show({message:p(`common.saveFailed`,`保存失败`),intent:k.DANGER,icon:`error`}))}finally{r===_.current&&f(!1)}},[e,t,p]),N=(0,Y.useCallback)(e=>{h.current&&clearTimeout(h.current),h.current=setTimeout(()=>{M(e)},600)},[M]),P=(0,Y.useCallback)(e=>{s(e),m.current||N(e)},[N]);return c||!o?(0,X.jsx)(`div`,{className:`p-20 flex justify-center`,children:(0,X.jsx)(E,{})}):(0,X.jsxs)(`div`,{className:`p-0 sm:px-4 lg:px-8 max-w-5xl mx-auto space-y-8 pb-20`,children:[(0,X.jsx)(Z,{profile:i,isEditingName:y,setIsEditingName:b,editName:x,setEditName:S,updateProfileName:j,exportProfile:async()=>{if(!(!i||!o))try{let[n,r]=await Promise.all([q(e).catch(()=>[]),K(e).catch(()=>[])]),a=new Set,s=(n||[]).filter(e=>{let t=(e.pattern||``).trim().toLowerCase();return!t||a.has(t)?!1:(a.add(t),!0)}),c=new Set,l=(r||[]).filter(e=>{let t=(e.url||``).trim().toLowerCase();return!t||c.has(t)?!1:(c.add(t),!0)}).map(e=>({url:e.url,enabled:!!e.enabled})),u={version:2,name:i.name,settings:o,rules:s,filters:l,exported_at:Math.floor(Date.now()/1e3)},d=new Blob([JSON.stringify(u,null,2)],{type:`application/json`}),f=URL.createObjectURL(d),m=document.createElement(`a`);m.href=f,m.download=`dns-worker-${i.name||e}.json`,document.body.appendChild(m),m.click(),document.body.removeChild(m),URL.revokeObjectURL(f),t?.current?.show({message:p(`settings.exportSuccess`,`配置成功导出`),intent:k.SUCCESS,icon:`download`})}catch(e){console.error(e),t?.current?.show({message:p(`settings.exportError`,`导出失败`),intent:k.DANGER,icon:`error`})}}}),(0,X.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-6`,children:[(0,X.jsx)(ne,{settings:o,setSettings:P}),(0,X.jsx)(re,{settings:o,setSettings:P}),(0,X.jsx)(ie,{settings:o,setSettings:P,isAdmin:n?.role===`admin`,maxRetentionDays:n?.max_log_retention_days??(n?.role===`admin`?30:7)}),(0,X.jsx)(ae,{profileId:e,toasterRef:t}),(0,X.jsx)(oe,{settings:o,setSettings:P}),(0,X.jsx)(se,{settings:o,setSettings:P})]}),(0,X.jsx)(ce,{testInput:C,setTestInput:w,handleDnsTest:async()=>{if(C.domain){A(!0),D(null);try{D(await ee(e,C))}catch(e){console.error(e)}finally{A(!1)}}},testing:O,testResult:T})]})};export{le as SettingsView};
1
+ import{i as e}from"./rolldown-runtime-C4Xdq4VV.js";import{C as t,D as n,J as r,Ot as i,P as a,V as o,Z as s,ct as c,en as l,ft as u,nt as d,ot as f,st as p,tt as m,v as h,vt as g,y as _}from"./vendor-react-BtC4HVVO.js";import{S as v,b as y}from"./vendor-icons-other-BTYC6Wvz.js";import"./vendor-i18next-BC3ewzY3.js";import{B as b,D as x,E as S,H as C,M as w,N as T,P as ee,S as E,T as D,V as O,_ as k,d as A,f as j,h as M,p as N,r as P,v as F,w as I,x as L}from"./vendor-ui-core-DUyKOLA8.js";import"./vendor-utils-xrsi4rSa.js";import{B as R,R as z,b as B,c as V,ot as H,pt as U,st as W,ut as G,vt as K,xt as q}from"./index-9kbjmMJz.js";import{t as J}from"./async-R_IFRE5c.js";var Y=e(v(),1),X=e(y(),1);const Z=({profile:e,isEditingName:t,setIsEditingName:n,editName:r,setEditName:i,updateProfileName:a,exportProfile:s})=>{let{t:c}=l(),[u,d]=(0,Y.useState)(!1);return(0,X.jsxs)(`div`,{className:`mb-6 flex flex-col md:flex-row justify-between items-start md:items-center gap-4`,children:[(0,X.jsxs)(`div`,{className:`flex flex-col justify-start`,children:[t?(0,X.jsxs)(`div`,{className:`flex items-center gap-2 mb-1`,children:[(0,X.jsx)(F,{content:c(`common.profileNameFormatTip`,`Profile Name tip: 1-30 characters, duplicates not allowed`),isOpen:u,position:b.TOP,intent:O.PRIMARY,className:`flex-1`,children:(0,X.jsx)(`div`,{className:`w-full block`,children:(0,X.jsx)(j,{value:r,onChange:e=>i(e.target.value),onFocus:()=>d(!0),onBlur:()=>d(!1),autoFocus:!0,onKeyDown:t=>{t.key===`Enter`&&a(),t.key===`Escape`&&(n(!1),i(e?.name||``))}})})}),(0,X.jsx)(T,{icon:(0,X.jsx)(g,{size:16}),intent:O.SUCCESS,minimal:!0,onClick:a,disabled:!V.test(r)}),(0,X.jsx)(T,{icon:(0,X.jsx)(_,{size:16}),minimal:!0,onClick:()=>{n(!1),i(e?.name||``)}})]}):(0,X.jsxs)(`div`,{className:`group flex items-center gap-2 mb-1 cursor-pointer`,onClick:()=>n(!0),children:[(0,X.jsx)(`h2`,{className:`bp6-heading mb-0`,children:e?.name}),(0,X.jsx)(T,{icon:(0,X.jsx)(o,{size:14}),minimal:!0,className:`opacity-30 group-hover:opacity-100 transition-opacity`})]}),(0,X.jsx)(`p`,{className:`bp6-text-muted`,children:c(`settings.subtitle`)})]}),(0,X.jsx)(`div`,{className:`flex gap-2 items-center`,children:(0,X.jsx)(T,{size:`large`,icon:(0,X.jsx)(p,{size:18}),text:c(`settings.export`,`导出配置`),onClick:s})})]})},Q=()=>{let{t:e}=l(),[t,n]=(0,Y.useState)([]);return(0,Y.useEffect)(()=>{R().then(t=>{t&&Array.isArray(t)&&n(t.map(t=>({label:e(t.label),url:t.url})))}).catch(e=>console.warn(`Failed to fetch preset upstreams from API`,e))},[e]),t},te=(e,t)=>{let{t:n}=l();return(0,Y.useMemo)(()=>{let e=t>0?t:30,r=n(`settings.retentionMaxSuffix`,`(最长)`),i=[{label:n(`settings.retentionDisabled`,`关闭 (隐私需要)`),value:0},{label:n(`settings.retention10m`,`10 分钟`),value:.007},{label:n(`settings.retention1h`,`1 小时`),value:.0416},{label:n(`settings.retention24h`,`24 小时`),value:1},{label:n(`settings.retention7d`,`7 天`),value:7},{label:n(`settings.retention30d`,`30 天`),value:30},{label:n(`settings.retention90d`,`90 天`),value:90},{label:n(`settings.retention180d`,`180 天`),value:180},{label:n(`settings.retention360d`,`360 天`),value:360}],a=i.filter(t=>t.value<=e);return e>0&&!a.some(t=>t.value===e)&&(a.push({label:`${e} ${n(`settings.daysUnit`,`天`)}`,value:e}),a.sort((e,t)=>e.value-t.value)),a.length===0?[i[0]]:a.map(t=>t.value===e&&t.value>0?{...t,label:`${t.label} ${r}`}:t)},[n,t])},ne=({settings:e,setSettings:t})=>{let{t:n}=l(),r=(0,X.jsx)(S,{className:`min-w-96`,children:Q().map((n,r)=>(0,X.jsx)(I,{text:n.label,onClick:()=>t({...e,upstream:[n.url]}),labelElement:(0,X.jsx)(`div`,{className:`flex flex-col items-end text-right`,children:(0,X.jsx)(`span`,{className:`text-[9px] opacity-85 max-w-64 truncate`,title:n.url,children:n.url})})},r))});return(0,X.jsxs)(L,{elevation:C.ONE,className:`dark:bg-gray-900 dark:border-gray-800`,children:[(0,X.jsxs)(w,{className:`flex items-center gap-2 mb-4 font-bold`,children:[(0,X.jsx)(a,{size:18,className:`text-blue-500`}),` `,n(`settings.upstreamTitle`)]}),(0,X.jsx)(N,{label:`DoH (https://) / DoT (tls://) / DNS Stamp (sdns://) / ${n(`settings.classicDns`)}`,children:(0,X.jsx)(j,{fill:!0,placeholder:`https://... | tls://... | sdns://... | 1.1.1.1`,value:e.upstream?.[0]||``,onChange:n=>t({...e,upstream:[n.target.value]}),onFocus:e=>e.target.select(),rightElement:(0,X.jsx)(D,{content:r,placement:`bottom-end`,animation:`minimal`,arrow:!1,children:(0,X.jsx)(T,{variant:`minimal`,icon:`chevron-down`})})})}),(0,X.jsx)(`p`,{className:`text-xs opacity-60`,children:n(`settings.upstreamDesc`)})]})},re=({settings:e,setSettings:t})=>{let{t:r}=l();return(0,X.jsxs)(L,{elevation:C.ONE,className:`dark:bg-gray-900 dark:border-gray-800`,children:[(0,X.jsxs)(w,{className:`flex items-center gap-2 mb-4 font-bold`,children:[(0,X.jsx)(n,{size:18,className:`text-green-500`}),` `,r(`settings.defaultPolicyTitle`)]}),(0,X.jsxs)(`div`,{className:`space-y-4`,children:[(0,X.jsx)(N,{label:r(`settings.onNoMatch`),children:(0,X.jsxs)(A,{fill:!0,value:e.default_policy,onChange:n=>t({...e,default_policy:n.target.value}),children:[(0,X.jsx)(`option`,{value:`ALLOW`,children:r(`settings.allowAll`)}),(0,X.jsx)(`option`,{value:`BLOCK`,children:r(`settings.blockAll`)})]})}),(0,X.jsx)(k,{}),(0,X.jsx)(N,{label:r(`settings.blockModeTitle`),helperText:r(`settings.blockModeDesc`),children:(0,X.jsxs)(A,{fill:!0,value:e.block_mode||`NULL_IP`,onChange:n=>t({...e,block_mode:n.target.value}),children:[(0,X.jsxs)(`option`,{value:`NULL_IP`,children:[`0.0.0.0 / :: (`,r(`settings.default`),`)`]}),(0,X.jsxs)(`option`,{value:`NXDOMAIN`,children:[`NXDOMAIN (`,r(`settings.NXDOMAIN`),`)`]}),(0,X.jsxs)(`option`,{value:`NODATA`,children:[`NODATA (`,r(`settings.NODATA`),`)`]}),(0,X.jsx)(`option`,{value:`CUSTOM_IP`,children:r(`settings.customIP`)})]})}),e.block_mode===`CUSTOM_IP`&&(0,X.jsxs)(`div`,{className:`space-y-2 animate-in fade-in slide-in-from-top-1`,children:[(0,X.jsx)(j,{placeholder:`IPv4: 127.0.0.1`,value:e.custom_block_ipv4||``,onChange:n=>t({...e,custom_block_ipv4:n.target.value})}),(0,X.jsx)(j,{placeholder:`IPv6: ::1`,value:e.custom_block_ipv6||``,onChange:n=>t({...e,custom_block_ipv6:n.target.value})})]})]})]})},ie=({settings:e,setSettings:t,isAdmin:n,maxRetentionDays:r})=>{let{t:i}=l(),a=te(n,r);Y.useEffect(()=>{if(r>0&&e.log_retention_days>r&&a.length>0){let n=a[a.length-1];n&&e.log_retention_days!==n.value&&t({...e,log_retention_days:n.value})}},[r,e.log_retention_days,a,t]);let o=e.log_retention_days===0;return(0,X.jsxs)(L,{elevation:C.ONE,className:`dark:bg-gray-900 dark:border-gray-800`,children:[(0,X.jsxs)(w,{className:`flex items-center gap-2 mb-4 font-bold`,children:[(0,X.jsx)(u,{size:18,className:`text-purple-500`}),` `,i(`settings.logRetentionTitle`)]}),(0,X.jsxs)(`div`,{className:`space-y-4`,children:[(0,X.jsx)(N,{label:i(`settings.retentionDuration`),children:(0,X.jsx)(A,{fill:!0,value:e.log_retention_days,onChange:n=>t({...e,log_retention_days:parseFloat(n.target.value)}),children:a.map(e=>(0,X.jsx)(`option`,{value:e.value,children:e.label},e.value))})}),(0,X.jsx)(`p`,{className:`text-xs opacity-60`,children:o?i(`settings.retentionDisabledDesc`,`已关闭日志记录。系统将不会记录任何 DNS 查询日志并立即清空历史日志。`):i(`settings.retentionDesc`)}),(0,X.jsxs)(`div`,{className:`pt-3 border-t border-gray-100 dark:border-gray-800/80`,children:[(0,X.jsx)(M,{label:i(`settings.skipLogOnPass`,`不记录放行记录`),checked:!o&&!!e.skip_log_on_pass,disabled:o,onChange:n=>t({...e,skip_log_on_pass:n.currentTarget.checked})}),(0,X.jsx)(`p`,{className:`text-xs opacity-60 mt-1`,children:i(`settings.skipLogOnPassDesc`,`启用后不记录正常放行的 DNS 查询,仅记录被拦截、重定向或解析失败的记录。可大幅减少存储占用与写操作。`)})]})]})]})},ae=({profileId:e,toasterRef:n})=>{let{t:r}=l(),[i,a]=(0,Y.useState)(()=>B.getLocalRetentionDays()),[o,s]=(0,Y.useState)(!1),[u,d]=(0,Y.useState)(null),[f,p]=(0,Y.useState)(!1),[h,g]=(0,Y.useState)(!1),_=(0,Y.useCallback)(async()=>{try{await B.init();let t=await B.getStorageInfo();s(t?.isOpfs??B.getIsOpfs());let n=t.profileStats.find(t=>t.profile_id===e);d(n?n.count:0)}catch(e){console.error(`[LocalRetentionCard] Failed to load storage info:`,e),s(B.getIsOpfs()),d(0)}},[e]);(0,Y.useEffect)(()=>{_()},[_]);let v=e=>{a(e),B.setLocalRetentionDays(e),_()};return(0,X.jsxs)(L,{elevation:C.ONE,className:`dark:bg-gray-900 dark:border-gray-800`,children:[(0,X.jsxs)(w,{className:`flex items-center gap-2 mb-4 font-bold`,children:[(0,X.jsx)(c,{size:18,className:`text-cyan-500`}),` `,r(`settings.localRetentionTitle`,`本地存储与留存`)]}),(0,X.jsxs)(`div`,{className:`space-y-4`,children:[(0,X.jsx)(N,{label:r(`settings.localRetentionDuration`,`本地保留时长`),children:(0,X.jsxs)(A,{fill:!0,value:i,onChange:e=>v(parseInt(e.target.value,10)),children:[(0,X.jsx)(`option`,{value:30,children:r(`settings.localRetention30d`,`30 天`)}),(0,X.jsx)(`option`,{value:90,children:r(`settings.localRetention90d`,`90 天 (推荐)`)}),(0,X.jsx)(`option`,{value:180,children:r(`settings.localRetention180d`,`180 天`)}),(0,X.jsx)(`option`,{value:365,children:r(`settings.localRetention365d`,`365 天 (1 年)`)}),(0,X.jsx)(`option`,{value:0,children:r(`settings.localRetentionUnlimited`,`永久保留 (直到手动清除)`)})]})}),(0,X.jsx)(`p`,{className:`text-xs opacity-60`,children:r(`settings.localRetentionDesc`,`日志将持久化保存在当前浏览器本地的 SQLite 数据库 (OPFS) 中,提供秒级本地搜索并节省云端存储费用。超出此时长的本地日志将自动清除。`)}),(0,X.jsxs)(`div`,{className:`pt-3 border-t border-gray-100 dark:border-gray-800/80 space-y-3`,children:[(0,X.jsxs)(`div`,{className:`flex items-center justify-between text-xs`,children:[(0,X.jsxs)(`span`,{className:`flex items-center gap-1.5 opacity-70`,children:[(0,X.jsx)(m,{size:14}),r(`settings.localEngineStorage`,`存储引擎`),`:`]}),(0,X.jsx)(P,{minimal:!0,intent:o?O.SUCCESS:O.WARNING,className:`text-[11px]`,children:o?r(`settings.localEngineOpfs`,`OPFS 本地持久化`):r(`settings.localEngineMemory`,`内存临时存储 (无痕/私密模式)`)})]}),(0,X.jsxs)(`div`,{className:`flex items-center justify-between text-xs`,children:[(0,X.jsxs)(`span`,{className:`opacity-70`,children:[r(`settings.localCachedCount`,`本地已缓存日志`),`:`]}),(0,X.jsx)(`span`,{className:`font-mono font-medium`,children:u===null?`...`:r(`settings.localCachedCountUnit`,`{{count}} 条记录`,{count:u})})]}),(0,X.jsx)(`div`,{className:`pt-1 flex justify-end`,children:(0,X.jsx)(T,{minimal:!0,small:!0,intent:O.DANGER,icon:(0,X.jsx)(t,{size:13}),text:r(`settings.clearLocalData`,`清空本地日志`),disabled:u===0||u===null||h,onClick:()=>p(!0)})})]})]}),(0,X.jsx)(x,{isOpen:f,confirmButtonText:r(`common.confirm`,`确认清空`),cancelButtonText:r(`common.cancel`,`取消`),intent:O.DANGER,icon:`trash`,onConfirm:async()=>{g(!0);try{await B.clearProfile(e),d(0),n?.current?.show({message:r(`settings.clearLocalDataSuccess`,`本地日志已成功清空`),intent:O.SUCCESS,icon:`tick`})}catch(e){console.error(`[LocalRetentionCard] Failed to clear local profile logs:`,e),n?.current?.show({message:r(`settings.clearLocalDataError`,`清空本地日志失败`),intent:O.DANGER,icon:`error`})}finally{g(!1),p(!1)}},onCancel:()=>p(!1),loading:h,children:(0,X.jsx)(`p`,{children:r(`settings.clearLocalDataConfirm`,`确定要清空此配置在本地保存的所有日志吗?(云端日志不受影响)`)})})]})},oe=({settings:e,setSettings:t})=>{let{t:n}=l();return(0,X.jsxs)(L,{elevation:C.ONE,className:`dark:bg-gray-900 dark:border-gray-800`,children:[(0,X.jsxs)(w,{className:`flex items-center gap-2 mb-3 font-bold`,children:[(0,X.jsx)(d,{size:18,className:`text-orange-500`}),` `,n(`settings.ecsTitle`)]}),(0,X.jsxs)(`div`,{className:`space-y-4`,children:[(0,X.jsx)(M,{label:n(`settings.sendEcs`),checked:e.ecs.enabled,onChange:n=>t({...e,ecs:{...e.ecs,enabled:n.currentTarget.checked}})}),(0,X.jsx)(M,{label:n(`settings.customSubnet`),disabled:!e.ecs.enabled,checked:!e.ecs.use_client_ip,onChange:n=>t({...e,ecs:{...e.ecs,use_client_ip:!n.currentTarget.checked}})}),(0,X.jsxs)(`div`,{className:`space-y-3 pt-2 border-t border-gray-100 dark:border-gray-800`,children:[(0,X.jsx)(N,{label:n(`settings.customIpv4`),labelInfo:n(`settings.ipv4Hint`),disabled:!(e.ecs.enabled&&!e.ecs.use_client_ip),children:(0,X.jsx)(j,{placeholder:`0.0.0.0/0`,value:e.ecs.ipv4_cidr||``,disabled:!(e.ecs.enabled&&!e.ecs.use_client_ip),onChange:n=>t({...e,ecs:{...e.ecs,ipv4_cidr:n.target.value}})})}),(0,X.jsx)(N,{label:n(`settings.customIpv6`),labelInfo:n(`settings.ipv6Hint`),disabled:!(e.ecs.enabled&&!e.ecs.use_client_ip),children:(0,X.jsx)(j,{placeholder:`::/0`,value:e.ecs.ipv6_cidr||``,disabled:!(e.ecs.enabled&&!e.ecs.use_client_ip),onChange:n=>t({...e,ecs:{...e.ecs,ipv6_cidr:n.target.value}})})})]}),(0,X.jsx)(`p`,{className:`text-xs opacity-60`,children:n(`settings.ecsUpstreamHint`)})]})]})};var $=[{domain:`cloudflare-ech.com`,isPreferred:!0},{domain:`crypto.cloudflare.com`,isPreferred:!1},{domain:`one.one.one.one`,isPreferred:!1},{domain:`www.cloudflare.com`,isPreferred:!1},{domain:`encryptedsni.com`,isPreferred:!1},{domain:`cdnjs.com`,isPreferred:!1}];const se=({settings:e,setSettings:t})=>{let{t:n}=l(),[r,i]=Y.useState($);Y.useEffect(()=>{z().then(e=>{Array.isArray(e)&&e.length>0&&i(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 a=typeof e.best_effort_ech==`boolean`?e.best_effort_ech:!!e.best_effort_ech?.enabled,o=typeof e.best_effort_ech==`object`&&e.best_effort_ech?.fronting_domain?e.best_effort_ech.fronting_domain:`cloudflare-ech.com`,c=n=>{t({...e,best_effort_ech:{enabled:n,fronting_domain:o||`cloudflare-ech.com`}})},u=n=>{t({...e,best_effort_ech:{enabled:a,fronting_domain:n}})},d=(0,X.jsx)(S,{className:`min-w-72`,children:r.map(e=>(0,X.jsx)(I,{text:e.domain,onClick:()=>u(e.domain),labelElement:e.isPreferred?(0,X.jsx)(P,{minimal:!0,intent:O.PRIMARY,className:`text-[10px]`,children:n(`settings.echPreferred`,`首选`)}):void 0},e.domain))});return(0,X.jsxs)(L,{elevation:C.ONE,className:`dark:bg-gray-900 dark:border-gray-800`,children:[(0,X.jsxs)(`div`,{className:`flex items-center justify-between mb-3`,children:[(0,X.jsxs)(w,{className:`flex items-center gap-2 m-0 font-bold text-purple-600 dark:text-purple-400`,children:[(0,X.jsx)(s,{size:18}),` `,n(`settings.echTitle`)]}),(0,X.jsx)(D,{placement:`bottom-end`,usePortal:!0,content:(0,X.jsxs)(`div`,{className:`p-4 max-w-sm`,children:[(0,X.jsx)(w,{children:n(`settings.whatIsEch`,`何为 ECH (Encrypted Client Hello)?`)}),(0,X.jsx)(`p`,{className:`text-sm mb-2`,children:n(`settings.echHelpDesc`)}),(0,X.jsxs)(`ul`,{className:`list-disc list-inside text-sm opacity-80 mb-3 space-y-1`,children:[(0,X.jsx)(`li`,{children:n(`settings.echHelpBenefit1`)}),(0,X.jsx)(`li`,{children:n(`settings.echHelpBenefit2`)})]}),(0,X.jsx)(`div`,{className:`text-xs border-t border-gray-100 dark:border-gray-700 pt-2`,children:(0,X.jsxs)(`a`,{href:`https://en.wikipedia.org/wiki/Encrypted_Client_Hello`,target:`_blank`,rel:`noreferrer`,className:`flex items-center gap-1 text-blue-500 hover:underline`,children:[(0,X.jsx)(f,{size:10}),` `,n(`setup.learnMore`,`了解更多`)]})})]}),children:(0,X.jsx)(T,{icon:`help`,variant:`minimal`,intent:O.NONE})})]}),(0,X.jsxs)(`div`,{className:`space-y-4`,children:[(0,X.jsx)(M,{label:n(`settings.enableEch`,`启用重写 ECH`),checked:a,onChange:e=>c(e.currentTarget.checked)}),(0,X.jsx)(`p`,{className:`text-xs opacity-60 leading-relaxed`,children:n(`settings.echDesc`,`针对由 Cloudflare 代理的域名,当查询 HTTPS (Type 65) 或 SVCB (Type 64) 记录且上游未配置 ECH 时,自动重写注入 ECH 参数以保护 SNI 隐私。`)}),a&&(0,X.jsx)(`div`,{className:`space-y-3 pt-3 border-t border-gray-100 dark:border-gray-800`,children:(0,X.jsx)(N,{label:n(`settings.echFrontingTitle`,`表层 SNI (ECH Fronting)`),labelInfo:(0,X.jsx)(`span`,{className:`text-xs opacity-60`,children:n(`settings.echFrontingDesc`,`TLS 握手外层可见的伪装域名`)}),children:(0,X.jsx)(j,{fill:!0,placeholder:n(`settings.echFrontingCustomPlaceholder`,`输入自定义表层域名,例如 crypto.cloudflare.com`),value:o,onChange:e=>u(e.target.value),onFocus:e=>e.target.select(),className:`font-mono text-sm`,rightElement:(0,X.jsx)(D,{content:d,placement:`bottom-end`,animation:`minimal`,arrow:!1,children:(0,X.jsx)(T,{variant:`minimal`,icon:`chevron-down`})})})})})]})]})},ce=({testInput:e,setTestInput:t,handleDnsTest:n,testing:a,testResult:o})=>{let{t:s}=l();return(0,X.jsxs)(L,{elevation:C.TWO,className:`dark:bg-gray-900 border-t-2 border-blue-500`,children:[(0,X.jsxs)(w,{className:`flex items-center gap-2 mb-6 font-bold`,children:[(0,X.jsx)(h,{size:20,className:`text-yellow-500 fill-yellow-500`}),` `,s(`settings.testToolTitle`)]}),(0,X.jsxs)(`div`,{className:`flex flex-col space-y-6`,children:[(0,X.jsx)(N,{label:s(`settings.testDomain`),className:`mb-0`,children:(0,X.jsx)(j,{fill:!0,large:!0,placeholder:s(`settings.domainPlaceholder`),value:e.domain,onChange:n=>t({...e,domain:n.target.value}),onKeyDown:e=>e.key===`Enter`&&n()})}),(0,X.jsxs)(`div`,{className:`flex justify-end gap-4 items-end`,children:[(0,X.jsx)(N,{label:s(`settings.recordType`),className:`w-32 mb-0`,children:(0,X.jsxs)(A,{fill:!0,large:!0,value:e.type,onChange:n=>t({...e,type:n.target.value}),children:[(0,X.jsx)(`option`,{value:`A`,children:`A`}),(0,X.jsx)(`option`,{value:`AAAA`,children:`AAAA`}),(0,X.jsx)(`option`,{value:`CNAME`,children:`CNAME`}),(0,X.jsx)(`option`,{value:`TXT`,children:`TXT`})]})}),(0,X.jsx)(N,{label:`\xA0`,className:`mb-0`,children:(0,X.jsx)(T,{size:`large`,intent:O.PRIMARY,icon:`search`,text:s(`settings.runTest`),onClick:n,loading:a})})]}),o&&(0,X.jsxs)(`div`,{className:`bg-gray-50 dark:bg-gray-800/50 p-6 rounded-xl border border-gray-100 dark:border-gray-800 space-y-6 animate-in fade-in slide-in-from-top-4`,children:[(0,X.jsxs)(`div`,{className:`flex flex-wrap gap-4 items-center`,children:[(0,X.jsx)(P,{large:!0,round:!0,intent:o.action===`PASS`?O.SUCCESS:o.action===`BLOCK`?O.DANGER:O.WARNING,className:`px-4 font-bold`,children:o.action}),(0,X.jsxs)(`div`,{className:`flex flex-col`,children:[(0,X.jsx)(`span`,{className:`text-[10px] uppercase font-bold opacity-40`,children:s(`settings.hitRule`)}),(0,X.jsx)(`span`,{className:`text-sm font-bold`,children:o.reason||s(`settings.defaultAllow`)})]}),(0,X.jsxs)(`div`,{className:`flex flex-col border-l border-gray-200 dark:border-gray-700 pl-4`,children:[(0,X.jsx)(`span`,{className:`text-[10px] uppercase font-bold opacity-40`,children:s(`settings.parseLatency`)}),(0,X.jsx)(`span`,{className:`text-sm font-mono font-bold`,children:o.latency?`${o.latency}ms`:`-`})]}),o.timings&&(0,X.jsx)(`div`,{className:`flex flex-wrap gap-x-4 gap-y-1 border-l border-gray-200 dark:border-gray-700 pl-4 max-w-md`,children:Object.entries(o.timings).map(([e,t])=>(0,X.jsxs)(`div`,{className:`flex gap-1 items-baseline`,children:[(0,X.jsxs)(`span`,{className:`text-[9px] opacity-40 uppercase font-mono`,children:[e,`:`]}),(0,X.jsxs)(`span`,{className:`text-[10px] font-mono font-bold`,children:[t,`ms`]})]},e))}),(0,X.jsx)(k,{}),(0,X.jsxs)(`div`,{className:`flex items-center gap-2 bg-white dark:bg-gray-900 px-3 py-1.5 rounded-lg shadow-sm border border-gray-100 dark:border-gray-800`,children:[(0,X.jsx)(r,{size:14,className:`text-red-500`}),(0,X.jsxs)(`div`,{className:`flex flex-col`,children:[(0,X.jsx)(`span`,{className:`text-[10px] uppercase font-bold opacity-40 leading-none`,children:s(`settings.sourceIp`)}),(0,X.jsxs)(`span`,{className:`text-xs font-mono`,children:[o.client_ip,` (`,o.geo_country,`)`]})]})]})]}),(0,X.jsxs)(`div`,{className:`space-y-3`,children:[(0,X.jsxs)(`div`,{className:`text-[10px] uppercase font-bold opacity-40 flex items-center gap-1`,children:[(0,X.jsx)(i,{size:10}),` `,s(`settings.answerSection`)]}),(0,X.jsx)(`div`,{className:`font-mono text-sm leading-relaxed bg-white dark:bg-gray-900 p-4 rounded-xl border border-gray-100 dark:border-gray-800 shadow-inner`,children:o.answers&&o.answers.length>0?o.answers.map((e,t)=>(0,X.jsxs)(`div`,{className:`flex gap-4 py-1 border-b border-gray-50 dark:border-gray-800 last:border-0 hover:bg-blue-50/50 dark:hover:bg-blue-900/10 transition-colors px-2`,children:[(0,X.jsx)(`span`,{className:`w-16 font-bold text-blue-500`,children:e.type}),(0,X.jsx)(`span`,{className:`flex-1 dark:text-gray-300`,children:e.data}),(0,X.jsxs)(`span`,{className:`text-[10px] opacity-30 italic`,children:[`TTL: `,e.ttl,`s`]})]},t)):(0,X.jsx)(`div`,{className:`p-4 opacity-40 italic text-center`,children:s(`settings.noRecordsReturned`)})})]}),o.diagnostics&&(0,X.jsx)(E,{minimal:!0,intent:o.action===`FAIL`?O.DANGER:O.NONE,className:`text-xs font-mono`,children:(0,X.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,X.jsxs)(`div`,{className:`flex justify-between items-center`,children:[(0,X.jsx)(`span`,{className:`font-bold uppercase tracking-wider`,children:s(`settings.diagnostics`)}),(0,X.jsx)(`span`,{className:`font-bold`,children:o.action===`FAIL`?o.diagnostics.status>0?`HTTP ${o.diagnostics.status}${o.diagnostics.status_text?` (${o.diagnostics.status_text})`:``}`:`Network / Connection Error`:o.diagnostics.method===`POST`||o.diagnostics.method===`GET`?`HTTP ${o.diagnostics.status}${o.diagnostics.status_text?` (${o.diagnostics.status_text})`:``}`:`Connected (OK)`})]}),(0,X.jsxs)(`div`,{className:`flex items-center gap-2 text-xs opacity-80`,children:[(0,X.jsx)(`span`,{className:`px-1.5 py-0.5 bg-gray-200 dark:bg-gray-700 rounded text-[10px] font-bold`,children:o.diagnostics.method}),(0,X.jsx)(`span`,{className:`break-all`,children:o.diagnostics.upstream_url})]}),o.diagnostics.cf_ray&&(0,X.jsxs)(`div`,{className:`text-[11px] opacity-75`,children:[`CF-Ray: `,(0,X.jsx)(`span`,{className:`font-bold`,children:o.diagnostics.cf_ray})]}),o.diagnostics.error_detail&&o.action===`FAIL`&&(0,X.jsxs)(`div`,{className:`p-2 bg-red-50 dark:bg-red-950/40 rounded border border-red-200 dark:border-red-900/50 text-red-700 dark:text-red-300 break-words`,children:[(0,X.jsxs)(`div`,{className:`font-bold mb-0.5`,children:[s(`settings.errorDetail`),`:`]}),(0,X.jsx)(`div`,{children:o.diagnostics.error_detail})]}),o.diagnostics.response_body&&(0,X.jsxs)(`div`,{className:`p-2 bg-gray-100 dark:bg-gray-900 rounded border border-gray-200 dark:border-gray-700 text-gray-700 dark:text-gray-300 break-words text-[11px]`,children:[(0,X.jsxs)(`div`,{className:`font-bold mb-0.5 opacity-60`,children:[s(`settings.upstreamResponse`),`:`]}),(0,X.jsx)(`div`,{className:`line-clamp-3`,children:o.diagnostics.response_body})]})]})})]})]})]})},le=({profileId:e,toasterRef:t,currentUser:n,onSavingChange:r})=>{let[i,a]=(0,Y.useState)(null),[o,s]=(0,Y.useState)(null),[c,u]=(0,Y.useState)(!0),[d,f]=(0,Y.useState)(!1),{t:p}=l();(0,Y.useEffect)(()=>(r?.(d),()=>{r?.(!1)}),[d,r]);let m=(0,Y.useRef)(!0),h=(0,Y.useRef)(null),g=(0,Y.useRef)(null),_=(0,Y.useRef)(0),v=e=>typeof structuredClone==`function`?structuredClone(e):JSON.parse(JSON.stringify(e)),[y,b]=(0,Y.useState)(!1),[x,S]=(0,Y.useState)(``),[C,w]=(0,Y.useState)({domain:`o-o.myaddr.l.google.com`,type:`TXT`}),[T,E]=(0,Y.useState)(null),[D,k]=(0,Y.useState)(!1);(0,Y.useEffect)(()=>{m.current=!0,h.current&&=(clearTimeout(h.current),null),(async()=>{u(!0);try{let t=await H(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{u(!1)}})()},[e]),(0,Y.useEffect)(()=>{if(!c&&o&&m.current){let e=setTimeout(()=>{m.current=!1,o&&(g.current=v(o))},500);return()=>clearTimeout(e)}},[c,o]),(0,Y.useEffect)(()=>()=>{h.current&&clearTimeout(h.current)},[]);let A=async()=>{if(!x||x===i?.name){b(!1);return}let n=i?.name||``;f(!0);try{await J(U(e,x),1e4),a(e=>e?{...e,name:x}:null),b(!1),t?.current?.show({message:p(`common.saveSuccess`,`保存成功`),intent:O.SUCCESS,icon:`tick`})}catch(e){console.error(e),S(n),b(!1);let r=e.message,i=r;r===`The profile name already exists`?i=p(`common.profileNameExists`,`The profile name already exists`):r===`Invalid Profile Name format`&&(i=p(`common.profileNameFormatError`,`Invalid Profile Name format`)),t?.current?.show({message:i||p(`common.saveFailed`,`保存失败`),intent:O.DANGER,icon:`error`})}finally{f(!1)}},j=(0,Y.useCallback)(async n=>{if(!n)return;let r=++_.current;f(!0);try{await J(q(e,n),1e4),r===_.current&&(g.current=v(n),t?.current?.show({message:p(`common.saveSuccess`,`保存成功`),intent:O.SUCCESS,icon:`tick`}))}catch(e){console.error(e),r===_.current&&(h.current&&=(clearTimeout(h.current),null),g.current&&s(v(g.current)),t?.current?.show({message:p(`common.saveFailed`,`保存失败`),intent:O.DANGER,icon:`error`}))}finally{r===_.current&&f(!1)}},[e,t,p]),M=(0,Y.useCallback)(e=>{h.current&&clearTimeout(h.current),h.current=setTimeout(()=>{j(e)},600)},[j]),N=(0,Y.useCallback)(e=>{s(e),m.current||M(e)},[M]);return c||!o?(0,X.jsx)(`div`,{className:`p-20 flex justify-center`,children:(0,X.jsx)(ee,{})}):(0,X.jsxs)(`div`,{className:`p-0 sm:px-4 lg:px-8 max-w-5xl mx-auto space-y-8 pb-20`,children:[(0,X.jsx)(Z,{profile:i,isEditingName:y,setIsEditingName:b,editName:x,setEditName:S,updateProfileName:A,exportProfile:async()=>{if(!(!i||!o))try{let[n,r]=await Promise.all([G(e).catch(()=>[]),W(e).catch(()=>[])]),a=new Set,s=(n||[]).filter(e=>{let t=(e.pattern||``).trim().toLowerCase();return!t||a.has(t)?!1:(a.add(t),!0)}),c=new Set,l=(r||[]).filter(e=>{let t=(e.url||``).trim().toLowerCase();return!t||c.has(t)?!1:(c.add(t),!0)}).map(e=>({url:e.url,enabled:!!e.enabled})),u={version:2,name:i.name,settings:o,rules:s,filters:l,exported_at:Math.floor(Date.now()/1e3)},d=new Blob([JSON.stringify(u,null,2)],{type:`application/json`}),f=URL.createObjectURL(d),m=document.createElement(`a`);m.href=f,m.download=`dns-worker-${i.name||e}.json`,document.body.appendChild(m),m.click(),document.body.removeChild(m),URL.revokeObjectURL(f),t?.current?.show({message:p(`settings.exportSuccess`,`配置成功导出`),intent:O.SUCCESS,icon:`download`})}catch(e){console.error(e),t?.current?.show({message:p(`settings.exportError`,`导出失败`),intent:O.DANGER,icon:`error`})}}}),(0,X.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-6`,children:[(0,X.jsx)(ne,{settings:o,setSettings:N}),(0,X.jsx)(re,{settings:o,setSettings:N}),(0,X.jsx)(ie,{settings:o,setSettings:N,isAdmin:n?.role===`admin`,maxRetentionDays:n?.max_log_retention_days??(n?.role===`admin`?30:7)}),(0,X.jsx)(ae,{profileId:e,toasterRef:t}),(0,X.jsx)(oe,{settings:o,setSettings:N}),(0,X.jsx)(se,{settings:o,setSettings:N})]}),(0,X.jsx)(ce,{testInput:C,setTestInput:w,handleDnsTest:async()=>{if(C.domain){k(!0),E(null);try{E(await K(e,C))}catch(e){console.error(e)}finally{k(!1)}}},testing:D,testResult:T})]})};export{le as SettingsView};
@@ -0,0 +1 @@
1
+ import{i as e}from"./rolldown-runtime-C4Xdq4VV.js";import{A as t,C as n,Dt as r,E as i,F as a,G as o,I as s,J as c,K as l,N as u,Ot as d,P as f,R as p,V as m,at as h,en as g,it as _,nt as v,ot as y,ut as b,w as x,z as S}from"./vendor-react-BtC4HVVO.js";import{S as C,b as w}from"./vendor-icons-other-BTYC6Wvz.js";import"./vendor-i18next-BC3ewzY3.js";import{A as T,B as E,F as D,L as O,M as k,N as A,O as j,P as M,R as N,S as P,T as F,V as I,a as L,d as R,f as z,i as B,n as V,o as H,r as U,v as W,z as G}from"./vendor-ui-core-DUyKOLA8.js";import{_t as K,t as ee,vt as q}from"./vendor-utils-xrsi4rSa.js";import{F as te,G as ne,H as re,I as ie,U as J,V as ae,_ as oe,a as se,cn as ce,h as le,ht as ue,it as de,mt as fe,n as Y,ot as pe,q as me,t as he,tt as ge}from"./index-9kbjmMJz.js";import{t as _e}from"./SwipeableDrawer-B1CCYC-Y.js";var X=e(C(),1),Z=e(w(),1);const ve=()=>{let{t:e}=g();return(0,Z.jsxs)(`div`,{className:`flex flex-col sm:flex-row justify-between items-start sm:items-center gap-4`,children:[(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(T,{className:`font-bold text-gray-900 dark:text-white m-0`,children:e(`setup.title`)}),(0,Z.jsx)(`p`,{className:`bp6-text-muted m-0 mt-1`,children:e(`setup.subtitle`)})]}),(0,Z.jsx)(`div`,{className:`flex items-center`,children:(0,Z.jsx)(he,{})})]})},ye=({isVerifying:e,verifyResult:n,handleVerify:r,isMobile:i,clientInfo:a,showIp:o,setShowIp:s,showLocation:l,setShowLocation:u,traceInfo:p,edgeLocation:m})=>{let{t:y}=g(),{isServerfull:b}=Y(),[x,S]=(0,X.useState)(!1),C=(0,Z.jsxs)(`div`,{className:q(`bg-white dark:bg-gray-900 p-4 rounded-lg border border-gray-100 dark:border-gray-800 shadow-sm flex items-start gap-3 select-none h-full transition-all`,!b),children:[(0,Z.jsx)(f,{size:18,className:`text-purple-500 mt-1 shrink-0`}),(0,Z.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Z.jsx)(`div`,{className:`text-[10px] uppercase font-bold opacity-40`,children:b?y(`setup.serverLocation`,`服务器位置`):y(`setup.edgeServer`)}),(0,Z.jsx)(`div`,{className:`font-bold truncate`,title:b?m||``:m||p?.colo||``,children:b?m||y(`setup.detecting`):m||p?.colo||y(`setup.detecting`)})]})]});return(0,Z.jsx)(H,{title:y(`setup.verifyConnection`),icon:(0,Z.jsx)(d,{size:16}),children:(0,Z.jsx)(L,{children:(0,Z.jsxs)(`div`,{className:`flex flex-col space-y-6`,children:[(0,Z.jsxs)(`div`,{className:`flex flex-col md:flex-row items-center justify-between bg-gray-50 dark:bg-gray-800/50 p-6 rounded-xl border border-gray-100 dark:border-gray-800 gap-6`,children:[(0,Z.jsxs)(`div`,{className:`flex flex-col md:flex-row items-center gap-4 text-center md:text-left`,children:[(0,Z.jsx)(`div`,{className:`p-3 rounded-full ${n?.success?`bg-green-100 text-green-600`:n?`bg-red-100 text-red-600`:`bg-blue-100 text-blue-600`}`,children:e?(0,Z.jsx)(M,{size:24}):n?.success?(0,Z.jsx)(t,{size:24}):(0,Z.jsx)(f,{size:24})}),(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`div`,{className:`font-bold text-lg`,children:e?y(`setup.verifying`):n?.success?y(`setup.connected`):y(`setup.notConnected`)}),(0,Z.jsx)(`div`,{className:`text-sm opacity-60`,children:n?.success?n.profileMatch?y(`setup.profileMatch`):y(`setup.profileMismatch`):y(`setup.verifyHint`)})]})]}),(0,Z.jsx)(A,{size:`large`,intent:n?.success?I.SUCCESS:I.PRIMARY,icon:`refresh`,text:y(`setup.refreshStatus`),onClick:r,loading:e,fill:i})]}),a&&(0,Z.jsxs)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 md:grid-cols-3 gap-4`,children:[(0,Z.jsxs)(`div`,{className:`bg-white dark:bg-gray-900 p-4 rounded-lg border border-gray-100 dark:border-gray-800 shadow-sm flex items-start gap-3`,children:[(0,Z.jsx)(v,{size:18,className:`text-blue-500 mt-1`}),(0,Z.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Z.jsx)(`div`,{className:`text-[10px] uppercase font-bold opacity-40`,children:y(`setup.egressIp`)}),(0,Z.jsx)(`button`,{onClick:()=>s(!o),className:`text-gray-400 hover:text-blue-500 transition-colors`,children:o?(0,Z.jsx)(_,{size:16}):(0,Z.jsx)(h,{size:16})})]}),(0,Z.jsx)(`div`,{className:`font-mono font-bold text-blue-600 dark:text-blue-400 truncate`,children:(0,Z.jsx)(`span`,{className:q(`transition-[filter] duration-200 inline-block`,!o&&`filter blur-[6px] select-none`),children:a.ip})})]})]}),(0,Z.jsxs)(`div`,{className:`bg-white dark:bg-gray-900 p-4 rounded-lg border border-gray-100 dark:border-gray-800 shadow-sm flex items-start gap-3`,children:[(0,Z.jsx)(c,{size:18,className:`text-red-500 mt-1`}),(0,Z.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Z.jsx)(`div`,{className:`text-[10px] uppercase font-bold opacity-40`,children:y(`setup.currentLocation`)}),(0,Z.jsx)(`button`,{onClick:()=>u(!l),className:`text-gray-400 hover:text-red-500 transition-colors`,children:l?(0,Z.jsx)(_,{size:16}):(0,Z.jsx)(h,{size:16})})]}),(0,Z.jsx)(`div`,{className:`font-bold truncate`,children:(0,Z.jsx)(`span`,{className:q(`transition-[filter] duration-200 inline-block`,!l&&`filter blur-[6px] select-none`),children:(()=>{let e=[a.city,a.region,a.country].filter(e=>!!(e&&e!==`UNKNOWN`));return e.length>0?e.join(`, `):y(`setup.detecting`)})()})})]})]}),b?C:(0,Z.jsx)(F,{isOpen:x,onInteraction:S,placement:`bottom-end`,portalClassName:`z-20000`,fill:!0,targetProps:{className:`h-full`},content:(0,Z.jsxs)(`div`,{className:`p-3 select-text w-72 sm:w-80 max-w-[85vw] space-y-2`,children:[(0,Z.jsx)(`div`,{className:`text-[11px] font-mono font-bold text-gray-500 dark:text-gray-400 tracking-wide border-b border-gray-100 dark:border-gray-800 pb-1.5`,children:`/cdn-cgi/trace`}),(0,Z.jsx)(`pre`,{className:`m-0 font-mono text-xs leading-relaxed whitespace-pre-wrap break-all overflow-x-hidden max-h-64 overflow-y-auto text-gray-800 dark:text-gray-200`,children:p?.raw||y(`setup.noTraceData`,`暂无 Trace 数据`)})]}),children:C})]})]})})})},Q=({step:e,className:t,size:n=144})=>{let r=e===1?47:50,i=e===1?45.5:45;return(0,Z.jsx)(`div`,{"aria-hidden":`true`,className:K(`absolute -top-7 -left-7 pointer-events-none select-none z-0`,`text-blue-600/[0.08] dark:text-blue-400/[0.12]`,`transition-all duration-500 ease-out`,`blur-none group-hover:blur-md group-hover:opacity-0`,t),style:{width:n,height:n},children:(0,Z.jsxs)(`svg`,{viewBox:`0 0 100 100`,fill:`none`,xmlns:`http://www.w3.org/2000/svg`,className:`w-full h-full`,children:[(0,Z.jsx)(`circle`,{cx:`50`,cy:`50`,r:`46`,stroke:`currentColor`,strokeWidth:`4`}),(0,Z.jsx)(`text`,{x:r,y:i,textAnchor:`middle`,dominantBaseline:`central`,fill:`currentColor`,fontSize:`80`,fontWeight:`900`,fontFamily:`'Helvetica Neue', Helvetica, Arial, sans-serif`,children:e})]})})},be=({accessPoints:e,selectedApId:t,onSelectAp:n,accessPointName:r,onManageAccessPoints:i,isMobile:a})=>{let{t:o}=g();return(0,Z.jsxs)(H,{title:o(`setup.accessPointsCardTitle`,`接入点`),icon:(0,Z.jsx)(l,{size:16}),className:`group relative overflow-hidden [&_.bp6-section-header]:relative [&_.bp6-section-header]:z-10 [&_.bp6-section-card]:relative [&_.bp6-section-card]:z-10`,children:[(0,Z.jsx)(Q,{step:1}),(0,Z.jsx)(L,{children:(0,Z.jsxs)(`div`,{className:`flex flex-col sm:flex-row items-start sm:items-center justify-between gap-4`,children:[(0,Z.jsxs)(`div`,{className:`flex flex-col gap-1.5 w-full sm:w-auto`,children:[(0,Z.jsx)(`span`,{className:`text-xs opacity-50 font-medium`,children:o(`setup.selectAccessPointToConfigure`)}),(0,Z.jsxs)(`div`,{className:`flex items-center gap-3`,children:[e.length>0?(0,Z.jsx)(R,{value:t||``,onChange:e=>n(e.target.value),options:e.map(e=>({label:e.name,value:e.id})),className:`font-semibold text-gray-900 dark:text-gray-100`}):(0,Z.jsx)(`div`,{className:`font-semibold text-gray-900 dark:text-gray-100 flex items-center gap-2`,children:r||o(`setup.defaultAccessPointName`,`设备-1`)}),e.length>0&&(0,Z.jsx)(U,{minimal:!0,round:!0,intent:I.PRIMARY,className:`text-xs`,children:e.length})]})]}),(0,Z.jsx)(A,{variant:`outlined`,intent:I.NONE,icon:(0,Z.jsx)(u,{size:14}),text:o(`setup.manageAccessPoints`,`管理接入点`),onClick:i,fill:a,className:`shrink-0`})]})})]})},xe=({dohUrl:e,copyToClipboard:t,isMobile:n})=>{let{t:r}=g();return(0,Z.jsxs)(H,{title:r(`setup.accessPointTitle`,`Access DoH URL`),icon:`globe`,className:`group relative overflow-hidden [&_.bp6-section-header]:relative [&_.bp6-section-header]:z-10 [&_.bp6-section-card]:relative [&_.bp6-section-card]:z-10`,rightElement:(0,Z.jsx)(F,{placement:`bottom-end`,usePortal:!0,content:(0,Z.jsxs)(`div`,{className:`p-4 max-w-sm`,children:[(0,Z.jsx)(k,{children:r(`setup.whatIsDoh`)}),(0,Z.jsx)(`p`,{className:`text-sm mb-2`,children:r(`setup.dohDesc`)}),(0,Z.jsxs)(`ul`,{className:`list-disc list-inside text-sm opacity-80 mb-3 space-y-1`,children:[(0,Z.jsx)(`li`,{children:r(`setup.dohBenefit1`)}),(0,Z.jsx)(`li`,{children:r(`setup.dohBenefit2`)})]}),(0,Z.jsx)(`div`,{className:`text-xs border-t border-gray-100 dark:border-gray-700 pt-2`,children:(0,Z.jsxs)(`a`,{href:`https://en.wikipedia.org/wiki/DNS_over_HTTPS`,target:`_blank`,rel:`noreferrer`,className:`flex items-center gap-1 text-blue-500 hover:underline`,children:[(0,Z.jsx)(y,{size:10}),` `,r(`setup.learnMore`)]})})]}),children:(0,Z.jsx)(A,{icon:`help`,variant:`minimal`,intent:I.NONE})}),children:[(0,Z.jsx)(Q,{step:2}),(0,Z.jsx)(L,{children:(0,Z.jsxs)(`div`,{className:`w-full bg-gray-100 dark:bg-gray-800 p-3 rounded-lg border border-gray-200 dark:border-gray-700 flex flex-col sm:flex-row items-stretch sm:items-center justify-between gap-3`,children:[(0,Z.jsx)(`span`,{className:`font-mono text-blue-600 dark:text-blue-400 break-all text-xs sm:text-sm`,children:e}),(0,Z.jsx)(A,{intent:I.PRIMARY,icon:`duplicate`,text:r(`setup.copyUrl`),fill:n,onClick:()=>t(e),className:`shrink-0 whitespace-nowrap min-w-fit w-auto`})]})})]})};function Se(e){let t=e.trim();try{return new URL(t.startsWith(`http://`)||t.startsWith(`https://`)?t:`https://${t}`).hostname||t}catch{return t.replace(/^https?:\/\//,``).split(`/`)[0].split(`:`)[0]||t}}function $(e,t){let n=(e||``).trim(),r=(t||``).trim();if(!r&&n.includes(`(`)&&n.endsWith(`)`)){let e=n.match(/^(.+?)\s*\((.+?)\)$/);e&&(n=e[1].trim(),r=e[2].trim())}let i=n&&n!==`DNS Worker`?n:``,a=r&&r!==`DNS Worker`?r:``;return i&&a?i.toLowerCase()===a.toLowerCase()?i:`${i} - ${a}`:i||a||``}function Ce(e,t,n,r){let i,a,o,s;typeof e==`object`?(i=e.profileKey,a=e.profileName,o=e.accessPointName,s=e.origin):(i=e,a=t,s=n||``,o=r);let c=s.trim(),l=Se(c),u=`${c}/${i}`,d=$(a,o),f=crypto.randomUUID(),p=crypto.randomUUID(),m=d?`DNS Worker - ${l} (${d})`:`DNS Worker (${l})`,h=d?`DNS Worker DoH - ${l} (${d})`:`DNS Worker DoH - ${l}`,g=d?`DNS Worker DoH configuration profile for ${d} via ${l}`:`DNS Worker DoH configuration profile via ${l}`,_=d?`Configures encrypted DNS over HTTPS (DoH) for ${d} via ${l}`:`Configures encrypted DNS over HTTPS (DoH) via ${l}`;return ee({PayloadContent:[{DNSSettings:{DNSProtocol:`HTTPS`,ServerHTTPVersion:3,ServerURL:u},OnDemandRules:[{Action:`Connect`,InterfaceTypeMatch:`WiFi`},{Action:`Connect`,InterfaceTypeMatch:`Cellular`},{Action:`Disconnect`}],PayloadDescription:_,PayloadDisplayName:h,PayloadIdentifier:`com.apple.dnsSettings.managed.${f}`,PayloadName:h,PayloadType:`com.apple.dnsSettings.managed`,PayloadUUID:f,PayloadVersion:1}],PayloadDescription:g,PayloadDisplayName:m,PayloadIdentifier:`com.dnsworker.profile.${i}`,PayloadName:m,PayloadRemovalDisallowed:!1,PayloadType:`Configuration`,PayloadUUID:p,PayloadVersion:1},{indent:` `})}const we=({isMobile:e,copyToClipboard:t,profileKey:n,profileName:a,accessPointName:c,currentIps:l,dotDomain:u})=>{let{t:d}=g(),{isCloudflare:f}=Y();return(0,Z.jsxs)(`div`,{className:`group relative overflow-hidden rounded-xl border border-gray-200 dark:border-gray-800 bg-white dark:bg-gray-900 shadow-sm`,children:[(0,Z.jsx)(Q,{step:3}),(0,Z.jsxs)(V,{id:`setup-tabs`,renderActiveTabPanelOnly:!0,vertical:!e,size:`large`,className:K(`p-4 md:p-6 setup-tabs-container relative z-10 bg-transparent`,e&&[`[&_.bp6-tab-list]:overflow-x-auto!`,`[&_.bp6-tab-list]:flex-nowrap!`,`[&_.bp6-tab-list]:pb-1`,`[&_.bp6-tab-list]:scrollbar-none`,`[&_.bp6-tab-list]:[-ms-overflow-style:none]`,`[&_.bp6-tab-list::-webkit-scrollbar]:hidden`,`[&_.bp6-tab]:shrink-0`]),children:[(0,Z.jsx)(B,{id:`browsers`,title:(0,Z.jsxs)(`span`,{children:[(0,Z.jsx)(v,{size:16,className:`inline mr-2`}),d(`setup.browsers`)]}),panel:(0,Z.jsxs)(`div`,{className:`space-y-4 md:ml-4 mt-4 md:mt-0`,children:[(0,Z.jsx)(k,{className:`font-bold`,children:d(`setup.browserTitle`)}),(0,Z.jsx)(`p`,{className:`text-sm`,children:d(`setup.browserSteps`)}),(0,Z.jsx)(`p`,{className:`text-[10px] opacity-50 cursor-pointer`,onClick:()=>t(`chrome://settings/security`),children:d(`setup.browserTips`,`or copy this URL to the address bar: `)+`chrome://settings/security`})]})}),(0,Z.jsx)(B,{id:`apple`,title:(0,Z.jsxs)(`span`,{children:[(0,Z.jsx)(r,{size:16,className:`inline mr-2`}),d(`setup.apple`)]}),panel:(0,Z.jsxs)(`div`,{className:`space-y-4 md:ml-4 mt-4 md:mt-0`,children:[(0,Z.jsx)(k,{className:`font-bold`,children:d(`setup.appleTitle`)}),(0,Z.jsx)(`p`,{className:`text-sm`,children:d(`setup.appleDesc`)}),(0,Z.jsx)(`p`,{className:`text-[10px] opacity-50 text-center`,children:d(`setup.appleWarning`)}),(0,Z.jsxs)(`div`,{className:`p-6 bg-gray-50 dark:bg-gray-800 rounded-xl border border-dashed border-gray-300 dark:border-gray-700 flex flex-col items-center justify-center`,children:[(0,Z.jsx)(D,{icon:`document`,size:40,className:`opacity-20 mb-4`}),(0,Z.jsx)(A,{intent:I.PRIMARY,text:d(`setup.downloadConfig`),icon:`download`,onClick:()=>{let e=Ce({profileKey:n,profileName:a,accessPointName:c,origin:window.location.origin}),t=new Blob([e],{type:`application/x-apple-aspen-config`}),r=URL.createObjectURL(t),i=document.createElement(`a`);i.href=r;let o=$(a,c),s=Se(window.location.origin);i.download=`dns_worker-${(o||s).replace(/[^a-zA-Z0-9_\-\u4e00-\u9fa5]/g,`_`).replace(/_+/g,`_`).replace(/^_|_$/g,``)}-${n}.mobileconfig`,i.click(),URL.revokeObjectURL(r)}})]}),(0,Z.jsx)(`p`,{className:`text-[10px] opacity-50 mt-4! text-center`,children:d(`setup.appleInstallHint`)})]})}),(0,Z.jsx)(B,{id:`windows`,title:(0,Z.jsxs)(`span`,{children:[(0,Z.jsx)(o,{size:16,className:`inline mr-2`}),d(`setup.windows`)]}),panel:(0,Z.jsxs)(`div`,{className:`space-y-4 md:ml-4 mt-4 md:mt-0`,children:[(0,Z.jsx)(k,{className:`font-bold`,children:d(`setup.windowsTitle`)}),(0,Z.jsxs)(`ol`,{className:`list-decimal list-inside space-y-4 text-sm leading-relaxed`,children:[(0,Z.jsx)(`li`,{children:(0,Z.jsx)(`a`,{href:`ms-settings:network-status`,children:d(`setup.windowsStep0`)})}),(0,Z.jsx)(`li`,{children:d(`setup.windowsStep1`)}),(0,Z.jsxs)(`li`,{children:[d(`setup.windowsStep2`),(0,Z.jsx)(`div`,{className:`mt-2 flex flex-wrap gap-2`,children:l.map(e=>(0,Z.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,Z.jsx)(U,{minimal:!0,interactive:!0,onClick:()=>t(e.ip),icon:`duplicate`,className:`font-mono`,children:e.ip}),(0,Z.jsx)(`span`,{className:`text-[9px] opacity-50 ml-1 font-mono`,children:e.area})]},e.ip))})]}),(0,Z.jsx)(`li`,{children:d(`setup.windowsStep3`)}),(0,Z.jsx)(`li`,{children:d(`setup.windowsStep4`)})]})]})}),(0,Z.jsx)(B,{id:`linux`,title:(0,Z.jsxs)(`span`,{children:[(0,Z.jsx)(x,{size:16,className:`inline mr-2`}),d(`setup.linux`)]}),panel:(0,Z.jsxs)(`div`,{className:`space-y-4 md:ml-4 mt-4 md:mt-0`,children:[(0,Z.jsx)(k,{className:`font-bold`,children:d(`setup.linuxTitle`)}),(0,Z.jsx)(`p`,{className:`text-sm`,children:d(`setup.linuxDesc`)}),(0,Z.jsxs)(`div`,{className:`mt-4`,children:[(0,Z.jsx)(`p`,{className:`text-sm font-bold mb-2`,children:d(`setup.linuxStep1`)}),(0,Z.jsxs)(`div`,{className:`relative group`,children:[(0,Z.jsx)(`pre`,{className:`bg-gray-100 dark:bg-gray-800 p-4 rounded-lg overflow-x-auto text-xs font-mono border border-gray-200 dark:border-gray-700`,children:(0,Z.jsx)(`code`,{children:`curl -sL "${window.location.origin}/setup.sh?key=${n}&origin=${window.location.origin}" | sudo bash`})}),(0,Z.jsx)(A,{className:`absolute top-2 right-2 opacity-0 group-hover:opacity-100 transition-opacity`,icon:`duplicate`,minimal:!0,small:!0,onClick:()=>{t(`curl -sL "${window.location.origin}/setup.sh?key=${n}&origin=${window.location.origin}" | sudo bash`)}})]})]}),(0,Z.jsx)(`div`,{className:`mt-4`,children:(0,Z.jsx)(`p`,{className:`text-sm font-bold`,children:d(`setup.linuxStep2`)})})]})}),(0,Z.jsx)(B,{id:`routeros`,title:(0,Z.jsxs)(`span`,{children:[(0,Z.jsx)(s,{size:16,className:`inline mr-2`}),d(`setup.routeros`)]}),panel:(0,Z.jsxs)(`div`,{className:`space-y-4 md:ml-4 mt-4 md:mt-0`,children:[(0,Z.jsx)(k,{className:`font-bold`,children:d(`setup.routerosTitle`)}),(0,Z.jsx)(`p`,{className:`text-sm`,children:d(`setup.routerosDesc`)}),(0,Z.jsxs)(`div`,{className:`mt-4`,children:[(0,Z.jsx)(`p`,{className:`text-sm font-bold mb-2`,children:d(`setup.routerosStep1`)}),(0,Z.jsxs)(`div`,{className:`relative group`,children:[(0,Z.jsx)(`pre`,{className:`bg-gray-100 dark:bg-gray-800 p-4 rounded-lg overflow-x-auto text-xs font-mono border border-gray-200 dark:border-gray-700`,children:(0,Z.jsx)(`code`,{children:`/ip dns set use-doh-server="${window.location.origin}/${n}" verify-doh-cert=yes`})}),(0,Z.jsx)(A,{className:`absolute top-2 right-2 opacity-0 group-hover:opacity-100 transition-opacity`,icon:`duplicate`,minimal:!0,small:!0,onClick:()=>{t(`/ip dns set use-doh-server="${window.location.origin}/${n}" verify-doh-cert=yes`)}})]})]}),(0,Z.jsx)(`p`,{className:`text-sm`,children:d(`setup.routerosNote`)}),(0,Z.jsxs)(`a`,{href:`https://help.mikrotik.com/docs/spaces/ROS/pages/37748767/DNS`,target:`_blank`,rel:`noreferrer`,className:`flex items-center gap-1 text-xs text-blue-500 hover:underline`,children:[(0,Z.jsx)(y,{size:10}),` `,d(`setup.routerosDocs`)]})]})}),(0,Z.jsx)(B,{id:`android`,title:(0,Z.jsxs)(`span`,{children:[(0,Z.jsx)(i,{size:16,className:`inline mr-2`}),d(`setup.android`)]}),panel:(0,Z.jsxs)(`div`,{className:`space-y-4 md:ml-4 mt-4 md:mt-0`,children:[(0,Z.jsx)(k,{className:`font-bold`,children:d(`setup.androidTitle`)}),(0,Z.jsx)(`p`,{className:`text-sm`,children:d(`setup.androidDesc`)}),f?(0,Z.jsxs)(P,{intent:I.WARNING,icon:`warning-sign`,className:`text-xs`,children:[(0,Z.jsx)(`div`,{className:`font-semibold mb-1`,children:d(`setup.dotUnavailableCfTitle`)}),(0,Z.jsx)(`div`,{children:d(`setup.dotUnavailableCfDesc`)})]}):(()=>{let e=/^(\d{1,3}\.){3}\d{1,3}$/.test(window.location.hostname)||window.location.hostname===`localhost`||window.location.hostname===`127.0.0.1`||window.location.hostname.includes(`:`),r=(u||``).trim().replace(/^\*\./,``),i=!J(r)&&r||(e?``:window.location.hostname);return(0,Z.jsxs)(`div`,{className:`p-4 bg-gray-50 dark:bg-gray-800/60 rounded-xl border border-gray-200 dark:border-gray-700 space-y-3`,children:[(0,Z.jsx)(`div`,{className:`text-xs font-semibold text-gray-700 dark:text-gray-300`,children:d(`setup.androidDotTitle`,`私有 DNS (DoT / DoQ)`)}),(0,Z.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-gray-400`,children:d(`setup.androidDotDesc`,`支持 Android 原生“私有 DNS (DoT)”及各类现代 DoQ 客户端。提供商主机名:`)}),i?(0,Z.jsx)(`div`,{className:`space-y-3 pt-1`,children:(0,Z.jsx)(`div`,{className:`flex flex-col sm:flex-row sm:items-center gap-1.5 sm:gap-2`,children:(0,Z.jsx)(U,{minimal:!0,interactive:!0,onClick:()=>t(`${n}.${i}`),icon:`duplicate`,className:`font-mono text-xs sm:text-sm py-1 px-3 self-start`,intent:I.PRIMARY,children:`${n}.${i}`})})}):(0,Z.jsx)(P,{intent:I.WARNING,icon:`warning-sign`,className:`text-xs`,children:d(`setup.androidIpNotice`,`检测到当前通过 IP 或本地地址访问面板。DoT / DoQ 仅接受域名,请在 .env 中配置 SERVERFULL_DOT_DOMAIN (例如 dns.example.com) 后刷新。`)})]})})(),!f&&(0,Z.jsx)(P,{intent:I.PRIMARY,icon:`info-sign`,className:`text-xs`,children:d(`setup.androidWarning`)})]})})]})]})};function Te({profileId:e,accessPoints:t,onRefresh:n,toasterRef:r}){let{t:i}=g(),[a,o]=(0,X.useState)(!1),[s,c]=(0,X.useState)(``),[l,u]=(0,X.useState)(!1),[d,f]=(0,X.useState)(null),[p,m]=(0,X.useState)(``),[h,_]=(0,X.useState)(!1),[v,y]=(0,X.useState)(null),[b,x]=(0,X.useState)(null),[S,C]=(0,X.useState)(!1),[w,T]=(0,X.useState)(!1),[E,D]=(0,X.useState)(null),[O,k]=(0,X.useState)(!1),[A,j]=(0,X.useState)(``);return{isAddDialogOpen:a,setIsAddDialogOpen:o,newApName:s,setNewApName:c,isAdding:l,renameApId:d,setRenameApId:f,renameApName:p,setRenameApName:m,isRenaming:h,rotatingApId:v,deletingApId:b,newApNameFocused:S,setNewApNameFocused:C,renameApNameFocused:w,setRenameApNameFocused:T,rotateConfirmApId:E,setRotateConfirmApId:D,isSearchOpen:O,setIsSearchOpen:k,searchQuery:A,setSearchQuery:j,filteredAccessPoints:t.filter(e=>e.name.toLowerCase().includes(A.toLowerCase())||e.token.toLowerCase().includes(A.toLowerCase())),isValidApName:e=>se.test(e),handleAdd:async()=>{let a=s.trim();if(a){if(t.some(e=>e.name.toLowerCase()===a.toLowerCase())){r.current?.show({message:i(`setup.accessPointNameExists`,`Access Point name already exists`),intent:I.DANGER});return}u(!0);try{await me(e,a),r.current?.show({message:i(`setup.accessPointCreated`),intent:I.SUCCESS}),o(!1),c(``),n()}catch(e){let t=e.message||`Failed to create access point`,n=t;if(t.startsWith(`Access point limit exceeded`)){let e=t.match(/\(max (\d+)\)/),r=e?e[1]:`100`;n=i(`setup.accessPointLimitExceeded`,{max:r,defaultValue:`Access Point limit exceeded (max ${r})`})}r.current?.show({message:n,intent:I.DANGER})}finally{u(!1)}}},handleRename:async()=>{let a=p.trim();if(!(!a||!d)){if(t.some(e=>e.id!==d&&e.name.toLowerCase()===a.toLowerCase())){r.current?.show({message:i(`setup.accessPointNameExists`,`Access Point name already exists`),intent:I.DANGER});return}_(!0);try{await fe(e,d,a),r.current?.show({message:i(`setup.accessPointRenamed`),intent:I.SUCCESS}),f(null),n()}catch(e){r.current?.show({message:e.message||`Failed to rename access point`,intent:I.DANGER})}finally{_(!1)}}},handleRotate:async t=>{y(t);try{await ue(e,t),r.current?.show({message:i(`setup.tokenRotated`),intent:I.SUCCESS}),n()}catch(e){console.error(e)}finally{y(null)}},handleDelete:async t=>{if(confirm(i(`setup.deleteAccessPointConfirm`))){x(t);try{await ge(e,t),r.current?.show({message:i(`setup.accessPointDeleted`),intent:I.SUCCESS}),n()}catch(e){console.error(e)}finally{x(null)}}}}}const Ee=({isOpen:e,onClose:t,newApName:n,setNewApName:r,newApNameFocused:i,setNewApNameFocused:a,handleAdd:o,isAdding:s,isValidApName:c})=>{let{t:l}=g();return(0,Z.jsxs)(j,{isOpen:e,onClose:t,title:l(`setup.addAccessPoint`),children:[(0,Z.jsx)(`div`,{className:O,children:(0,Z.jsx)(W,{content:l(`setup.accessPointNameFormatTip`,`1-30 characters, letters, numbers, hyphens and underscores allowed`),isOpen:i,position:E.TOP,intent:I.PRIMARY,className:`w-full`,children:(0,Z.jsx)(`div`,{className:`w-full block`,children:(0,Z.jsx)(z,{autoFocus:!0,large:!0,placeholder:l(`setup.accessPointName`),value:n,onChange:e=>r(e.target.value),onFocus:()=>a(!0),onBlur:()=>a(!1)})})})}),(0,Z.jsx)(`div`,{className:N,children:(0,Z.jsxs)(`div`,{className:G,children:[(0,Z.jsx)(A,{onClick:t,children:l(`common.cancel`,`Cancel`)}),(0,Z.jsx)(A,{intent:I.PRIMARY,onClick:o,loading:s,disabled:!c(n),children:l(`common.create`)})]})})]})},De=({isOpen:e,onClose:t,renameApName:n,setRenameApName:r,renameApNameFocused:i,setRenameApNameFocused:a,handleRename:o,isRenaming:s,isValidApName:c})=>{let{t:l}=g();return(0,Z.jsxs)(j,{isOpen:e,onClose:t,title:l(`setup.renameAccessPoint`),children:[(0,Z.jsx)(`div`,{className:O,children:(0,Z.jsx)(W,{content:l(`setup.accessPointNameFormatTip`,`1-30 characters, letters, numbers, hyphens and underscores allowed`),isOpen:i,position:E.TOP,intent:I.PRIMARY,className:`w-full`,children:(0,Z.jsx)(`div`,{className:`w-full block`,children:(0,Z.jsx)(z,{autoFocus:!0,large:!0,placeholder:l(`setup.accessPointName`),value:n,onChange:e=>r(e.target.value),onFocus:()=>a(!0),onBlur:()=>a(!1)})})})}),(0,Z.jsx)(`div`,{className:N,children:(0,Z.jsxs)(`div`,{className:G,children:[(0,Z.jsx)(A,{onClick:t,children:l(`common.cancel`,`Cancel`)}),(0,Z.jsx)(A,{intent:I.PRIMARY,onClick:o,loading:s,disabled:!c(n),children:l(`common.save`)})]})})]})},Oe=({ap:e,totalApCount:t,toasterRef:r,onRenameTrigger:i,rotateConfirmApId:a,setRotateConfirmApId:o,rotatingApId:s,handleRotate:c,deletingApId:u,handleDelete:d})=>{let{t:f}=g();return(0,Z.jsx)(H,{title:(0,Z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Z.jsx)(l,{size:16}),(0,Z.jsx)(`span`,{children:e.name})]}),className:`shadow-none! rounded-lg!`,children:(0,Z.jsxs)(L,{children:[(0,Z.jsxs)(`div`,{className:`space-y-3`,children:[(0,Z.jsxs)(`div`,{className:`flex justify-between items-start gap-4`,children:[(0,Z.jsx)(`span`,{className:`text-xs opacity-50 mt-1`,children:`DoH URL`}),(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 text-sm font-mono bg-blue-50 text-blue-600 dark:bg-blue-900/20 dark:text-blue-400 px-2 py-1 rounded cursor-pointer hover:bg-blue-100 dark:hover:bg-blue-900/40 transition-colors break-all`,onClick:()=>{navigator.clipboard.writeText(`${window.location.origin}/${e.token}`),r.current?.show({message:f(`setup.copied`),intent:I.SUCCESS})},title:f(`setup.copyUrl`),children:[(0,Z.jsx)(`span`,{className:`select-all`,children:`${window.location.origin}/${e.token}`}),(0,Z.jsx)(b,{size:14,className:`shrink-0`})]})]}),(0,Z.jsxs)(`div`,{className:`flex justify-between items-start gap-4`,children:[(0,Z.jsx)(`span`,{className:`text-xs opacity-50 mt-1`,children:f(`setup.accessPointToken`)}),(0,Z.jsx)(`span`,{className:`text-sm font-mono bg-gray-100 dark:bg-gray-800 px-2 py-1 rounded select-all break-all`,children:e.token})]}),(0,Z.jsxs)(`div`,{className:`flex justify-between items-start gap-4`,children:[(0,Z.jsx)(`span`,{className:`text-xs opacity-50 mt-1`,children:`Created`}),(0,Z.jsx)(`span`,{className:`text-sm`,children:le(new Date(e.created_at*1e3))})]})]}),(0,Z.jsxs)(`div`,{className:`mt-4 flex gap-2 flex-wrap`,children:[(0,Z.jsx)(A,{small:!0,icon:(0,Z.jsx)(m,{size:14}),text:f(`setup.renameAccessPoint`),onClick:()=>i(e.id,e.name)}),(0,Z.jsx)(F,{isOpen:a===e.id,onInteraction:e=>{e||o(null)},content:(0,Z.jsxs)(`div`,{className:`p-4 space-y-3 dark:bg-gray-800 dark:text-white max-w-xs`,children:[(0,Z.jsx)(`p`,{className:`text-xs font-semibold leading-relaxed`,children:f(`setup.rotateTokenConfirmDesc`,`Rotating the key will immediately disconnect devices using the old key. Are you sure you want to continue?`)}),(0,Z.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,Z.jsx)(A,{small:!0,minimal:!0,text:f(`common.cancel`,`Cancel`),onClick:()=>o(null)}),(0,Z.jsx)(A,{small:!0,intent:I.DANGER,text:f(`common.confirm`,`Confirm`),onClick:()=>{o(null),c(e.id)}})]})]}),placement:`top`,children:(0,Z.jsx)(A,{small:!0,icon:(0,Z.jsx)(p,{size:14}),text:f(`setup.rotateToken`),loading:s===e.id,onClick:()=>o(e.id)})}),(0,Z.jsx)(A,{small:!0,intent:I.DANGER,icon:(0,Z.jsx)(n,{size:14}),text:f(`setup.deleteAccessPoint`),loading:u===e.id,onClick:()=>d(e.id),disabled:t<=1,title:t<=1?`Cannot delete the only access point`:void 0})]})]})})},ke=({isOpen:e,onClose:t,profileId:n,isMobile:r,accessPoints:i,loading:o,onRefresh:s,toasterRef:c})=>{let{t:l}=g(),{isAddDialogOpen:u,setIsAddDialogOpen:d,newApName:f,setNewApName:p,isAdding:m,renameApId:h,setRenameApId:_,renameApName:v,setRenameApName:y,isRenaming:b,rotatingApId:x,deletingApId:C,newApNameFocused:w,setNewApNameFocused:T,renameApNameFocused:E,setRenameApNameFocused:D,rotateConfirmApId:O,setRotateConfirmApId:k,isSearchOpen:j,setIsSearchOpen:N,searchQuery:P,setSearchQuery:F,filteredAccessPoints:L,isValidApName:R,handleAdd:B,handleRename:V,handleRotate:H,handleDelete:U}=Te({profileId:n,accessPoints:i,onRefresh:s,toasterRef:c});return(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsxs)(_e,{isOpen:e,onClose:t,title:j?(0,Z.jsx)(z,{leftIcon:`search`,placeholder:l(`setup.searchAccessPoints`,`Search...`),value:P,onChange:e=>F(e.target.value),rightElement:(0,Z.jsx)(A,{icon:`cross`,minimal:!0,onClick:()=>{N(!1),F(``)}}),autoFocus:!0}):(0,Z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Z.jsx)(`span`,{children:l(`setup.manageAccessPoints`)}),(0,Z.jsx)(A,{icon:(0,Z.jsx)(a,{size:14}),minimal:!0,onClick:()=>N(!0),className:`opacity-50 hover:opacity-100`})]}),icon:`diagram-tree`,size:r?`100%`:`450px`,children:[(0,Z.jsx)(A,{fill:!0,intent:I.PRIMARY,icon:(0,Z.jsx)(S,{size:16}),text:l(`setup.addAccessPoint`),onClick:()=>d(!0),large:!0}),o?(0,Z.jsx)(`div`,{className:`flex justify-center p-8`,children:(0,Z.jsx)(M,{})}):(0,Z.jsx)(`div`,{className:`space-y-4 mt-4`,children:L.map(e=>(0,Z.jsx)(Oe,{ap:e,totalApCount:i.length,toasterRef:c,onRenameTrigger:(e,t)=>{_(e),y(t)},rotateConfirmApId:O,setRotateConfirmApId:k,rotatingApId:x,handleRotate:H,deletingApId:C,handleDelete:U},e.id))})]}),(0,Z.jsx)(Ee,{isOpen:u,onClose:()=>{d(!1),p(``)},newApName:f,setNewApName:p,newApNameFocused:w,setNewApNameFocused:T,handleAdd:B,isAdding:m,isValidApName:R}),(0,Z.jsx)(De,{isOpen:!!h,onClose:()=>_(null),renameApName:v,setRenameApName:y,renameApNameFocused:E,setRenameApNameFocused:D,handleRename:V,isRenaming:b,isValidApName:R})]})},Ae=({profileId:e,profileKey:t,profileName:n,toasterRef:r})=>{let i=ce(),{t:a}=g(),[o,s]=(0,X.useState)([]),[c,l]=(0,X.useState)(!1),[u,d]=(0,X.useState)(!1),[f,p]=(0,X.useState)(null),m=async()=>{l(!0);try{s(await de(e))}catch(e){console.error(e)}finally{l(!1)}};(0,X.useEffect)(()=>{m()},[e]);let[h,_]=(0,X.useState)(n||``);(0,X.useEffect)(()=>{n?_(n):e&&pe(e).then(e=>{e?.name&&_(e.name)}).catch(()=>{})},[e,n]);let v=(0,X.useMemo)(()=>o.length===0?null:o.find(e=>e.id===f)||o[0],[o,f]),y=v?v.token:t,b=v?v.name:void 0,x=`${window.location.origin}/${y}`,[S,C]=(0,X.useState)(null),[w,T]=(0,X.useState)(!1),[E,D]=(0,X.useState)(!1),[O,k]=(0,X.useState)(!1),[A,j]=(0,X.useState)(null),[M,N]=(0,X.useState)(null),[P,F]=(0,X.useState)({ipv4:[],ipv6:[]}),[L,R]=(0,X.useState)(null),z=e=>{navigator.clipboard.writeText(e),r?.current?.show({message:a(`setup.copied`),intent:I.SUCCESS})},B=async()=>{T(!0),R(null);try{let[t,n]=await Promise.all([te(),re()]);if(t.ip&&(t.country===`UNKNOWN`||!t.country))try{let e=await fetch(`/api/geoip?ip=${encodeURIComponent(t.ip)}`);if(e.ok){let n=await e.json();n.success&&(n.country&&(t.country=n.country),n.region&&(t.region=n.region),n.city&&(t.city=n.city),n.timezone?.id&&(t.timezone=n.timezone.id),n.connection?.org&&(t.asOrganization=n.connection.org))}}catch{}C(t),j(n),t.timezone&&t.timezone!==`UNKNOWN`&&oe(t.timezone);let r=window.location.hostname===`localhost`||window.location.hostname===`127.0.0.1`||window.location.hostname===`::1`||window.location.hostname.startsWith(`192.168.`)||window.location.hostname.startsWith(`10.`)||/^172\.(1[6-9]|2\d|3[01])\./.test(window.location.hostname),i=!!(t.dotDomain&&!J(t.dotDomain));ie(r&&i||i?t.dotDomain:window.location.hostname||``).then(e=>N(e)).catch(e=>console.warn(`Failed fetching domain geo location:`,e));let a=t.substituteDomain||`www.okx.com`;ae().then(e=>{F(t=>t.ipv4.length>0||t.ipv6.length>0?t:{ipv4:e.ip?[e.ip]:[],ipv6:e.ipv6?[e.ipv6]:[]})}).catch(()=>{}),ne(a).then(e=>{(e.ipv4.length>0||e.ipv6.length>0)&&F(e)}).catch(e=>console.warn(`Failed resolving substitute domain DNS IPs:`,e)),R({success:!!t.connectedProfileId,profileMatch:t.connectedProfileId===e})}catch(e){console.error(`Verification failed`,e)}finally{T(!1)}};(0,X.useEffect)(()=>{B()},[e]);let V=(0,X.useMemo)(()=>{let e=[],t=(P.ipv4||[]).slice(0,2),n=(P.ipv6||[]).slice(0,2),r=S?.substituteDomain||`www.okx.com`;for(let n of t)e.push({ip:n,area:`${r} IPv4`});for(let t of n)e.push({ip:t,area:`${r} IPv6`});return e},[P,S?.substituteDomain]);return(0,Z.jsxs)(`div`,{className:`mx-auto space-y-8 pb-24 ${i?`p-1`:`px-8 max-w-5xl`}`,children:[(0,Z.jsx)(ve,{isMobile:i}),(0,Z.jsx)(ye,{isVerifying:w,verifyResult:L,handleVerify:B,isMobile:i,clientInfo:S,showIp:E,setShowIp:D,showLocation:O,setShowLocation:k,traceInfo:A,edgeLocation:M}),(0,Z.jsx)(be,{accessPoints:o,selectedApId:v?.id||null,onSelectAp:p,accessPointName:b,onManageAccessPoints:()=>d(!0),isMobile:i}),(0,Z.jsx)(xe,{dohUrl:x,copyToClipboard:z,isMobile:i}),(0,Z.jsx)(we,{isMobile:i,copyToClipboard:z,profileKey:y,profileName:h||void 0,accessPointName:b,currentIps:V,dotDomain:S?.dotDomain}),(0,Z.jsx)(ke,{isOpen:u,onClose:()=>d(!1),profileId:e,isMobile:i,accessPoints:o,loading:c,onRefresh:m,toasterRef:r})]})};export{Ae as SetupView};