1import{r as h,j as e}from"./framer-vendor-BQFVqQmJ.js";import{h as bt,a5 as _t,a as xe,V as Ut,l as oe,R as Qe,X as Et,U as Be,Q as Ie,T as Bt}from"./index-CjIeyhK0.js";import{a as It}from"./liveActivity-DKHu-sXK.js";import{C as te}from"./check-circle-2-DvlBosaH.js";import{C as dt}from"./crown-DOUSA71V.js";import{U as xt}from"./user-check-BG9IP48S.js";import{E as Ot}from"./eye-Dzwwx7Jl.js";import{Z as mt}from"./zap-CrB2r0X1.js";import{T as Pt}from"./trending-up-CBXZ7X3x.js";import{T as Ft}from"./trophy-CjAyKyz6.js";import{H as Vt}from"./hourglass-CgRlmnM2.js";import{G as Ht}from"./gift-DFLVEdfq.js";import{M as zt}from"./megaphone-C-3vIJYl.js";import{R as ye,A as Kt,C as be,X as _e,Y as de,T as je,g as Se,f as Oe,B as Ze,h as ve,L as ut,d as Je}from"./chart-vendor-D7KebX4S.js";import{S as qt}from"./smartphone-Cnp5Ll-i.js";import{M as pt}from"./monitor-DD4BE59Z.js";import{G as Wt}from"./globe-CwrWhgGd.js";import{M as Ce}from"./minus-COdirOrM.js";import{A as Pe}from"./arrow-up-right-Cuz5u52B.js";import{A as Fe}from"./arrow-down-right-ChiQ83wo.js";import{C as Gt}from"./chevron-down-BDx2E2SM.js";import"./supabase-vendor-DJa18kbt.js";/** 2 * @license lucide-react v0.344.0 - ISC 3 * 4 * This source code is licensed under the ISC license. 5 * See the LICENSE file in the root directory of this source tree. 6 */const Yt=bt("CalendarX",[["path",{d:"M8 2v4",key:"1cmpym"}],["path",{d:"M16 2v4",key:"4m81vk"}],["rect",{width:"18",height:"18",x:"3",y:"4",rx:"2",key:"1hopcy"}],["path",{d:"M3 10h18",key:"8toen8"}],["path",{d:"m14 14-4 4",key:"rymu2i"}],["path",{d:"m10 14 4 4",key:"3sz06r"}]]);/** 7 * @license lucide-react v0.344.0 - ISC 8 * 9 * This source code is licensed under the ISC license. 10 * See the LICENSE file in the root directory of this source tree. 11 */const Xt=bt("MousePointer",[["path",{d:"m3 3 7.07 16.97 2.51-7.39 7.39-2.51L3 3z",key:"y2ucgo"}],["path",{d:"m13 13 6 6",key:"1nhxnf"}]]);function Qt(s=10*60*1e3){const[n,a]=h.useState(null),r=h.useRef(new Map),c=h.useRef(null),l=h.useRef(null);function o(p){return p.device_id||p.session_token||p.id||""}function f(){const p=Date.now()-s;let u=0;r.current.forEach(x=>{x>=p&&u++}),a(u)}return h.useEffect(()=>{const p=_t();p.rpc("get_online_members",{p_limit:200}).then(({data:x})=>{const j=x==null?void 0:x.members;Array.isArray(j)&&(j.forEach(g=>{const m=g,b=o(m);b&&typeof m.last_seen=="string"&&r.current.set(b,new Date(m.last_seen).getTime())}),f())});const u=p.channel("admin-online-count").on("postgres_changes",{event:"*",schema:"public",table:"user_sessions"},x=>{const j=x.new??x.old??{},g=o(j);g&&(x.eventType==="DELETE"?r.current.delete(g):j.last_seen&&r.current.set(g,new Date(j.last_seen).getTime()),f())}).subscribe();return c.current=u,l.current=setInterval(()=>{const x=Date.now()-s;let j=!1;r.current.forEach((g,m)=>{g<x&&(r.current.delete(m),j=!0)}),j&&f()},6e4),()=>{p.removeChannel(u),l.current&&clearInterval(l.current)}},[s]),n}function O(){return _t()}function Zt(){try{return!!localStorage.getItem("admin_session_token")}catch{return!1}}const Jt=new Set(["staff","giveaway"]),es=new Set(["kol","partner","marketing"]);function ts(s){const n={customerActivated:0,customerPending:0,adminGrant:0,kolPartner:0};for(const a of s){const r=a.holder_type||"";a.plan_type==="99999_days"||Jt.has(r)?n.adminGrant++:es.has(r)?n.kolPartner++:a.is_used?n.customerActivated++:n.customerPending++}return n}function ss(s){return s?/ipad|tablet/i.test(s)?"Tablet":/mobile|android|iphone/i.test(s)?"Mobile":"Desktop":"Unknown"}function as(s){return s?s.includes("Edg")?"Edge":s.includes("Chrome")&&!s.includes("Edg")?"Chrome":s.includes("Safari")&&!s.includes("Chrome")?"Safari":s.includes("Firefox")?"Firefox":s.includes("Opera")||s.includes("OPR")?"Opera":"Other":"Unknown"}function Ne(s){return s.device_id||s.session_token||s.id||""}function Ae(s){const n=new Map;return s.forEach(a=>{const r=Ne(a);if(!r)return;const c=n.get(r),l=a.last_seen||a.created_at||"",o=(c==null?void 0:c.last_seen)||(c==null?void 0:c.created_at)||"";(!c||l>o)&&n.set(r,a)}),Array.from(n.values())}function et(s){if(!s)return"UNKNOWN";const n=s.toUpperCase().replace("/",""),a=n.indexOf("."),r=n.indexOf("#"),c=[a,r].filter(o=>o>=0),l=c.length>0?Math.min(...c):-1;return(l>=0?n.slice(0,l):n).replace(/[^A-Z0-9]/g,"")}async function rs(){const s=O(),n=new Date,a=new Date(n.getTime()-24*60*60*1e3).toISOString(),r=new Date(n.getTime()-7*24*60*60*1e3).toISOString(),c=new Date(n.getTime()-10*60*1e3).toISOString(),[l,o,f,p,u,x,j]=await Promise.all([s.from("user_sessions").select("id, device_id, session_token, vip_code, is_vip, last_seen, created_at, total_time_spent, page_views, signals_viewed, charts_viewed").order("last_seen",{ascending:!1}).limit(5e3),s.from("user_sessions").select("id, device_id, session_token, is_vip, vip_code").gte("last_seen",c),s.from("user_sessions").select("id, device_id, session_token").gte("last_seen",a),s.from("user_sessions").select("id, device_id, session_token").gte("last_seen",r),s.from("vip_codes").select("id, expires_at, is_used, is_active, is_deleted, plan_type, holder_type"),s.from("signal_history").select("id",{count:"estimated",head:!0}),s.from("processed_payments").select("id",{count:"exact",head:!0}).eq("payment_type","vip_renewal")]),g=l.data||[],m=o.data||[],b=f.data||[],Z=p.data||[],J=(u.data||[]).filter(w=>w.is_active!==!1&&!w.is_deleted),A=new Set(b.map(w=>
11Ne(w)).filter(Boolean)),ke=new Set(Z.map(w=>Ne(w)).filter(Boolean)),_=new Set(m.map(w=>Ne(w)).filter(Boolean)),N=J.filter(w=>new Date(w.expires_at)>n),U=N.length,E=J.filter(w=>new Date(w.expires_at)<=n).length,I=g.reduce((w,z)=>w+(z.page_views||0),0),me=g.reduce((w,z)=>w+(z.signals_viewed||0),0),W=g.reduce((w,z)=>w+(z.charts_viewed||0),0),ue=g.reduce((w,z)=>w+(z.total_time_spent||0),0),D=g.length>0?ue/g.length:0,$e=J.filter(w=>w.is_used).length,se=$e,{count:Ve}=await s.from("trade_executions").select("id",{count:"exact",head:!0}),G=$e;return{totalUsers:G,activeUsers24h:A.size,activeUsers7d:ke.size,onlineNow:_.size,totalVipCodes:J.length,activeVipCodes:U,activeVipBreakdown:ts(N),expiredVipCodes:E,renewPaid:j.count||0,totalPageViews:I,totalSignalsViewed:me,totalChartsViewed:W,avgSessionDuration:D,totalTrades:Ve||0,totalSignals:x.count||0,vipUsers:se,guestUsers:Math.max(0,G-se)}}async function ns(s=30){const n=O(),a=new Date(Date.now()-s*24*60*60*1e3).toISOString(),r=new Date().toISOString(),[c,l,o]=await Promise.all([n.from("user_sessions").select("id, device_id, session_token, created_at, last_seen").gte("created_at",a).order("created_at",{ascending:!0}),n.from("vip_codes").select("id, expires_at").eq("is_active",!0).or("is_deleted.is.null,is_deleted.eq.false").gte("expires_at",a).lte("expires_at",r),n.from("processed_payments").select("id, created_at").eq("payment_type","vip_renewal").gte("created_at",a)]),f=c.data||[],p=l.data||[],u=o.data||[],x=new Map;for(let g=0;g<s;g++){const b=new Date(Date.now()-(s-1-g)*24*60*60*1e3).toISOString().slice(0,10);x.set(b,{newUsers:0,activeUsers:new Set,expiredUsers:0,renewals:0})}const j=new Map;return f.forEach(g=>{const m=Ne(g);if(!m||!g.created_at)return;const b=j.get(m);(!b||g.created_at<b)&&j.set(m,g.created_at)}),j.forEach(g=>{const m=g.slice(0,10);m&&x.has(m)&&x.get(m).newUsers++}),f.forEach(g=>{var Z;const m=Ne(g);if(!m)return;const b=(Z=g.last_seen)==null?void 0:Z.slice(0,10);b&&x.has(b)&&x.get(b).activeUsers.add(m)}),p.forEach(g=>{var b;const m=(b=g.expires_at)==null?void 0:b.slice(0,10);m&&x.has(m)&&x.get(m).expiredUsers++}),u.forEach(g=>{var b;const m=(b=g.created_at)==null?void 0:b.slice(0,10);m&&x.has(m)&&x.get(m).renewals++}),Array.from(x.entries()).map(([g,m])=>({date:g,label:new Date(g).toLocaleDateString("en",{month:"short",day:"numeric"}),newUsers:m.newUsers,activeUsers:m.activeUsers.size,expiredUsers:m.expiredUsers,renewals:m.renewals}))}async function ls(){const s=O(),{data:n}=await s.from("user_sessions").select("id, device_id, session_token, created_at, last_seen, user_agent"),a=Ae(n||[]),r=new Map;a.forEach(l=>{const o=ss(l.user_agent);r.set(o,(r.get(o)||0)+1)});const c=Array.from(r.values()).reduce((l,o)=>l+o,0);return Array.from(r.entries()).map(([l,o])=>({type:l,count:o,percentage:c>0?Math.round(o/c*100):0})).sort((l,o)=>o.count-l.count)}async function is(){const s=O(),{data:n}=await s.from("user_sessions").select("id, device_id, session_token, created_at, last_seen, user_agent"),a=Ae(n||[]),r=new Map;a.forEach(l=>{const o=as(l.user_agent);r.set(o,(r.get(o)||0)+1)});const c=Array.from(r.values()).reduce((l,o)=>l+o,0);return Array.from(r.entries()).map(([l,o])=>({browser:l,count:o,percentage:c>0?Math.round(o/c*100):0})).sort((l,o)=>o.count-l.count)}async function cs(){const s=O(),{data:n}=await s.from("user_sessions").select("id, device_id, session_token, created_at, last_seen, location"),a=Ae(n||[]),r=new Map;a.forEach(l=>{const o=l.location||"Unknown";r.set(o,(r.get(o)||0)+1)});const c=Array.from(r.values()).reduce((l,o)=>l+o,0);return Array.from(r.entries()).map(([l,o])=>({location:l,count:o,percentage:c>0?Math.round(o/c*100):0})).sort((l,o)=>o.count-l.count).slice(0,15)}async function os(){const s=O(),n=new Date(Date.now()-24*60*60*1e3).toISOString(),{data:a}=await s.from("user_sessions").select("last_seen").gte("last_seen",n),r=new Array(24).fill(0);return(a||[]).forEach(c=>{if(c.last_seen){const l=new Date(c.last_seen).getHours();r[l]++}}),r.map((c,l)=>({hour:l,label:`${l.toString().padStart(2,"0")}:00`,sessions:c}))}async function ds(){const s=O(),n=new Date,a=new Date(n);a.setMinutes(0,0,0);const r=new Date(a);r.setHours(r.getHours()+1);const c=new Date(a);c.setDate(c.getDate()-1);const l=new Date(r);l.setDate(l.getDate()-1);const[o,f]=await Promise.all([s.from("user_sessions").select("id, device_id, session_token, created_at, last_seen").gte("last_seen",a.toISOString()).lt("last_seen",r.toISOString()),s.from("user_sessions").select("id, device_id, session_token, created_at, last_seen").gte("last_seen",c.toISOString()).lt("last_seen",l.toISOString())]),p=Ae(o.data||[]).length,u=Ae(f.data||[]).length,x=u>0?p/u:p>0?p:1;return{currentHourUsers:p,yesterdaySameHourUsers:u,ratioVsYesterday:Math.round(x*100)/100,hourLabel:`${a.getHours().toString().padStart(2,"0")}:00`}}async function xs(s=10){const n=O(),{data:a}=await n.from("vip_code_usage_stats").select("*").gt("unique_devices_all_time",0).order("unique_devices_all_time",{ascending:!1}).limit(s);return(a||[]).map(r=>({code:r.vip_code,notes:r.notes,accountType:r.account_type,uniqueDevices:r.unique_devices_all_time,totalSessions:r.total_sessions,lastActivity:r.last_activity}))}async function ms(){const s=O(),{data:n}=await s.from("user_sessions").select("page_views, signals_viewed, charts_viewed, total_time_spent, device_id"),a=n||[],r=a.length||1,c=a.reduce((m,b)=>m+(b.page_views||0),0)/r,l=a.reduce((m,b)=>m+(b.signals_viewed||0),0)/r,o=a.reduce((m,b)=>m+(b.charts_viewed||0),0)/r,f=a.reduce((m,b)=>m+(b.total_time_spent||0),0)/r,u=a.filter(m=>(m.page_views||0)<=1&&(m.total_time_spent||0)<30).length/r*100,x=new Map;a.forEach(m=>{m.device_id&&x.set(m.device_id,(x.get(m.device_id)||0)+1)});const j=Array.from(x.values()).filter(m=>m>1).length,g=x.size||1;return{avgPageViews:Math.round(c*10)/10,avgSignalsViewed:Math.round(l*10)/10,avgChartsViewed:Math.round(o*10)/10,avgTimeSpent:Math.round(f),bounceRate:Math.round(u*10)/10,returningUsers:j,returningRate:Math.round(j/g*1e3)/10}}async function us(s=7){const n=O(),a=new Date(Date.now()-s*24*60*60*1e3).toISOString(),[r,c]=await Promise.all([n.from("signal_broadcasts").select("asset,
11created_at").gte("created_at",a),n.from("metaapi_trades").select("symbol, status, created_at").gte("created_at",a)]),l=new Map;(r.data||[]).forEach(p=>{const u=et(p.asset);l.set(u,(l.get(u)||0)+1)});const o=new Map;(c.data||[]).forEach(p=>{const u=String(p.status||"").toLowerCase();if(!["executed","closed","filled"].includes(u))return;const x=et(p.symbol);o.set(x,(o.get(x)||0)+1)});const f=new Set([...l.keys(),...o.keys()]);return Array.from(f).map(p=>{const u=l.get(p)||0,x=o.get(p)||0,j=u>0?Math.round(x/u*1e3)/10:0,g=Math.max(0,u-x);return{asset:p,broadcasts:u,executions:x,conversionRate:j,dropOff:g}}).filter(p=>p.broadcasts>0||p.executions>0).sort((p,u)=>u.broadcasts-p.broadcasts).slice(0,12)}async function ps(s=7){if(!Zt())return[];const n=O(),a=new Date(Date.now()-s*24*60*60*1e3).toISOString(),{data:r,error:c}=await n.from("auto_trade_account_monitor_logs").select("asset, account_status, account_reason, created_at").gte("created_at",a);if(c||!r)return[];const l=new Map;return r.forEach(o=>{const f=et(o.asset),p=String(o.account_status||"").toLowerCase();l.has(f)||l.set(f,{attempts:0,blocked:0,executed:0,errors:0,reasonCount:new Map});const u=l.get(f);if(u.attempts++,p==="blocked"){u.blocked++;const x=String(o.account_reason||"Unknown reason").slice(0,140);u.reasonCount.set(x,(u.reasonCount.get(x)||0)+1)}else p==="executed"?u.executed++:u.errors++}),Array.from(l.entries()).map(([o,f])=>{var u;const p=((u=Array.from(f.reasonCount.entries()).sort((x,j)=>j[1]-x[1])[0])==null?void 0:u[0])||"-";return{asset:o,attempts:f.attempts,blocked:f.blocked,executed:f.executed,errors:f.errors,topBlockReason:p}}).sort((o,f)=>f.blocked-o.blocked).slice(0,15)}async function hs(s=1,n=250){const{data:a,error:r}=await xe("admin_anti_flip_blocks_hourly",{p_days:Math.max(1,s),p_limit:Math.max(10,Math.min(n,1e3))});return r||!a?[]:a.map(c=>({hourBucket:String(c.hour_bucket||""),reasonCode:String(c.reason_code||"").toLowerCase()==="duplicate_alias_cooldown"?"duplicate_alias_cooldown":"anti_flip_cooldown",accountId:String(c.account_id||"unknown"),vipCode:String(c.vip_code||"unknown"),broker:String(c.broker||"unknown"),blockedCount:Number(c.blocked_count||0)}))}async function gs(){const s=O(),n=new Date(Date.now()-7*864e5).toISOString(),a=new Date(Date.now()-864e5).toISOString(),r=new Date(Date.now()-14*864e5).toISOString(),[c,l,o]=await Promise.all([s.from("user_behavior_events").select("event_type, event_target, device_id").gte("created_at",n),s.from("user_behavior_events").select("id",{count:"exact",head:!0}).gte("created_at",a),s.from("user_behavior_events").select("event_type, event_target, device_id").gte("created_at",r).lt("created_at",n)]),f=c.data||[],p=o.data||[],u=new Set(f.map(_=>_.device_id)).size;function x(_,N){const U=new Map;return _.filter(E=>E.event_type===N).forEach(E=>{const I=U.get(E.event_target)||{count:0,users:new Set};I.count++,I.users.add(E.device_id),U.set(E.event_target,I)}),U}function j(_,N,U,E){var W;const I=N.filter(ue=>ue.event_type===U&&ue.event_target===E).length,me=((W=_.get(E))==null?void 0:W.count)||0;return me>I*1.1?"up":me<I*.9?"down":"stable"}const g=x(f,"feature_use"),m=Array.from(g.entries()).sort((_,N)=>N[1].count-_[1].count).slice(0,10).map(([_,N])=>({feature:_,count:N.count,uniqueUsers:N.users.size,trend:j(g,p,"feature_use",_)})),b=x(f,"page_view"),Z=Array.from(b.entries()).sort((_,N)=>N[1].count-_[1].count).slice(0,10).map(([_,N])=>({feature:_,count:N.count,uniqueUsers:N.users.size,trend:j(b,p,"page_view",_)})),H=x(f,"chart_view"),J=x(f,"signal_view"),A=new Map;[H,J].forEach(_=>{_.forEach((N,U)=>{const E=A.get(U)||{count:0,users:new Set};E.count+=N.count,N.users.forEach(I=>E.users.add(I)),A.set(U,E)})});const ke=Array.from(A.entries()).sort((_,N)=>N[1].count-_[1].count).slice(0,10).map(([_,N])=>({feature:_,count:N.count,uniqueUsers:N.users.size,trend:"stable"}));return{topFeatures:m,topPages:Z,topAssets:ke,totalEvents7d:f.length,totalEvents24h:l.count||0,avgEventsPerUser:u>0?Math.round(f.length/u):0}}async function fs(s=3,n=200){const a=O(),{data:r,error:c}=await a.from("v_news_article_extraction_domain_metrics").select("*").gte("total_attempts",s).order("total_attempts",{ascending:!1}).limit(n);return c||!r?[]:r.map(l=>({domain:String(l.domain||""),totalAttempts:Number(l.total_attempts||0),successfulExtractions:Number(l.successful_extractions||0),goodExtractions:Number(l.good_extractions||0),successRatePct:Number(l.success_rate_pct||0),goodExtractionRatePct:Number(l.good_extraction_rate_pct||0),domPrimaryCount:Number(l.dom_primary_count||0),domHeuristicCount:Number(l.dom_heuristic_count||0),readerFallbackCount:Number(l.reader_fallback_count||0),rawHtmlFallbackCount:Number(l.raw_html_fallback_count||0),summaryFallbackCount:Number(l.summary_fallback_count||0),avgContentLength:Number(l.avg_content_length||0),maxContentLength:Number(l.max_content_length||0),lastContentLength:Number(l.last_content_length||0),lastExtractionMode:String(l.last_extraction_mode||"-"),lastHttpStatus:l.last_http_status==null?null:Number(l.last_http_status),lastSeenAt:String(l.last_seen_at||"")}))}async function ys(s=7){const{data:n,error:a}=await xe("admin_assistant_tool_access_matrix",{p_days:s});return a||!n?[]:n.map(r=>({metric_date:String(r.metric_date||""),resolved_feature:String(r.resolved_feature||"unknown"),target_tab:String(r.target_tab||"unknown"),toolbox_tab:String(r.toolbox_tab||"none"),total_attempts:Number(r.total_attempts||0),successful_attempts:Number(r.successful_attempts||0),failed_attempts:Number(r.failed_attempts||0),pass_rate_percent:Number(r.pass_rate_percent||0)}))}async function bs(s=30){const{data:n,error:a}=await xe("admin_assistant_tool_access_coverage",{p_days:s});return a||!n?[]:n.map(r=>({metric_date:String(r.metric_date||""),matrix_cells:Number(r.matrix_cells||0),total_attempts:Number(r.total_attempts||0),successful_attempts:Number(r.successful_attempts||0),failed_attempts:Number(r.failed_attempts||0),pass_rate_percent:Number(r.pass_rate_percent||0),healthy_cells:Number(r.healthy_cells||0),warning_cells:Number(r.warning_cells||0),critical_cells:Number(r.critical_cells||0)}
11))}async function _s(s=7,n=50){const{data:a,error:r}=await xe("admin_assistant_tool_failure_reasons",{p_days:s,p_limit:n});return r||!a?[]:a.map(c=>({resolved_feature:String(c.resolved_feature||"unknown"),failure_reason:String(c.failure_reason||"unknown"),fail_count:Number(c.fail_count||0),distinct_users:Number(c.distinct_users||0),sample_vip_code:String(c.sample_vip_code||""),last_seen:String(c.last_seen||""),sample_command:String(c.sample_command||""),resolved_at:c.resolved_at?String(c.resolved_at):null}))}async function js(s,n,a=!0,r=null){const{error:c}=await xe("admin_resolve_tool_failure",{p_feature:s,p_reason:n,p_resolved:a,p_note:r});return!c}async function vs(s=7,n=20){const{data:a,error:r}=await xe("admin_assistant_verification_top_conflicts",{p_days:s,p_limit:n});return r||!a?[]:a.map(c=>({conflict_type:String(c.conflict_type||"unknown"),conflict_count:Number(c.conflict_count||0),affected_logs:Number(c.affected_logs||0),avg_confidence:Number(c.avg_confidence||0),recent_seen:String(c.recent_seen||"")}))}async function Ns(){const{data:s,error:n}=await xe("admin_assistant_verification_conflict_daily",{p_days:30});return n||!s?[]:s.map(a=>({metric_date:String(a.metric_date||""),conflict_type:String(a.conflict_type||"unknown"),conflict_count:Number(a.conflict_count||0),affected_logs:Number(a.affected_logs||0),avg_confidence:Number(a.avg_confidence||0)}))}const ks={Desktop:"#3b82f6",Mobile:"#10b981",Tablet:"#f59e0b",Unknown:"#6b7280"},ws={Chrome:"#22c55e",Safari:"#3b82f6",Firefox:"#f97316",Edge:"#06b6d4",Opera:"#ef4444",Other:"#6b7280",Unknown:"#374151"};function ht(s){return s<60?`${Math.round(s)}s`:s<3600?`${Math.floor(s/60)}m ${Math.round(s%60)}s`:`${Math.floor(s/3600)}h ${Math.floor(s%3600/60)}m`}function R(s){return s>=1e6?`${(s/1e6).toFixed(1)}M`:s>=1e3?`${(s/1e3).toFixed(1)}K`:s.toLocaleString()}function Ss(s){const n=(s||"").toLowerCase();return n.includes("à¹à¸¡à¹à¸£à¸¹à¹à¸à¸±à¸à¸ªà¸´à¸à¸à¸£à¸±à¸à¸¢à¹")||n.includes("unknown asset")?{kind:"expected",text:"à¸à¸¹à¹à¹à¸à¹à¸à¸à¸ªà¸´à¸à¸à¸£à¸±à¸à¸¢à¹à¸à¸µà¹à¸£à¸°à¸à¸à¸¢à¸±à¸à¹à¸¡à¹à¸£à¸à¸à¸£à¸±à¸ â à¸à¸³à¸à¸²à¸à¸à¸¹à¸à¸à¹à¸à¸ à¹à¸¡à¹à¹à¸à¹à¸à¸±à¹à¸ à¹à¸à¸´à¹à¸¡à¸ªà¸´à¸à¸à¸£à¸±à¸à¸¢à¹/alias à¹à¸à¹à¸à¹à¸²à¸¡à¸µà¸à¸µà¸¡à¸²à¸à¸à¹"}:n.includes("à¹à¸¡à¹à¸£à¸¹à¹à¸à¸±à¸à¸à¸³à¸ªà¸±à¹à¸")||n.includes("unknown command")?{kind:"expected",text:"à¹à¸¡à¹à¸à¸¥à¹à¸£à¸µà¸¢à¸ action à¸à¸µà¹à¸¢à¸±à¸à¹à¸¡à¹à¹à¸à¹ register (à¹à¸à¸à¸à¸µà¹à¸£à¸à¸à¸£à¸±à¸à¸¢à¸±à¸à¹à¸¡à¹à¹à¸à¸´à¸à¸à¸à¸à¸à¸±à¹à¸)"}:n.includes("onnavigate_not_available")?{kind:"bug",text:"à¹à¸à¸à¸à¸¥à¸²à¸¢à¸à¸²à¸à¸¢à¸±à¸à¹à¸¡à¹à¸à¸£à¹à¸à¸¡ (onNavigate à¹à¸¡à¹à¸à¸¹à¸à¸ªà¹à¸à¹à¸à¹à¸²à¸¡à¸²) â สัà¹à¸à¸à¹à¸à¸ Dashboard mount"}:n.includes("toolbox_tab_persist_failed")?{kind:"bug",text:"à¸à¸±à¸à¸à¸¶à¸à¹à¸à¹à¸ Toolbox ลภlocalStorage à¹à¸¡à¹à¹à¸à¹ (à¹à¸«à¸¡à¸à¸ªà¹à¸§à¸à¸à¸±à¸§/à¸à¸·à¹à¸à¸à¸µà¹à¹à¸à¹à¸¡)"}:!n||n==="unknown"?{kind:"bug",text:"à¹à¸¡à¹à¸¡à¸µ failure_reason à¸à¸¹à¸à¸à¸±à¸à¸à¸¶à¸ â à¸à¸£à¸§à¸ path à¸à¸µà¹ log fail"}:{kind:"bug",text:"à¸à¹à¸à¸à¸´à¸à¸à¸¥à¸²à¸à¸à¸²à¸à¸à¸±à¸§ handler â à¸à¸¹ reason + à¸à¸³à¸ªà¸±à¹à¸à¸¥à¹à¸²à¸ªà¸¸à¸à¹à¸à¸·à¹à¸ reproduce"}}const Cs={direction_conflict_bias_vs_trend:"AI à¸à¸µà¹à¸à¸´à¸¨à¸ªà¸§à¸à¹à¸à¸£à¸à¸à¹à¸à¸²à¸à¹à¸à¸à¸à¸´à¸",direction_conflict_bias_vs_ema:"AI à¸à¸µà¹à¸à¸´à¸¨à¸ªà¸§à¸à¸à¸²à¸£à¹à¸£à¸µà¸¢à¸à¸à¸±à¸§à¸à¸à¸ EMA",direction_conflict_bias_vs_macd:"AI à¸à¸µà¹à¸à¸´à¸¨à¸ªà¸§à¸ MACD (histogram à¸à¸à¸¥à¸°à¸à¸±à¹à¸)",direction_conflict_bias_vs_smc:"AI à¸à¸µà¹à¸à¸´à¸¨à¸ªà¸§à¸à¹à¸à¸£à¸à¸ªà¸£à¹à¸²à¸ SMC (smart money)",direction_conflict_buy_vs_realtime:"AI à¹à¸à¸à¸à¸±à¹à¸ BUY à¹à¸à¹à¸à¹à¸à¸¡à¸¹à¸¥à¸ªà¸à¹à¸à¸ bearish",direction_conflict_sell_vs_realtime:"AI à¹à¸à¸à¸à¸±à¹à¸ SELL à¹à¸à¹à¸à¹à¸à¸¡à¸¹à¸¥à¸ªà¸à¹à¸à¸ bullish",rsi_overbought_vs_bullish:"AI à¸à¸à¸à¸à¸¶à¹à¸ à¸à¸±à¹à¸à¸à¸µà¹ RSI overbought (â¥70) à¹à¸¥à¹à¸§ â à¹à¸¥à¹à¸¢à¸à¸",rsi_oversold_vs_bearish:"AI à¸à¸à¸à¸¥à¸ à¸à¸±à¹à¸à¸à¸µà¹ RSI oversold (â¤30) à¹à¸¥à¹à¸§ â à¹à¸¥à¹à¸à¹à¸",setup_invali
11d_sl_for_buy:"à¸à¸±à¹à¸ SL à¸à¸´à¸à¸à¸±à¹à¸à¸ªà¸³à¸«à¸£à¸±à¸ BUY (SL à¸à¸§à¸£à¸à¹à¸³à¸à¸§à¹à¸² Entry)",setup_invalid_tp_for_buy:"à¸à¸±à¹à¸ TP à¸à¸´à¸à¸à¸±à¹à¸à¸ªà¸³à¸«à¸£à¸±à¸ BUY (TP à¸à¸§à¸£à¸ªà¸¹à¸à¸à¸§à¹à¸² Entry)",setup_invalid_sl_for_sell:"à¸à¸±à¹à¸ SL à¸à¸´à¸à¸à¸±à¹à¸à¸ªà¸³à¸«à¸£à¸±à¸ SELL (SL à¸à¸§à¸£à¸ªà¸¹à¸à¸à¸§à¹à¸² Entry)",setup_invalid_tp_for_sell:"à¸à¸±à¹à¸ TP à¸à¸´à¸à¸à¸±à¹à¸à¸ªà¸³à¸«à¸£à¸±à¸ SELL (TP à¸à¸§à¸£à¸à¹à¸³à¸à¸§à¹à¸² Entry)",setup_low_risk_reward:"Risk/Reward à¸à¹à¸³à¸à¸§à¹à¸² 1.0",low_confidence:"AI มัà¹à¸à¹à¸à¸à¹à¸³ (< 50%)",scanner_stale:"à¸à¹à¸à¸¡à¸¹à¸¥ scanner à¹à¸à¹à¸²à¹à¸à¸´à¸ ~3 à¸à¸²à¸à¸µ",scanner_sync_missing:"à¹à¸¡à¹à¸¡à¸µà¹à¸§à¸¥à¸² sync scanner ลà¹à¸²à¸ªà¸¸à¸",realtime_context_incomplete:"à¸à¹à¸à¸¡à¸¹à¸¥ realtime หลัà¸à¹à¸¡à¹à¸à¸£à¸ (price / order flow / liquidity / à¸à¸´à¸à¸à¸´à¹à¸à¹à¸à¸à¸£à¹)"};function gt(s){return Cs[s]??s.replace(/_/g," ")}const As=new Set(["rsi_oversold_vs_bearish","rsi_overbought_vs_bullish","setup_invalid_sl_for_buy","setup_invalid_tp_for_buy","setup_invalid_sl_for_sell","setup_invalid_tp_for_sell","setup_low_risk_reward"]);function ft(s){if(s.length===0)return 0;const n=[...s].sort((r,c)=>r-c),a=Math.floor(n.length/2);return n.length%2?n[a]:(n[a-1]+n[a])/2}function $s(s){switch(s){case"healthy":return{label:"à¸à¸à¸à¸´",bg:"from-emerald-500/10 to-transparent",border:"border-emerald-500/30",text:"text-emerald-400",iconBg:"bg-emerald-500/15"};case"watch":return{label:"à¹à¸à¹à¸²à¸£à¸°à¸§à¸±à¸",bg:"from-amber-500/10 to-transparent",border:"border-amber-500/30",text:"text-amber-400",iconBg:"bg-amber-500/15"};case"anomaly":return{label:"à¸à¸´à¸à¸à¸à¸à¸´",bg:"from-rose-500/10 to-transparent",border:"border-rose-500/30",text:"text-rose-400",iconBg:"bg-rose-500/15"};default:return{label:"à¸à¹à¸à¸¡à¸¹à¸¥à¹à¸¡à¹à¸à¸",bg:"from-gray-500/10 to-transparent",border:"border-gray-700",text:"text-gray-400",iconBg:"bg-gray-500/15"}}}function Ds(s){return s>=75?"bg-emerald-500":s>=50?"bg-amber-500":"bg-rose-500"}function Ts(s){return s>=75?"text-emerald-400":s>=50?"text-amber-400":"text-rose-400"}function Rs(s,n){return s?new Date(n).getTime()>new Date(s).getTime()?"regressed":"resolved":"active"}function Ms(s,n,a,r){if(!s)return[];const c=r??s.onlineNow,l=[];c>s.activeUsers24h&&l.push({key:"online-gt-active24h",message:"Online now should not exceed active users (24h).",level:"warning"}),s.activeUsers24h>s.activeUsers7d&&l.push({key:"active24h-gt-active7d",message:"Active users (24h) should not exceed active users (7d).",level:"warning"}),s.activeUsers7d>s.totalUsers&&l.push({key:"active7d-gt-total",message:"Active users (7d) should not exceed total users.",level:"warning"}),s.vipUsers>s.totalUsers&&l.push({key:"vip-gt-total",message:"VIP users should not exceed total users.",level:"warning"}),s.vipUsers+s.guestUsers!==s.totalUsers&&l.push({key:"vip-guest-ne-total",message:"VIP + Guest should equal total users.",level:"warning"});const o=n.length>0?n.reduce((x,j)=>x+j.sessions,0)/n.length:0,f=n.length>0?Math.max(...n.map(x=>x.sessions)):0,p=3,u=Math.max(15,Math.ceil(o*p));return o>0&&c>=u&&l.push({key:"online-spike-vs-24h-avg",message:`Online now spike detected: ${c} vs 24h average ${o.toFixed(1)} (threshold >= ${u}, x${p}).`,level:"anomaly"}),f>0&&c>=Math.ceil(f*1.5)&&l.push({key:"online-spike-vs-24h-peak",message:`Online now exceeds historical 24h peak by >50%: ${c} vs peak ${f}.`,level:"anomaly"}),a&&a.yesterdaySameHourUsers>0&&a.ratioVsYesterday>=2.5&&l.push({key:"online-spike-vs-yesterday-same-hour",message:`Same-hour baseline anomaly: current hour ${a.currentHourUsers} vs yesterday ${a.yesterdaySameHourUsers} (${a.ratioVsYesterday}x).`,level:"anomaly"}),a&&a.yesterdaySameHourUsers===0&&a.currentHourUsers>=20&&l.push({key:"online-spike-no-yesterday-baseline",message:`Same-hour baseline anomaly: yesterday had 0 users but current hour is ${a.currentHourUsers}.`,level:"anomaly"}),l}function v({icon:s,label:n,value:a,sub:r,color:c,trend:l,onClick:o,expanded:f}){const p={blue:{bg:"from-blue-500/5 to-transparent",border:"border-blue-500/20",text:"text-blue-400",iconBg:"bg-blue-500/15"},emerald:{bg:"from-emerald-500/5 to-transparent",border:"border-emerald-500/20",text:"text-emerald-400",iconBg:"bg-emerald-500/15"},amber:{bg:"from-amber-500/5 to-transparent",border:"border-amber-500/20",text:"text-amber-400",iconBg:"bg-amber-500/15"},sky:{bg:"from-sky-500/5 to-transparent",border:"border-sky-500/20",text:"text-sky-400",iconBg:"bg-sky-500/15"},rose:{bg:"from-rose-500/5 to-transparent",border:"border-rose-500/20",text:"text-rose-400",iconBg:"bg-rose-500/15"},teal:{bg:"from-teal-500/5 to-transparent",border:"border-teal-500/20",text:"text-teal-400",iconBg:"bg-teal-500/15"},orange:{bg:"from-orange-500/5 to-transparent",border:"border-orange-500/20",text:"text-orange-400",iconBg:"bg-orange-500/15"},cyan:{bg:"from-cyan-500/5 to-transparent",border:"border-cyan-500/20",text:"text-cyan-400",iconBg:"bg-cyan-500/15"}
11,violet:{bg:"from-violet-500/5 to-transparent",border:"border-violet-500/20",text:"text-violet-400",iconBg:"bg-violet-500/15"}},u=p[c]||p.blue,x=o?"button":"div";return e.jsxs(x,{...o?{type:"button",onClick:o,"aria-expanded":!!f}:{},className:`relative overflow-hidden bg-gradient-to-br ${u.bg} border ${u.border} rounded-xl p-4 transition-all hover:scale-[1.02] ${o?`w-full text-left cursor-pointer ${f?"ring-1 ring-white/20":""}`:""}`,children:[e.jsxs("div",{className:"flex items-start justify-between mb-3",children:[e.jsx("div",{className:`p-2 ${u.iconBg} rounded-lg`,children:e.jsx(s,{className:`w-4 h-4 ${u.text}`})}),o&&e.jsx(Gt,{className:`w-4 h-4 text-gray-500 transition-transform ${f?"rotate-180":""}`}),l&&e.jsx("div",{className:`flex items-center gap-0.5 text-xs font-medium ${l==="up"?"text-emerald-400":l==="down"?"text-rose-400":"text-gray-500"}`,children:l==="up"?e.jsx(Pe,{className:"w-3 h-3"}):l==="down"?e.jsx(Fe,{className:"w-3 h-3"}):e.jsx(Ce,{className:"w-3 h-3"})})]}),e.jsx("p",{className:"text-2xl font-bold text-white tracking-tight",children:a}),e.jsx("p",{className:"text-xs text-gray-500 mt-1",children:n}),r&&e.jsx("p",{className:"text-[10px] text-gray-600 mt-0.5",children:r})]})}function $({title:s,children:n,className:a=""}){return e.jsxs("div",{className:`bg-gray-900/50 border border-gray-800 rounded-xl p-5 ${a}`,children:[e.jsx("h3",{className:"text-sm font-semibold text-gray-300 mb-4",children:s}),n]})}function yt({items:s,colorMap:n}){return e.jsx("div",{className:"space-y-3",children:s.map(a=>e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-1",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"w-2.5 h-2.5 rounded-full",style:{backgroundColor:n[a.label]||"#6b7280"}}),e.jsx("span",{className:"text-sm text-gray-300",children:a.label})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("span",{className:"text-xs text-gray-500",children:a.count}),e.jsxs("span",{className:"text-xs font-medium text-white w-10 text-right",children:[a.percentage,"%"]})]})]}),e.jsx("div",{className:"w-full h-1.5 bg-gray-800 rounded-full overflow-hidden",children:e.jsx("div",{className:"h-full rounded-full transition-all duration-700",style:{width:`${a.percentage}%`,backgroundColor:n[a.label]||"#6b7280"}})})]},a.label))})}function sa(){const[s,n]=h.useState(null),[a,r]=h.useState(!1),[c,l]=h.useState([]),[o,f]=h.useState([]),[p,u]=h.useState([]),[x,j]=h.useState([]),[g,m]=h.useState([]),[b,Z]=h.useState([]),[H,J]=h.useState(null),[A,ke]=h.useState(null),[_,N]=h.useState([]),[U,E]=h.useState([]),[I,me]=h.useState([]),[W,ue]=h.useState([]),[D,$e]=h.useState(null),[se,Ve]=h.useState([]),[G,w]=h.useState([]),[z,tt]=h.useState([]),[st,jt]=h.useState([]),[at,vt]=h.useState([]),[He,rt]=h.useState(!0),[ze,Nt]=h.useState(7),[Y,kt]=h.useState(7),[we,wt]=h.useState(7),[De,St]=h.useState(7),[pe,Ct]=h.useState("ALL"),[ae,At]=h.useState("all"),[re,$t]=h.useState(new Date),[Dt,Ke]=h.useState(!1),nt=Qt(),qe=nt??(s==null?void 0:s.onlineNow)??0,M=Ms(s,g,D,nt??void 0),Te=M.filter(t=>t.level==="anomaly").length,Re=M.filter(t=>t.level==="warning").length,Tt=h.useCallback(()=>{if(!s)return;const i=["section,key,value",`meta,generated_at,${new Date().toISOString()}`,`meta,last_refresh,${re.toISOString()}`,`summary,total_issues,${M.length}`,`summary,warning_count,${Re}`,`summary,anomaly_count,${Te}`,`metrics,online_now,${qe}`,`metrics,active_users_24h,${s.activeUsers24h}`,`metrics,active_users_7d,${s.activeUsers7d}`,`metrics,total_users,${s.totalUsers}`,`metrics,vip_users,${s.vipUsers}`,`metrics,guest_users,${s.guestUsers}`,`baseline,current_hour_label,${(D==null?void 0:D.hourLabel)||""}`,`baseline,current_hour_users,${(D==null?void 0:D.currentHourUsers)??""}`,`baseline,yesterday_same_hour_users,${(D==null?void 0:D.yesterdaySameHourUsers)??""}`,`baseline,ratio_vs_yesterday,${(D==null?void 0:D.ratioVsYesterday)??""}`];M.forEach(k=>{const B=k.message.replace(/"/g,'""');i.push(`issues,${k.level},"${B}"`)}),M.length===0&&i.push('issues,none,"No sanity/anomaly issues detected"');const d=i.join(` 12`),S=new Blob([d],{type:"text/csv;charset=utf-8;"}),C=URL.createObjectURL(S),y=document.createElement("a"),L=new Date().toISOString().replace(/[:.]/g,"-");y.href=C,y.download=`analytics-sanity-report-${L}.csv`,document.body.appendChild(y),y.click(),document.body.removeChild(y),URL.revokeObjectURL(C)},[s,re,M,Re,Te,D]),he=h.useMemo(()=>U.filter(t=>!(pe!=="ALL"&&t.asset!==pe||ae==="blocked"&&t.blocked<=0||ae==="executed"&&t.executed<=0||ae==="errors"&&t.errors<=0)),[U,pe,ae]),Rt=h.useMemo(()=>["ALL",...Array.from(new Set(U.map(t=>t.asset))).sort()],[U]),lt=h.useMemo(()=>[...W].sort((t,i)=>t.successRatePct!==i.successRatePct?t.successRatePct-i.successRatePct:i.totalAttempts-t.totalAttempts).slice(0,10),[W]),it=h.useMemo(()=>[...W].filter(t=>t.readerFallbackCount>0).sort((t,i)=>t.readerFallbackCount!==i.readerFallbackCount?i.readerFallbackCount-t.readerFallbackCount:i.totalAttempts-t.totalAttempts).slice(0,10),[W]),ct=h.useMemo(()=>{const t=new Map;return se.forEach(i=>
12{const d=`${i.resolved_feature}::${i.target_tab}::${i.toolbox_tab}`,S=t.get(d)||{total:0,success:0,fail:0};S.total+=i.total_attempts,S.success+=i.successful_attempts,S.fail+=i.failed_attempts,t.set(d,S)}),Array.from(t.entries()).map(([i,d])=>{const[S,C,y]=i.split("::");return{feature:S,targetTab:C,toolboxTab:y,total:d.total,success:d.success,fail:d.fail,passRate:d.total>0?Math.round(d.success/d.total*1e3)/10:0}}).sort((i,d)=>d.total-i.total).slice(0,12)},[se]),ge=h.useMemo(()=>{const t=G.reduce((i,d)=>(i.totalAttempts+=d.total_attempts,i.successAttempts+=d.successful_attempts,i.failAttempts+=d.failed_attempts,i.healthy+=d.healthy_cells,i.warning+=d.warning_cells,i.critical+=d.critical_cells,i),{totalAttempts:0,successAttempts:0,failAttempts:0,healthy:0,warning:0,critical:0});return{...t,passRate:t.totalAttempts>0?Math.round(t.successAttempts/t.totalAttempts*1e3)/10:0}},[G]),X=h.useMemo(()=>st.slice(0,10),[st]),K=h.useMemo(()=>{var C;const t=X.reduce((y,L)=>y+L.conflict_count,0),i=X.reduce((y,L)=>y+L.affected_logs,0),d=X.reduce((y,L)=>y+L.avg_confidence*L.conflict_count,0),S=t>0?Math.round(d/t*10)/10:0;return{totalConflicts:t,totalLogs:i,avgConfidence:S,topType:((C=X[0])==null?void 0:C.conflict_type)||"-"}},[X]),Me=h.useMemo(()=>{const t=new Map;return at.forEach(i=>{const d=t.get(i.metric_date)||{conflict_count:0,affected_logs:0,confidenceNumerator:0,confidenceDenominator:0};d.conflict_count+=i.conflict_count,d.affected_logs+=i.affected_logs,d.confidenceNumerator+=i.avg_confidence*i.conflict_count,d.confidenceDenominator+=i.conflict_count,t.set(i.metric_date,d)}),Array.from(t.entries()).map(([i,d])=>({metric_date:i,conflict_count:d.conflict_count,affected_logs:d.affected_logs,avg_confidence:d.confidenceDenominator>0?Math.round(d.confidenceNumerator/d.confidenceDenominator*10)/10:0})).sort((i,d)=>i.metric_date.localeCompare(d.metric_date))},[at]),ne=h.useMemo(()=>{const t=Me,i=t.slice(-3),d=t.slice(0,-3),S=t.reduce((T,q)=>T+q.conflict_count,0);if(t.length<5||d.length<2||S===0)return{status:"insufficient",score:null,verdict:"à¸à¹à¸à¸¡à¸¹à¸¥à¸¢à¸±à¸à¹à¸¡à¹à¸à¸à¸à¸£à¸°à¹à¸¡à¸´à¸ (à¸à¹à¸à¸à¸¡à¸µà¸à¸£à¸°à¸§à¸±à¸à¸´ â¥5 วัà¸à¸à¸µà¹à¸¡à¸µ conflict)",signals:[]};const C=d.map(T=>T.conflict_count),y=ft(C),L=ft(C.map(T=>Math.abs(T-y))),k=Math.max(L*1.4826,1),B=i.reduce((T,q)=>T+q.conflict_count,0)/i.length,F=B/Math.max(y,1),V=(B-y)/k,We=B-y;let P;B<=y?P=100:We<=2&&B<=5||F<=1.3&&V<2?P=90:F<=2&&V<3?P=65:F<=3?P=40:P=15;const Ue=i.reduce((T,q)=>T+q.conflict_count,0),le=Ue>0?i.reduce((T,q)=>T+q.avg_confidence*q.conflict_count,0)/Ue:K.avgConfidence;let Q;le<60?Q=100:le<70?Q=85:le<80?Q=65:Q=45;const Ee=K.totalConflicts,Ge=X.filter(T=>As.has(T.conflict_type)).reduce((T,q)=>T+q.conflict_count,0),ie=Ee>0?Ge/Ee:0;let ce;ie<.15?ce=100:ie<.3?ce=80:ie<.5?ce=55:ce=30;const Ye=Math.round(P*.55+Q*.2+ce*.25),ot=Ye>=75?"healthy":Ye>=50?"watch":"anomaly";let Xe;if(ot==="healthy")Xe=`conflict à¸à¸¢à¸¹à¹à¹à¸à¸à¹à¸§à¸à¸à¸à¸à¸´ â ลà¹à¸²à¸ªà¸¸à¸ ~${B.toFixed(1)}/วัภà¹à¸à¸µà¸¢à¸à¸¡à¸±à¸à¸¢à¸à¸²à¸ 30 วัภ(${y})`;else{const T=[];P<65&&T.push(`conflict à¸à¸¸à¹à¸ ${F.toFixed(1)}à à¸à¸²à¸à¸à¹à¸²à¸à¸à¸à¸´`),Q<65&&T.push(`AI มัà¹à¸à¹à¸à¸ªà¸¹à¸ (${le.toFixed(0)}%) à¸à¸à¸°à¸à¸±à¸à¹à¸¢à¹à¸`),ce<55&&T.push(`รูà¸à¹à¸à¸à¹à¸ªà¸µà¹à¸¢à¸ ${Math.round(ie*100)}% à¸à¸à¸à¸à¸±à¹à¸à¸«à¸¡à¸`),Xe=T.length?T.join(" · "):"มีสัà¸à¸à¸²à¸à¸à¸´à¸à¸à¸à¸à¸´à¹à¸¥à¹à¸à¸à¹à¸à¸¢ à¸à¸§à¸£à¹à¸à¹à¸²à¸à¸¹"}return{status:ot,score:Ye,verdict:Xe,signals:[{key:"volume",label:"à¸à¸£à¸´à¸¡à¸²à¸à¹à¸à¸µà¸¢à¸ baseline",score:P,detail:`ลà¹à¸²à¸ªà¸¸à¸ ${B.toFixed(1)}/วัภ· มัà¸à¸¢à¸à¸²à¸ ${y} · ${F.toFixed(1)}Ã`},{key:"confidence",label:"à¸à¸§à¸²à¸¡à¸¡à¸±à¹à¸à¹à¸à¸à¸à¸°à¸à¸±à¸à¹à¸¢à¹à¸",score:Q,detail:`${le.toFixed(0)}%`},{key:"concentration",label:"สัà¸à¸ªà¹à¸§à¸à¸£à¸¹à¸à¹à¸à¸à¹à¸ªà¸µà¹à¸¢à¸",score:ce,detail:`${Math.round(ie*100)}% (RSI à¹à¸¥à¹à¸ªà¸¸à¸ / setup à¸à¸´à¸)`}]}},[Me,X,K]),ee=$s(ne.status),Mt=h.useCallback(()=>{const i=["section,key,value",`meta,generated_at,${new Date().toISOString()}`,`meta,last_refresh,${re.toISOString()}`,`meta,window_days,${Y}`,`summary,funnel_rows,${_.length}`,"","asset,broadcasts,executions,drop_off,conversion_rate_percent"];_.forEach(k=>{i.push(`${k.asset},${k.broadcasts},${k.executions},${k.dropOff},${k.conversionRate}`)}),_.length===0&&i.push("none,0,0,0,0");const d=i.join(` 13`),S=new Blob([d],{type:"text/csv;charset=utf-8;"}),C=URL.createObjectURL(S),y=document.createElement("a"),L=new Date().toISOString().replace(/[:.]/g,"-");y.href=C,y.download=`funnel-${L}.csv`,document.body.appendChild(y),y.click(),document.body.removeChild(y),URL.revokeObjectURL(C)},[re,Y,_]),Lt=h.useCallback(()=>{const i=["section,key,value",`meta,generated_at,${new Date().toISOString()}`,`meta,last_refresh,${re.toISOString()}`,`meta,window_days,${Y}`,`meta,asset_filter,${pe}`,`meta,status_filter,${ae}`,`summary,block_monitor_rows,${he.length}`,"","asset,attempts,blocked,executed,errors,block_rate_percent,exec_rate_percent,top_block_reason"];he.forEach(k=>{const B=k.attempts>0?Math.round(k.blocked/k.attempts*1e3)/10:0,F=k.attempts>0?Math.round(k.executed/k.attempts*1e3)/10:0,V=k.topBlockReason.replace(/"/g,'""');i.push(`${k.asset},${k.attempts},${k.blocked},${k.executed},${k.errors},${B},${F},"${V}"`)}),he.length===0&&i.push('none,0,0,0,0,0,0,"-"');const d=i.join(` 14`),S=new Blob([d],{type:"text/csv;charset=utf-8;"}),C=URL.createObjectURL(S),y=document.createElement("a"),L=new Date().toISOString().replace(/[:.]/g,"-");y.href=C,y.download=`block-monitor-${L}.csv`,document.body.appendChild(y),y.click(),document.body.removeChild(y),URL.revokeObjectURL(C)},[re,Y,pe,ae,he]),Le=h.useCallback(async()=>{rt(!0);try{const[t,i,d,S,C,y,L,k,B,F,V,We,P,Ue,le,Q,Ee,Ge,ie]=await Promise.all([rs(),ns(ze),ls(),is(),cs(),os(),ds(),xs(8),ms(),us(Y),ps(Y),hs(Y,300),gs().catch(()=>null),fs(3,250).catch(()=>[]),ys(we).catch(()=>[]),bs(we).catch(()=>[]),_s(we,50).catch(()=>[]),vs(De,30).catch(()=>[]),Ns().catch(()=>[])]);n(t),l(i),f(d),u(S),j(C),m(y),$e(L),Z(k),J(B),N(F),E(V),me(We),ue(Ue),Ve(le),w(Q),tt(Ee),jt(Ge),vt(ie),P&&ke(P),$t(new Date)}catch(t){console.error("Analytics load failed:",t)}finally{rt(!1)}},[ze,Y,we,De]);h.useEffect(()=>{Le();const t=setInterval(Le,6e4);return()=>clearInterval(t)},[Le]);const fe=({active:t,payload:i,label:d})=>!t||!(i!=null&&i.length)?null:e.jsxs("div",{className:"bg-gray-900 border border-gray-700 rounded-lg px-3 py-2 shadow-xl",children:[e.jsx("p",{className:"text-xs text-gray-400 mb-1",children:d==null?"":String(d)}),i.map((S,C)=>e.jsxs("p",{className:"text-xs font-medium",style:{color:S.color||"#9ca3af"},children:[String(S.name??""),": ",String(S.value??"")]},C))]});return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsxs("h2",{className:"text-xl font-bold text-white flex items-center gap-2",children:[e.jsx(Ut,{className:"w-5 h-5 text-sky-400"}),"Analytics Overview"]}),e.jsxs("p",{className:"text-xs text-gray-500 mt-1",children:["Last updated: ",re.toLocaleTimeString()," (auto-refresh 1min)"]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[s&&e.jsxs("div",{className:`flex items-center gap-2 px-3 py-2 rounded-lg border text-xs ${M.length===0?"bg-emerald-500/10 border-emerald-500/30 text-emerald-300":"bg-amber-500/10 border-amber-500/30 text-amber-300"}`,title:M.length===0?"All sanity checks passed":M.map(t=>t.message).join(" | "),children:[M.length===0?e.jsx(te,{className:"w-3.5 h-3.5"}):e.jsx(oe,{className:"w-3.5 h-3.5"}),e.jsxs("span",{children:["Data Sanity ",M.length===0?"OK":`${M.length} issue${M.length>
141?"s":""}`]})]}),s&&e.jsx("button",{onClick:()=>Ke(!0),className:"px-3 py-2 rounded-lg border border-gray-700 bg-gray-800 text-xs text-gray-300 hover:text-white hover:border-gray-600 transition-all",children:"View Details"}),e.jsxs("button",{onClick:Le,disabled:He,className:"flex items-center gap-2 px-4 py-2 bg-gray-800 border border-gray-700 rounded-lg text-sm text-gray-300 hover:text-white hover:border-gray-600 transition-all disabled:opacity-50",children:[e.jsx(Qe,{className:`w-4 h-4 ${He?"animate-spin":""}`}),"Refresh"]})]})]}),s&&M.length>0&&e.jsxs("div",{className:"bg-amber-500/10 border border-amber-500/30 rounded-xl p-3",children:[e.jsxs("p",{className:"text-xs font-semibold text-amber-300 mb-2 flex items-center gap-1.5",children:[e.jsx(oe,{className:"w-3.5 h-3.5"}),"Analytics sanity warnings (",Re," warning, ",Te," anomaly)"]}),e.jsx("div",{className:"space-y-1",children:M.map(t=>e.jsxs("p",{className:"text-xs text-amber-200/90",children:["- [",t.level,"] ",t.message]},t.key))})]}),Dt&&s&&e.jsx("div",{className:"fixed inset-0 bg-black/70 backdrop-blur-sm flex items-center justify-center p-4",style:{zIndex:1e4},onClick:()=>Ke(!1),children:e.jsxs("div",{className:"w-full max-w-2xl bg-gray-900 border border-gray-700 rounded-2xl shadow-2xl",onClick:t=>t.stopPropagation(),children:[e.jsxs("div",{className:"flex items-center justify-between px-5 py-4 border-b border-gray-800",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-base font-bold text-white",children:"Analytics Sanity Details"}),e.jsx("p",{className:"text-xs text-gray-400 mt-0.5",children:M.length===0?"All checks passed.":`${M.length} issue found (${Re} warning, ${Te} anomaly)`})]}),e.jsx("button",{onClick:()=>Ke(!1),className:"p-2 rounded-lg border border-gray-700 text-gray-400 hover:text-white hover:border-gray-600",children:e.jsx(Et,{className:"w-4 h-4"})})]}),e.jsxs("div",{className:"p-5 space-y-3 max-h-[70vh] overflow-y-auto",children:[e.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-2 text-xs",children:[e.jsxs("div",{className:"bg-gray-800/60 border border-gray-700 rounded-lg p-2",children:[e.jsx("p",{className:"text-gray-500",children:"Online Now"}),e.jsx("p",{className:"text-white font-semibold",children:qe})]}),e.jsxs("div",{className:"bg-gray-800/60 border border-gray-700 rounded-lg p-2",children:[e.jsx("p",{className:"text-gray-500",children:"Active (24h)"}),e.jsx("p",{className:"text-white font-semibold",children:s.activeUsers24h})]}),e.jsxs("div",{className:"bg-gray-800/60 border border-gray-700 rounded-lg p-2",children:[e.jsx("p",{className:"text-gray-500",children:"Active (7d)"}),e.jsx("p",{className:"text-white font-semibold",children:s.activeUsers7d})]}),e.jsxs("div",{className:"bg-gray-800/60 border border-gray-700 rounded-lg p-2",children:[e.jsx("p",{className:"text-gray-500",children:"Total Users"}),e.jsx("p",{className:"text-white font-semibold",children:s.totalUsers})]})]}),D&&e.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-2 text-xs",children:[e.jsxs("div",{className:"bg-gray-800/60 border border-gray-700 rounded-lg p-2",children:[e.jsx("p",{className:"text-gray-500",children:"Baseline Hour"}),e.jsx("p",{className:"text-white font-semibold",children:D.hourLabel})]}),e.jsxs("div",{className:"bg-gray-800/60 border border-gray-700 rounded-lg p-2",children:[e.jsx("p",{className:"text-gray-500",children:"Current Hour"}),e.jsx("p",{className:"text-white font-semibold",children:D.currentHourUsers})]}),e.jsxs("div",{className:"bg-gray-800/60 border border-gray-700 rounded-lg p-2",children:[e.jsx("p",{className:"text-gray-500",children:"Yesterday Same Hour"}),e.jsx("p",{className:"text-white font-semibold",children:D.yesterdaySameHourUsers})]}),e.jsxs("div",{className:"bg-gray-800/60 border border-gray-700 rounded-lg p-2",children:[e.jsx("p",{className:"text-gray-500",children:"Ratio"}),e.jsxs("p",{className:"text-white font-semibold",children:[D.ratioVsYesterday,"x"]})]})]}),M.length===0?e.jsx("div",{className:"bg-emerald-500/10 border border-emerald-500/30 rounded-xl p-4 text-sm text-emerald-200",children:"No sanity or anomaly issues detected in current snapshot."}):e.jsx("div",{className:"space-y-2",children:M.map(t=>e.jsxs("div",{className:`rounded-lg p-3 border ${t.level==="anomaly"?"bg-rose-500/10 border-rose-500/30 text-rose-200":"bg-amber-500/10 border-amber-500/30 text-amber-200"}`,children:[e.jsx("p",{className:"text-xs uppercase tracking-wide opacity-80 mb-1",children:t.level}),e.jsx("p",{className:"text-sm",children:t.message})]},t.key))}),e.jsx("div",{className:"pt-2 border-t border-gray-800",children:e.jsx("button",{onClick:Tt,className:"px-3 py-2 rounded-lg border border-sky-500/40 bg-sky-500/10 text-xs text-sky-300 hover:text-sky-200 hover:bg-sky-500/15 transition-all",children:"Export Sanity Report (CSV)"})})]})]})}),He&&!s?e.jsx("div",{className:"flex items-center justify-center py-20",children:e.jsx(Qe,{className:"w-8 h-8 text-sky-400 animate-spin"})}):s&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"bg-emerald-500/10 border border-emerald-500/30 rounded-xl p-4 flex items-center gap-4",children:[e.jsxs("div",{className:"relative",children:[e.jsx("div",{className:"w-3 h-3 bg-emerald-400 rounded-full animate-pulse"}),e.jsx("div",{className:"absolute inset-0 w-3 h-3 bg-emerald-400 rounded-full animate-ping"})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-3xl font-bold text-emerald-400",children:qe}),e.jsx("span",{className:"text-sm text-gray-400 ml-2",children:"users online right now"})]}),e.jsxs("div",{className:"ml-auto flex items-center gap-4 text-xs text-gray-500",children:[e.jsxs("span",{children:[e.jsx(dt,{className:"w-3 h-3 inline mr-1 text-amber-400"}),s.vipUsers," VIP"]}),e.jsxs("span",{children:[e.jsx(Be,{className:"w-3 h-3 inline mr-1 text-gray-400"}),s.guestUsers," Guests"]})]})]}),e.jsxs("div",{children:[e.jsx("p",{className:"text-[11px] font-semibold uppercase tracking-wider text-gray-500 mb-2",children:"Users"}),e.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-3",children:[e.jsx(v,{icon:Be,label:"Total Users",value:R(s.totalUsers),color:"blue"}),e.jsx(v,{icon:xt,label:"Active (24h)",value:R(s.activeUsers24h),color:"emerald"}),e.jsx(v,{icon:Ie,label:"Active (7d)",value:R(s.activeUsers7d),color:"sky"}),e.jsx(v,{icon:Bt,label:"Avg Session",value:ht(s.avgSessionDuration),color:"teal"})]})]}),e.jsxs("div",{children:[e.jsx("p",{className:"text-[11px] font-semibold uppercase tracking-wider text-gray-500 mb-2",children:"Engagement"}),e.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-3",children:[e.jsx(v,{icon:Ot,label:"Page Views",value:R(s.totalPageViews),color:"amber"}),e.jsx(v,{icon:mt,label:"Signals Viewed",value:R(s.totalSignalsViewed),color:"orange"}),e.jsx(v,{icon:Pt,label:"Charts Viewed",value:R(s.totalChartsViewed),color:"cyan"})]})]}),e.jsxs("div",{children:[e.jsx("p",{className:"text-[11px] font-semibold uppercase tracking-wider text-gray-500 mb-2",children:"VIP & Revenue"}),e.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-3",children:[e.jsx(v,{icon:dt,label:"Active VIP Codes",value:s.activeVipCodes,sub:a?"à¸à¸à¹à¸à¸·à¹à¸à¸à¹à¸à¸":`ลูà¸à¸à¹à¸² ${s.activeVipBreakdown.customerActivated+s.activeVipBreakdown.customerPending} · à¹à¸à¸ ${s.activeVipBreakdown.adminGrant} · KOL ${s.activeVipBreakdown.kolPartner} â à¸à¸à¹à¸à¸·à¹à¸à¹à¸¢à¸`,color:"rose",onClick:()=>r(t=>!t),expanded:a}),e.jsx(v,{icon:Yt,label:"Expired VIP",value:R(s.expiredVipCodes),sub:`of ${s.totalVipCodes} total codes`,color:"amber"}),e.jsx(v,{icon:Ft,label:"Peak VIP (All-Time)",value:R(s.totalVipCodes),sub:`Active ${s.activeVipCodes} + Expired ${s.expiredVipCodes}`,color:"violet"}),e.jsx(v,{icon:Qe,label:"Renew Paid",value:R(s.renewPaid),sub:"paid renewals (all-time)",color:"teal"})]}),a&&e.jsxs(e.Fragment,{children:[e.jsxs("p",{className:"text-[11px] text-gray-500 mt-3 mb-2",children:["à¹à¸¢à¸ ",s.activeVipCodes," Active VIP Codes (รวมà¸à¸±à¸à¹à¸à¹à¹à¸à¹à¸²à¸à¸±à¸à¸¢à¸à¸à¸à¹à¸²à¸à¸à¸à¹à¸ªà¸¡à¸)"]}),e.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-3",children:[e.jsx(v,{icon:xt,label:"Activate à¹à¸¥à¹à¸§ (à¹à¸à¹à¸à¸²à¸à¸à¸£à¸´à¸)",value:s.activeVipBreakdown.customerActivated,sub:"ลูà¸à¸à¹à¸² â à¹à¸¡à¹à¸£à¸§à¸¡à¹à¸à¹à¸à¹à¸à¸ / KOL",color:"emerald"}),e.jsx(v,{icon:Vt,label:"ยัà¸à¹à¸¡à¹ Activate",value:s.activeVipBreakdown.customerPending,sub:"ลูà¸à¸à¹à¸²à¹à¸à¹à¹à¸à¹à¸à¹à¸¥à¹à¸§ ยัà¸à¹à¸¡à¹à¹à¸à¹à¸²à¹à¸à¹",color:"amber"}),e.jsx(v,{icon:Ht,label:"à¹à¸à¸à¸¡à¸´à¸à¹à¸à¸",value:s.activeVipBreakdown.adminGrant,sub:"99999_days ·
14staff · giveaway",color:"violet"}),e.jsx(v,{icon:zt,label:"KOL / Partner",value:s.activeVipBreakdown.kolPartner,sub:"kol · partner · marketing",color:"sky"})]})]})]}),H&&e.jsxs("div",{children:[e.jsx("p",{className:"text-[11px] font-semibold uppercase tracking-wider text-gray-500 mb-2",children:"Session Quality"}),e.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-3",children:[e.jsxs("div",{className:"bg-gray-900/50 border border-gray-800 rounded-xl p-4",children:[e.jsx("p",{className:"text-xs text-gray-500 mb-1",children:"Bounce Rate"}),e.jsxs("p",{className:"text-xl font-bold text-white",children:[H.bounceRate,"%"]}),e.jsx("div",{className:"w-full h-1 bg-gray-800 rounded-full mt-2 overflow-hidden",children:e.jsx("div",{className:"h-full rounded-full bg-rose-500 transition-all duration-700",style:{width:`${Math.min(H.bounceRate,100)}%`}})})]}),e.jsxs("div",{className:"bg-gray-900/50 border border-gray-800 rounded-xl p-4",children:[e.jsx("p",{className:"text-xs text-gray-500 mb-1",children:"Returning Users"}),e.jsxs("p",{className:"text-xl font-bold text-white",children:[H.returningRate,"%"]}),e.jsxs("p",{className:"text-[10px] text-gray-600",children:[H.returningUsers," users"]})]}),e.jsxs("div",{className:"bg-gray-900/50 border border-gray-800 rounded-xl p-4",children:[e.jsx("p",{className:"text-xs text-gray-500 mb-1",children:"Avg Page Views / Session"}),e.jsx("p",{className:"text-xl font-bold text-white",children:H.avgPageViews})]}),e.jsxs("div",{className:"bg-gray-900/50 border border-gray-800 rounded-xl p-4",children:[e.jsx("p",{className:"text-xs text-gray-500 mb-1",children:"Avg Time / Session"}),e.jsx("p",{className:"text-xl font-bold text-white",children:ht(H.avgTimeSpent)})]})]})]}),e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-3 gap-4",children:[e.jsxs($,{title:"Users Over Time",className:"lg:col-span-2",children:[e.jsx("div",{className:"flex items-center gap-1 mb-4",children:[7,14,30].map(t=>e.jsxs("button",{onClick:()=>Nt(t),className:`px-3 py-1 rounded-md text-xs font-medium transition-all ${ze===t?"bg-sky-500/20 text-sky-400":"text-gray-500 hover:text-gray-300"}`,children:[t,"D"]},t))}),e.jsx(ye,{width:"100%",height:220,children:e.jsxs(Kt,{data:c,children:[e.jsxs("defs",{children:[e.jsxs("linearGradient",{id:"gradActive",x1:"0",y1:"0",x2:"0",y2:"1",children:[e.jsx("stop",{offset:"5%",stopColor:"#0ea5e9",stopOpacity:.3}),e.jsx("stop",{offset:"95%",stopColor:"#0ea5e9",stopOpacity:0})]}),e.jsxs("linearGradient",{id:"gradNew",x1:"0",y1:"0",x2:"0",y2:"1",children:[e.jsx("stop",{offset:"5%",stopColor:"#10b981",stopOpacity:.3}),e.jsx("stop",{offset:"95%",stopColor:"#10b981",stopOpacity:0})]}),e.jsxs("linearGradient",{id:"gradExpired",x1:"0",y1:"0",x2:"0",y2:"1",children:[e.jsx("stop",{offset:"5%",stopColor:"#f43f5e",stopOpacity:.3}),e.jsx("stop",{offset:"95%",stopColor:"#f43f5e",stopOpacity:0})]}),e.jsxs("linearGradient",{id:"gradRenewals",x1:"0",y1:"0",x2:"0",y2:"1",children:[e.jsx("stop",{offset:"5%",stopColor:"#a78bfa",stopOpacity:.3}),e.jsx("stop",{offset:"95%",stopColor:"#a78bfa",stopOpacity:0})]})]}),e.jsx(be,{strokeDasharray:"3 3",stroke:"#1f2937"}),e.jsx(_e,{dataKey:"label",tick:{fill:"#6b7280",fontSize:10},tickLine:!1,axisLine:!1}),e.jsx(de,{tick:{fill:"#6b7280",fontSize:10},tickLine:!1,axisLine:!1,width:30}),e.jsx(je,{content:fe}),e.jsx(Se,{wrapperStyle:{fontSize:11,color:"#9ca3af"},iconType:"circle",iconSize:8}),e.jsx(Oe,{type:"monotone",dataKey:"activeUsers",name:"Active Users",stroke:"#0ea5e9",fill:"url(#gradActive)",strokeWidth:2}),e.jsx(Oe,{type:"monotone",dataKey:"newUsers",name:"New Users",stroke:"#10b981",fill:"url(#gradNew)",strokeWidth:2}),e.jsx(Oe,{type:"monotone",dataKey:"expiredUsers",name:"Expired Users",stroke:"#f43f5e",fill:"url(#gradExpired)",strokeWidth:2}),e.jsx(Oe,{type:"monotone",dataKey:"renewals",name:"Renewals",stroke:"#a78bfa",fill:"url(#gradRenewals)",strokeWidth:2})]})})]}),e.jsx($,{title:"Hourly Activity (24h)",children:e.jsx(ye,{width:"100%",height:220,children:e.jsxs(Ze,{data:g,children:[e.jsx(be,{strokeDasharray:"3 3",stroke:"#1f2937"}),e.jsx(_e,{dataKey:"label",tick:{fill:"#6b7280",fontSize:9}
14,tickLine:!1,axisLine:!1,interval:2}),e.jsx(de,{tick:{fill:"#6b7280",fontSize:10},tickLine:!1,axisLine:!1,width:25}),e.jsx(je,{content:fe}),e.jsx(ve,{dataKey:"sessions",name:"Sessions",fill:"#0ea5e9",radius:[2,2,0,0]})]})})})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-4",children:[e.jsxs($,{title:"Device Types",children:[e.jsx(yt,{items:o.map(t=>({label:t.type,count:t.count,percentage:t.percentage})),colorMap:ks}),e.jsx("div",{className:"flex items-center gap-4 mt-4 pt-3 border-t border-gray-800",children:o.map(t=>e.jsxs("div",{className:"flex items-center gap-1.5 text-xs text-gray-400",children:[t.type==="Mobile"?e.jsx(qt,{className:"w-3 h-3"}):e.jsx(pt,{className:"w-3 h-3"}),t.count]},t.type))})]}),e.jsx($,{title:"Browsers",children:e.jsx(yt,{items:p.map(t=>({label:t.browser,count:t.count,percentage:t.percentage})),colorMap:ws})}),e.jsx($,{title:"Top Locations",children:e.jsxs("div",{className:"space-y-2 max-h-[200px] overflow-y-auto custom-scrollbar",children:[x.map((t,i)=>e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-xs text-gray-600 w-5 text-right",children:i+1}),e.jsx(Wt,{className:"w-3 h-3 text-gray-600 flex-shrink-0"}),e.jsx("span",{className:"text-sm text-gray-300 flex-1 truncate",children:t.location}),e.jsx("span",{className:"text-xs text-gray-500",children:t.count}),e.jsxs("span",{className:"text-xs font-medium text-white w-10 text-right",children:[t.percentage,"%"]})]},t.location)),x.length===0&&e.jsx("p",{className:"text-xs text-gray-600 text-center py-4",children:"No location data"})]})})]}),e.jsx($,{title:"Top Shared Accounts (by unique devices)",children:b.length===0?e.jsx("p",{className:"text-sm text-gray-500 text-center py-6",children:"No account sharing detected"}):e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"border-b border-gray-800",children:[e.jsx("th",{className:"text-left py-2 px-3 text-xs font-medium text-gray-500",children:"VIP Code"}),e.jsx("th",{className:"text-left py-2 px-3 text-xs font-medium text-gray-500",children:"Notes"}),e.jsx("th",{className:"text-left py-2 px-3 text-xs font-medium text-gray-500",children:"Type"}),e.jsx("th",{className:"text-center py-2 px-3 text-xs font-medium text-gray-500",children:"Devices"}),e.jsx("th",{className:"text-center py-2 px-3 text-xs font-medium text-gray-500",children:"Sessions"}),e.jsx("th",{className:"text-right py-2 px-3 text-xs font-medium text-gray-500",children:"Last Active"})]})}),e.jsx("tbody",{children:b.map(t=>{const i=t.uniqueDevices>=3?"high":t.uniqueDevices>=2?"medium":"normal";return e.jsxs("tr",{className:"border-b border-gray-800/50 hover:bg-white/[0.02] transition-colors",children:[e.jsx("td",{className:"py-2.5 px-3",children:e.jsx("span",{className:"font-mono text-white text-xs",children:t.code})}),e.jsx("td",{className:"py-2.5 px-3 text-xs text-gray-400 max-w-[150px] truncate",children:t.notes||"-"}),e.jsx("td",{className:"py-2.5 px-3",children:t.accountType&&e.jsx("span",{className:`px-1.5 py-0.5 text-[10px] rounded ${t.accountType==="paid"?"bg-emerald-500/20 text-emerald-400":"bg-gray-600/30 text-gray-400"}`,children:t.accountType.toUpperCase()})}),e.jsx("td",{className:"py-2.5 px-3 text-center",children:e.jsx("span",{className:`inline-flex items-center justify-center w-7 h-7 rounded-lg text-xs font-bold ${i==="high"?"bg-red-500/20 text-red-400":i==="medium"?"bg-amber-500/20 text-amber-400":"bg-gray-700 text-gray-300"}`,children:t.uniqueDevices})}),e.jsx("td",{className:"py-2.5 px-3 text-center text-xs text-gray-400",children:t.totalSessions}),e.jsx("td",{className:"py-2.5 px-3 text-right text-xs text-gray-500",children:t.lastActivity?new Date(t.lastActivity).toLocaleDateString("en",{month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"}):"-"})]},t.code)})})]})})}),e.jsxs("div",{className:"grid grid-cols-1 xl:grid-cols-2 gap-4",children:[e.jsx($,{title:"Top Domains: Highest Fail Rate (Extraction)",children:lt.length===0?e.jsx("p",{className:"text-xs text-gray-600 text-center py-8",children:"No extraction telemetry yet"}):e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"border-b border-gray-800",children:[e.jsx("th",{className:"text-left py-2 px-3 text-xs font-medium text-gray-500",children:"Domain"}),e.jsx("th",{className:"text-center py-2 px-3 text-xs font-medium text-gray-500",children:"Attempts"}),e.jsx("th",{className:"text-center py-2 px-3 text-xs font-medium text-gray-500",children:"Success %"}),e.jsx("th",{className:"text-center py-2 px-3 text-xs font-medium text-gray-500",children:"Last Mode"}),e.jsx("th",{className:"text-right py-2 px-3 text-xs font-medium text-gray-500",children:"Last Seen"})]})}),e.jsx("tbody",{children:lt.map(t=>e.jsxs("tr",{className:"border-b border-gray-800/50 hover:bg-white/[0.02] transition-colors",children:[e.jsx("td",{className:"py-2.5 px-3 text-xs text-white font-mono",children:t.domain}),e.jsx("td",{className:"py-2.5 px-3 text-center text-xs text-gray-300",children:t.totalAttempts}),e.jsx("td",{className:"py-2.5 px-3 text-center",children:e.jsxs("span",{className:`inline-flex items-center justify-center px-2 py-0.5 rounded text-xs ${t.successRatePct<60?"bg-rose-500/15 text-rose-300":t.successRatePct<85?"bg-amber-500/15 text-amber-300":"bg-emerald-500/15 text-emerald-300"}`,children:[t.successRatePct.toFixed(1),"%"]})}),e.jsx("td",{className:"py-2.5 px-3 text-center text-[11px] text-cyan-300",children:t.lastExtractionMode}),e.jsx("td",{className:"py-2.5 px-3 text-right text-xs text-gray-500",children:t.lastSeenAt?new Date(t.lastSeenAt).toLocaleStr
14ing():"-"})]},t.domain))})]})})}),e.jsx($,{title:"Top Domains: Reader Fallback Most Used",children:it.length===0?e.jsx("p",{className:"text-xs text-gray-600 text-center py-8",children:"No reader-fallback usage detected yet"}):e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"border-b border-gray-800",children:[e.jsx("th",{className:"text-left py-2 px-3 text-xs font-medium text-gray-500",children:"Domain"}),e.jsx("th",{className:"text-center py-2 px-3 text-xs font-medium text-gray-500",children:"Reader Count"}),e.jsx("th",{className:"text-center py-2 px-3 text-xs font-medium text-gray-500",children:"Usage %"}),e.jsx("th",{className:"text-center py-2 px-3 text-xs font-medium text-gray-500",children:"Avg Len"}),e.jsx("th",{className:"text-right py-2 px-3 text-xs font-medium text-gray-500",children:"Last Seen"})]})}),e.jsx("tbody",{children:it.map(t=>{const i=t.totalAttempts>0?t.readerFallbackCount/t.totalAttempts*100:0;return e.jsxs("tr",{className:"border-b border-gray-800/50 hover:bg-white/[0.02] transition-colors",children:[e.jsx("td",{className:"py-2.5 px-3 text-xs text-white font-mono",children:t.domain}),e.jsx("td",{className:"py-2.5 px-3 text-center text-xs text-amber-300 font-semibold",children:t.readerFallbackCount}),e.jsxs("td",{className:"py-2.5 px-3 text-center text-xs text-gray-300",children:[i.toFixed(1),"%"]}),e.jsx("td",{className:"py-2.5 px-3 text-center text-xs text-gray-400",children:Math.round(t.avgContentLength)}),e.jsx("td",{className:"py-2.5 px-3 text-right text-xs text-gray-500",children:t.lastSeenAt?new Date(t.lastSeenAt).toLocaleString():"-"})]},t.domain)})})]})})})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3 flex-wrap",children:[e.jsxs("h3",{className:"text-lg font-bold text-white flex items-center gap-2",children:[e.jsx(pt,{className:"w-5 h-5 text-cyan-400"}),"Jarvis Tool Access Telemetry"]}),e.jsx("div",{className:"flex items-center gap-2",children:[7,30].map(t=>e.jsxs("button",{onClick:()=>wt(t),className:`px-2.5 py-1 rounded-md text-xs font-medium transition-all ${we===t?"bg-cyan-500/20 text-cyan-300 border border-cyan-500/40":"text-gray-500 hover:text-gray-300 border border-gray-800"}`,children:[t,"D"]},t))})]}),e.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-3 xl:grid-cols-6 gap-3",children:[e.jsx(v,{icon:te,label:"Total Attempts",value:R(ge.totalAttempts),color:"cyan"}),e.jsx(v,{icon:te,label:"Pass Rate",value:`${ge.passRate}%`,color:"emerald"}),e.jsx(v,{icon:te,label:"Success",value:R(ge.successAttempts),color:"blue"}),e.jsx(v,{icon:oe,label:"Failures",value:R(ge.failAttempts),color:"rose"}),e.jsx(v,{icon:te,label:"Healthy Cells",value:R(ge.healthy),color:"teal"}),e.jsx(v,{icon:oe,label:"Critical Cells",value:R(ge.critical),color:"amber"})]}),e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-4",children:[e.jsx($,{title:"Daily Pass Rate Trend",children:G.length===0?e.jsx("p",{className:"text-xs text-gray-600 text-center py-8",children:"No tool telemetry yet"}):e.jsx(ye,{width:"100%",height:240,children:e.jsxs(ut,{data:[...G].reverse(),children:[e.jsx(be,{strokeDasharray:"3 3",stroke:"#1f2937"}),e.jsx(_e,{dataKey:"metric_date",tick:{fill:"#6b7280",fontSize:10},tickLine:!1,axisLine:!1}),e.jsx(de,{tick:{fill:"#6b7280",fontSize:10},tickLine:!1,axisLine:!1,width:35,domain:[0,100]}),e.jsx(je,{content:fe}),e.jsx(Se,{wrapperStyle:{fontSize:11,color:"#9ca3af"},iconType:"circle",iconSize:8}),e.jsx(Je,{type:"monotone",dataKey:"pass_rate_percent",name:"Pass Rate %",stroke:"#10b981",strokeWidth:2,dot:{r:2}})]})})}),e.jsx($,{title:"Daily Quality Buckets",children:G.length===0?e.jsx("p",{className:"text-xs text-gray-600 text-center py-8",children:"No tool telemetry yet"}):e.jsx(ye,{width:"100%",height:240,children:e.jsxs(Ze,{data:[...G].reverse(),children:[e.jsx(be,{strokeDasharray:"3 3",stroke:"#1f2937"}),e.jsx(_e,{dataKey:"metric_date",tick:{fill:"#6b7280",fontSize:10},tickLine:!1,axisLine:!1}),e.jsx(de,{tick:{fill:"#6b7280",fontSize:10}
14,tickLine:!1,axisLine:!1,width:35}),e.jsx(je,{content:fe}),e.jsx(Se,{wrapperStyle:{fontSize:11,color:"#9ca3af"},iconType:"circle",iconSize:8}),e.jsx(ve,{dataKey:"healthy_cells",name:"Healthy",fill:"#10b981",radius:[3,3,0,0]}),e.jsx(ve,{dataKey:"warning_cells",name:"Warning",fill:"#f59e0b",radius:[3,3,0,0]}),e.jsx(ve,{dataKey:"critical_cells",name:"Critical",fill:"#ef4444",radius:[3,3,0,0]})]})})})]}),e.jsx($,{title:"Top Tool Commands (by volume)",children:ct.length===0?e.jsx("p",{className:"text-xs text-gray-600 text-center py-8",children:"No tool telemetry yet"}):e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 xl:grid-cols-3 gap-3",children:ct.slice(0,6).map(t=>e.jsxs("div",{className:"bg-gray-900/40 border border-gray-800 rounded-lg p-3",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3 mb-1",children:[e.jsx("span",{className:"text-sm text-white font-medium truncate",children:t.feature}),e.jsxs("span",{className:`text-[11px] px-2 py-0.5 rounded ${t.passRate>=80?"bg-emerald-500/15 text-emerald-300":t.passRate>=50?"bg-amber-500/15 text-amber-300":"bg-rose-500/15 text-rose-300"}`,children:[t.passRate.toFixed(1),"%"]})]}),e.jsxs("p",{className:"text-xs text-gray-500",children:[t.targetTab,t.toolboxTab?` ⢠${t.toolboxTab}`:""]}),e.jsxs("p",{className:"text-xs text-gray-400 mt-2",children:["Attempts: ",t.total," | Success: ",t.success," | Fail: ",t.fail]})]},`${t.feature}-${t.targetTab}-${t.toolboxTab}`))})}),e.jsx($,{title:"Tool Access Matrix",children:se.length===0?e.jsx("p",{className:"text-xs text-gray-600 text-center py-8",children:"No tool access rows yet"}):e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"border-b border-gray-800",children:[e.jsx("th",{className:"text-left py-2 px-3 text-xs font-medium text-gray-500",children:"Date"}),e.jsx("th",{className:"text-left py-2 px-3 text-xs font-medium text-gray-500",children:"Feature"}),e.jsx("th",{className:"text-left py-2 px-3 text-xs font-medium text-gray-500",children:"Target"}),e.jsx("th",{className:"text-left py-2 px-3 text-xs font-medium text-gray-500",children:"Toolbox Tab"}),e.jsx("th",{className:"text-center py-2 px-3 text-xs font-medium text-gray-500",children:"Attempts"}),e.jsx("th",{className:"text-center py-2 px-3 text-xs font-medium text-gray-500",children:"Success"}),e.jsx("th",{className:"text-center py-2 px-3 text-xs font-medium text-gray-500",children:"Fail"}),e.jsx("th",{className:"text-center py-2 px-3 text-xs font-medium text-gray-500",children:"Pass Rate"})]})}),e.jsx("tbody",{children:se.slice(0,20).map(t=>e.jsxs("tr",{className:"border-b border-gray-800/50 hover:bg-white/[0.02] transition-colors",children:[e.jsx("td",{className:"py-2.5 px-3 text-xs text-gray-500 whitespace-nowrap",children:t.metric_date}),e.jsx("td",{className:"py-2.5 px-3 text-xs text-white",children:t.resolved_feature}),e.jsx("td",{className:"py-2.5 px-3 text-xs text-gray-300",children:t.target_tab}),e.jsx("td",{className:"py-2.5 px-3 text-xs text-gray-300",children:t.toolbox_tab}),e.jsx("td",{className:"py-2.5 px-3 text-center text-xs text-gray-300",children:t.total_attempts}),e.jsx("td",{className:"py-2.5 px-3 text-center text-xs text-emerald-300",children:t.successful_attempts}),e.jsx("td",{className:"py-2.5 px-3 text-center text-xs text-rose-300",children:t.failed_attempts}),e.jsx("td",{className:"py-2.5 px-3 text-center",children:e.jsxs("span",{className:`inline-flex items-center justify-center px-2 py-0.5 rounded text-xs ${t.pass_rate_percent>=80?"bg-emerald-500/15 text-emerald-300":t.pass_rate_percent>=50?"bg-amber-500/15 text-amber-300":"bg-rose-500/15 text-rose-300"}`,children:[t.pass_rate_percent.toFixed(1),"%"]})})]},`${t.metric_date}-${t.resolved_feature}-${t.target_tab}-${t.toolbox_tab}`))})]})})}),e.jsx($,{title:"Failure Reasons â à¸à¸³à¹à¸¡à¹à¸à¸¥à¸¥à¹à¸à¸¶à¸à¹à¸à¹à¸ Warning / Critical",children:z.length===0?e.jsx("p",{className:"text-xs text-gray-600 text-center py-8",children:"à¹à¸¡à¹à¸¡à¸µ failure à¹à¸à¸à¹à¸§à¸à¸à¸µà¹ â à¸à¸¸à¸à¸à¸³à¸ªà¸±à¹à¸à¹à¸à¹à¸²à¸à¸¶à¸à¹à¸à¸£à¸·à¹à¸à¸à¸¡à¸·à¸à¸ªà¸³à¹à¸£à¹à¸"}):e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"border-b border-gray-800",children:[e.jsx("th",{className:"text-left py-2 px-3 text-xs font-medium text-gray-500",children:"Feature"}),e.jsx("th",{className:"text-left py-2 px-3 text-xs font-medium text-gray-500",children:"Failure Reason"}),e.jsx("th",{className:"text-left py-2 px-3 text-xs font-medium text-gray-500",children:"Meaning / Fix"}),e.jsx("th",{className:"text-center py-2 px-3 text-xs font-medium text-gray-500",children:"Count"}),e.jsx("th",{className:"text-left py-2 px-3 text-xs font-medium text-gray-500",children:"Last Command"}),e.jsx("th",{className:"text-left py-2 px-3 text-xs font-medium text-gray-500",children:"VIP Code"}),e.jsx("th",{className:"text-right py-2 px-3 text-xs font-medium text-gray-500",children:"Last Seen"}),e.jsx("th",{className:"text-center py-2 px-3 text-xs font-medium text-gray-500",children:"à¹à¸à¹à¹à¸¥à¹à¸§?"})]})}),e.jsx("tbody",{children:z.map(t=>{const i=Ss(t.failure_reason),d=Rs(t.resolved_at,t.last_seen),S=async()=>{const C=d!=="resolved",y=t.resolved_at,L=B=>tt(F=>F.map(V=>V.resolved_feature===t.resolved_feature&&V.failure_reason===t.failure_reason?{...V,resolved_at:B}:V));L(C?new Date().toISOString():null),await js(t.resolved_feature,t.failure_reason,C)||L(y)};return e.jsxs("tr",{className:`border-b border-gray-800/50 hover:bg-white/[0.02] transition-colors align-top ${d==="resolved"?"opacity-45":""}`,children:[e.jsx("td",{className:"py-2.5 px-3 text-xs text-white whitespace-nowrap",children:t.resolved_feature}),e.jsx("td",{className:`py-2.5 px-3 text-xs max-w-[220px] break-words ${d==="resolved"?"text-gray-400 line-through":"text-rose-300"}`,children:t.failure_reason}),e.jsxs("td",{className:"py-2.5 px-3 text-xs text-gray-400 max-w-[280px]",children:[e.jsx("span",{className:`inline-block mb-1 px-1.5 py-0.5 rounded text-[10px] font-medium ${i.kind==="expected"?"bg-amber-500/15 text-amber-300":"bg-rose-500/15 text-rose-300"}`,children:i.kind==="expected"?"Expected":"Bug"}),e.jsx("span",{className:"block",children:i.text})]}),e.jsx("td",{className:"py-2.5 px-3 text-center text-xs text-rose-300",children:t.fail_count}),e.jsx("td",{className:"py-2.5 px-3 text-xs text-gray-300 font-mono max-w-[160px] truncate",title:t.sample_command,children:t.sample_command||"-"}),e.jsxs("td",{className:"py-2.5 px-3 text-xs whitespace-nowrap",children:[t.sample_vip_code?e.jsx("span",{className:"font-mono text-emerald-300",children:t.sample_vip_code}):e.jsx("span",{className:"text-gray-600",children:"à¹à¸¡à¹à¸£à¸°à¸à¸¸"}),t.distinct_users>1&&e.jsxs("span",{className:"ml-1 text-[10px] text-gray-500",children:["+",t.distinct_users-1," à¸à¸"]})]}),e.jsx("td",{className:"py-2.5 px-3 text-right text-xs text-gray-500 whitespace-nowrap",children:t.last_seen?new Date(t.last_seen).toLocaleStr
14ing():"-"}),e.jsx("td",{className:"py-2.5 px-3 text-center whitespace-nowrap",children:e.jsxs("button",{onClick:S,title:d==="resolved"?"à¸à¸³à¹à¸à¸£à¸·à¹à¸à¸à¸«à¸¡à¸²à¸¢à¸§à¹à¸²à¸¢à¸±à¸à¹à¸¡à¹à¹à¸à¹":d==="regressed"?"à¹à¸à¸´à¸à¸à¹à¸³à¸«à¸¥à¸±à¸à¹à¸à¹ â à¸à¸à¹à¸à¸·à¹à¸à¸¢à¸·à¸à¸¢à¸±à¸à¹à¸à¹à¸à¸µà¸à¸à¸£à¸±à¹à¸":"à¸à¸³à¹à¸à¸£à¸·à¹à¸à¸à¸«à¸¡à¸²à¸¢à¸§à¹à¸²à¹à¸à¹à¹à¸¥à¹à¸§",className:`inline-flex items-center gap-1 px-2 py-1 rounded text-[11px] font-medium transition-colors ${d==="resolved"?"bg-emerald-500/15 text-emerald-300 hover:bg-emerald-500/25":d==="regressed"?"bg-amber-500/15 text-amber-300 hover:bg-amber-500/25":"bg-white/[0.04] text-gray-400 hover:bg-emerald-500/15 hover:text-emerald-300"}`,children:[e.jsx(te,{className:"w-3.5 h-3.5"}),d==="resolved"?"à¹à¸à¹à¹à¸¥à¹à¸§":d==="regressed"?"à¹à¸à¸´à¸à¸à¹à¸³!":"ยัà¸à¹à¸¡à¹à¹à¸à¹"]})})]},`${t.resolved_feature}-${t.failure_reason}-${t.last_seen}`)})})]})})}),e.jsxs("div",{className:"flex items-center justify-between gap-3 flex-wrap",children:[e.jsxs("h3",{className:"text-lg font-bold text-white flex items-center gap-2",children:[e.jsx(oe,{className:"w-5 h-5 text-rose-400"}),"Verification Telemetry"]}),e.jsx("div",{className:"flex items-center gap-2",children:[7,30].map(t=>e.jsxs("button",{onClick:()=>St(t),className:`px-2.5 py-1 rounded-md text-xs font-medium transition-all ${De===t?"bg-rose-500/20 text-rose-300 border border-rose-500/40":"text-gray-500 hover:text-gray-300 border border-gray-800"}`,children:[t,"D"]},t))})]}),ne.status==="insufficient"?e.jsx("div",{className:"rounded-xl border border-gray-800 bg-white/[0.02] p-4",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"p-2.5 rounded-lg bg-gray-500/15",children:e.jsx(Ce,{className:"w-5 h-5 text-gray-400"})}),e.jsxs("div",{children:[e.jsx("div",{className:"text-sm font-semibold text-gray-300",children:"System Health â à¸à¹à¸à¸¡à¸¹à¸¥à¹à¸¡à¹à¸à¸à¸à¸£à¸°à¹à¸¡à¸´à¸"}),e.jsx("p",{className:"text-xs text-gray-500",children:ne.verdict})]})]})}):e.jsxs("div",{className:`rounded-xl border p-4 bg-gradient-to-br ${ee.bg} ${ee.border}`,children:[e.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center gap-4",children:[e.jsxs("div",{className:"flex items-center gap-3 sm:w-60 shrink-0",children:[e.jsx("div",{className:`p-2.5 rounded-lg ${ee.iconBg}`,children:ne.status==="healthy"?e.jsx(te,{className:`w-6 h-6 ${ee.text}`}):e.jsx(oe,{className:`w-6 h-6 ${ee.text}`})}),e.jsxs("div",{children:[e.jsx("div",{className:"text-[11px] text-gray-500 uppercase tracking-wide",children:"System Health"}),e.jsxs("div",{className:"flex items-baseline gap-1.5",children:[e.jsx("span",{className:`text-3xl font-bold ${ee.text}`,children:ne.score}),e.jsx("span",{className:"text-sm text-gray-500",children:"/100"}),e.jsx("span",{className:`text-sm font-semibold ml-1 ${ee.text}`,children:ee.label})]})]})]}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"text-xs text-gray-400 mb-2",children:ne.verdict}),e.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-3 gap-2",children:ne.signals.map(t=>e.jsxs("div",{className:"rounded-lg bg-black/20 border border-gray-800 px-2.5 py-2",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("span",{className:"text-[11px] text-gray-400 truncate",children:t.label}),e.jsx("span",{className:`text-[11px] font-semibold ${Ts(t.score)}`,children:t.score})]}),e.jsx("div",{className:"h-1 rounded-full bg-gray-800 mt-1.5 overflow-hidden",children:e.jsx("div",{className:`h-full rounded-full ${Ds(t.score)}`,style:{width:`${t.score}%`}})}),e.jsx("div",{className:"text-[10px] text-gray-600 mt-1 truncate",children:t.detail})]},t.key))})]})]}),e.jsx("p",{className:"text-[10px] text-gray-600 mt-3",children:"à¸à¸°à¹à¸à¸à¸§à¸±à¸ âà¸à¸§à¸²à¸¡à¸à¸à¸à¸´à¸à¸à¸ telemetryâ à¹à¸à¸µà¸¢à¸ baseline 30 วัà¸à¸à¸à¸à¸à¸±à¸§à¹à¸à¸ (à¸à¸£à¸´à¸¡à¸²à¸ · à¸à¸§à¸²à¸¡à¸¡à¸±à¹à¸à¹à¸ · สัà¸à¸ªà¹à¸§à¸à¸£à¸¹à¸à¹à¸à¸à¹à¸ªà¸µà¹à¸¢à¸) â à¹à¸¡à¹à¹à¸à¹à¸§à¸±à¸à¸à¸³à¹à¸£/à¸à¸²à¸à¸à¸¸à¸à¸à¸à¸à¸ªà¸±à¸à¸à¸²à¸"})]}),e.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-3",children:[e.jsx(v,{icon:oe,label:"Conflicts (Top 10)",value:R(K.totalConflicts),color:"rose"}),e.jsx(v,{icon:Be,label:"Affected Logs",value:R(K.totalLogs),color:"amber"}),e.jsx(v,{icon:te,label:"Avg Confidence",value:`${K.avgConfidence}%`,color:"emerald"}),e.jsx(v,{icon:Ie,label:"Top Conflict",value:K.topType==="-"?"-":K.topType.replace(/_/g," "),sub:K.topType==="-"?void 0:gt(K.topType),color:"cyan"})]}),e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-4",children:[e.jsx($,{title:"Verification Daily Trend (30d)",children:Me.length===0?e.jsx("p",{className:"text-xs text-gray-600 text-center py-8",children:"No verification telemetry yet"}):e.jsx(ye,{width:"100%",height:240,children:e.jsxs(ut,{data:Me,children:[e.jsx(be,{strokeDasharray:"3 3",stroke:"#1f2937"}),e.jsx(_e,{dataKey:"metric_date",tick:{fill:"#6b7280",fontSize:10}
14,tickLine:!1,axisLine:!1}),e.jsx(de,{yAxisId:"left",tick:{fill:"#6b7280",fontSize:10},tickLine:!1,axisLine:!1,width:35}),e.jsx(de,{yAxisId:"right",orientation:"right",domain:[0,100],tick:{fill:"#6b7280",fontSize:10},tickLine:!1,axisLine:!1,width:35}),e.jsx(je,{content:fe}),e.jsx(Se,{wrapperStyle:{fontSize:11,color:"#9ca3af"},iconType:"circle",iconSize:8}),e.jsx(Je,{yAxisId:"left",type:"monotone",dataKey:"conflict_count",name:"Conflict Count",stroke:"#f97316",strokeWidth:2,dot:{r:2}}),e.jsx(Je,{yAxisId:"right",type:"monotone",dataKey:"avg_confidence",name:"Avg Confidence",stroke:"#10b981",strokeWidth:2,dot:{r:2}})]})})}),e.jsx($,{title:`Top Verification Conflicts (${De}d)`,children:X.length===0?e.jsx("p",{className:"text-xs text-gray-600 text-center py-8",children:"No verification conflicts yet"}):e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"border-b border-gray-800",children:[e.jsx("th",{className:"text-left py-2 px-3 text-xs font-medium text-gray-500",children:"Conflict Type"}),e.jsx("th",{className:"text-center py-2 px-3 text-xs font-medium text-gray-500",children:"Count"}),e.jsx("th",{className:"text-center py-2 px-3 text-xs font-medium text-gray-500",children:"Logs"}),e.jsx("th",{className:"text-center py-2 px-3 text-xs font-medium text-gray-500",children:"Avg Conf"}),e.jsx("th",{className:"text-right py-2 px-3 text-xs font-medium text-gray-500",children:"Last Seen"})]})}),e.jsx("tbody",{children:X.map(t=>e.jsxs("tr",{className:"border-b border-gray-800/50 hover:bg-white/[0.02] transition-colors",children:[e.jsxs("td",{className:"py-2.5 px-3 text-xs",children:[e.jsx("div",{className:"text-white",children:t.conflict_type}),e.jsx("div",{className:"text-[11px] text-gray-500 mt-0.5",children:gt(t.conflict_type)})]}),e.jsx("td",{className:"py-2.5 px-3 text-center text-xs text-rose-300",children:t.conflict_count}),e.jsx("td",{className:"py-2.5 px-3 text-center text-xs text-gray-300",children:t.affected_logs}),e.jsxs("td",{className:"py-2.5 px-3 text-center text-xs text-emerald-300",children:[t.avg_confidence.toFixed(1),"%"]}),e.jsx("td",{className:"py-2.5 px-3 text-right text-xs text-gray-500",children:t.recent_seen?new Date(t.recent_seen).toLocaleString():"-"})]},`${t.conflict_type}-${t.recent_seen}`))})]})})})]})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("h3",{className:"text-lg font-bold text-white flex items-center gap-2",children:[e.jsx(Ie,{className:"w-5 h-5 text-cyan-400"}),"Auto-Trade Asset Funnel"]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("button",{onClick:Mt,className:"px-3 py-1 rounded-md border border-cyan-500/40 bg-cyan-500/10 text-xs text-cyan-300 hover:text-cyan-200 hover:bg-cyan-500/15 transition-all",children:"Export Funnel CSV"}),e.jsx("button",{onClick:Lt,className:"px-3 py-1 rounded-md border border-amber-500/40 bg-amber-500/10 text-xs text-amber-300 hover:text-amber-200 hover:bg-amber-500/15 transition-all",children:"Export Block CSV"}),[1,7,30].map(t=>e.jsxs("button",{onClick:()=>kt(t),className:`px-2.5 py-1 rounded-md text-xs font-medium transition-all ${Y===t?"bg-cyan-500/20 text-cyan-300 border border-cyan-500/40":"text-gray-500 hover:text-gray-300 border border-gray-800"}`,children:[t,"D"]},t))]})]}),e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-4",children:[e.jsx($,{title:"Broadcast vs Executed by Asset",children:_.length===0?e.jsx("p",{className:"text-xs text-gray-600 text-center py-8",children:"No funnel data for selected range"}):e.jsx(ye,{width:"100%",height:260,children:e.jsxs(Ze,{data:_,children:[e.jsx(be,{strokeDasharray:"3 3",stroke:"#1f2937"}),e.jsx(_e,{dataKey:"asset",tick:{fill:"#6b7280",fontSize:10},tickLine:!1,axisLine:!1}),e.jsx(de,{tick:{fill:"#6b7280",fontSize:10},tickLine:!1,axisLine:!1,width:30}),e.jsx(je,{content:fe}),e.jsx(Se,{wrapperStyle:{fontSize:11,color:"#9ca3af"},iconType:"circle",iconSize:8}),e.jsx(ve,{dataKey:"broadcasts",name:"Broadcasts",fill:"#0ea5e9",radius:[3,3,0,0]}),e.jsx(ve,{dataKey:"executions",name:"Executions",fill:"#10b981",radius:[3,3,0,0]})]})})}),e.jsx($,{title:"Biggest Drop-off Assets",children:_.length===0?e.jsx("p",{className:"text-xs text-gray-600 text-center py-8",children:"No data yet"}):e.jsx("div",{className:"space-y-2.5",children:[..._].sort((t,i)=>i.dropOff-t.dropOff).slice(0,8).map(t=>e.jsxs("div",{className:"bg-gray-900/40 border border-gray-800 rounded-lg p-2.5",children:[e.jsxs("div",{className:"flex items-center justify-between text-xs mb-1",children:[e.jsx("span",{className:"text-white font-mono",children:t.asset}),e.jsxs("span",{className:"text-gray-400",children:[t.executions,"/",t.broadcasts," (",t.conversionRate,"%)"]})]}),e.jsx("div",{className:"w-full h-1.5 bg-gray-800 rounded-full overflow-hidden",children:e.jsx("div",{className:"h-full rounded-full bg-emerald-500 transition-all duration-700",style:{width:`${Math.min(t.conversionRate,100)}%`}})})]},t.asset))})})]}),e.jsxs($,{title:"Per-Account Block Reason Monitor (by asset)",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-3",children:[e.jsx("select",{value:pe,onCh
14ange:t=>Ct(t.target.value),className:"px-2 py-1 rounded border border-gray-700 bg-gray-800 text-xs text-gray-300",children:Rt.map(t=>e.jsx("option",{value:t,children:t},t))}),e.jsxs("select",{value:ae,onChange:t=>At(t.target.value),className:"px-2 py-1 rounded border border-gray-700 bg-gray-800 text-xs text-gray-300",children:[e.jsx("option",{value:"all",children:"All Status"}),e.jsx("option",{value:"blocked",children:"Blocked"}),e.jsx("option",{value:"executed",children:"Executed"}),e.jsx("option",{value:"errors",children:"Errors"})]}),e.jsxs("span",{className:"text-[11px] text-gray-500",children:["Showing ",he.length," asset(s)"]})]}),U.length===0?e.jsx("p",{className:"text-xs text-gray-600 text-center py-8",children:"No account-level monitor logs yet. New logs will appear after auto-trade attempts."}):e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"border-b border-gray-800",children:[e.jsx("th",{className:"text-left py-2 px-3 text-xs font-medium text-gray-500",children:"Asset"}),e.jsx("th",{className:"text-center py-2 px-3 text-xs font-medium text-gray-500",children:"Attempts"}),e.jsx("th",{className:"text-center py-2 px-3 text-xs font-medium text-gray-500",children:"Blocked"}),e.jsx("th",{className:"text-center py-2 px-3 text-xs font-medium text-gray-500",children:"Executed"}),e.jsx("th",{className:"text-center py-2 px-3 text-xs font-medium text-gray-500",children:"Errors"}),e.jsx("th",{className:"text-center py-2 px-3 text-xs font-medium text-gray-500",children:"Block Rate"}),e.jsx("th",{className:"text-center py-2 px-3 text-xs font-medium text-gray-500",children:"Exec Rate"}),e.jsx("th",{className:"text-left py-2 px-3 text-xs font-medium text-gray-500",children:"Top Block Reason"})]})}),e.jsx("tbody",{children:he.map(t=>{const i=t.attempts>0?Math.round(t.blocked/t.attempts*1e3)/10:0,d=t.attempts>0?Math.round(t.executed/t.attempts*1e3)/10:0;return e.jsxs("tr",{className:"border-b border-gray-800/50 hover:bg-white/[0.02] transition-colors",children:[e.jsx("td",{className:"py-2.5 px-3 text-xs text-white font-mono",children:t.asset}),e.jsx("td",{className:"py-2.5 px-3 text-center text-xs text-gray-300",children:t.attempts}),e.jsx("td",{className:"py-2.5 px-3 text-center",children:e.jsx("span",{className:"inline-flex items-center justify-center px-2 py-0.5 rounded bg-amber-500/15 text-amber-300 text-xs",children:t.blocked})}),e.jsx("td",{className:"py-2.5 px-3 text-center",children:e.jsx("span",{className:"inline-flex items-center justify-center px-2 py-0.5 rounded bg-emerald-500/15 text-emerald-300 text-xs",children:t.executed})}),e.jsx("td",{className:"py-2.5 px-3 text-center",children:e.jsx("span",{className:"inline-flex items-center justify-center px-2 py-0.5 rounded bg-rose-500/15 text-rose-300 text-xs",children:t.errors})}),e.jsxs("td",{className:"py-2.5 px-3 text-center text-xs text-amber-300",children:[i,"%"]}),e.jsxs("td",{className:"py-2.5 px-3 text-center text-xs text-emerald-300",children:[d,"%"]}),e.jsx("td",{className:"py-2.5 px-3 text-xs text-gray-300 max-w-[420px] truncate",title:t.topBlockReason,children:t.topBlockReason})]},t.asset)})})]})})]}),e.jsx($,{title:"Anti-Flip Blocks (Hourly by Account)",children:I.length===0?e.jsx("p",{className:"text-xs text-gray-600 text-center py-8",children:"No anti-flip / duplicate-alias cooldown blocks in selected window yet."}):e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"border-b border-gray-800",children:[e.jsx("th",{className:"text-left py-2 px-3 text-xs font-medium text-gray-500",children:"Hour"}),e.jsx("th",{className:"text-left py-2 px-3 text-xs font-medium text-gray-500",children:"VIP"}),e.jsx("th",{className:"text-left py-2 px-3 text-xs font-medium text-gray-500",children:"Account"}),e.jsx("th",{className:"text-left py-2 px-3 text-xs font-medium text-gray-500",children:"Broker"}),e.jsx("th",{className:"text-left py-2 px-3 text-xs font-medium text-gray-500",children:"Reason"}),e.jsx("th",{className:"text-center py-2 px-3 text-xs font-medium text-gray-500",children:"Blocks"})]})}),e.jsx("tbody",{children:I.slice(0,120).map((t,i)=>e.jsxs("tr",{className:"border-b border-gray-800/50 hover:bg-white/[0.02] transition-colors",children:[e.jsx("td",{className:"py-2.5 px-3 text-xs text-gray-300 whitespace-nowrap",children:new Date(t.hourBucket).toLocaleStr
14ing()}),e.jsx("td",{className:"py-2.5 px-3 text-xs text-white font-mono",children:t.vipCode}),e.jsx("td",{className:"py-2.5 px-3 text-xs text-gray-300 font-mono",children:t.accountId}),e.jsx("td",{className:"py-2.5 px-3 text-xs text-gray-300",children:t.broker}),e.jsx("td",{className:"py-2.5 px-3 text-xs text-gray-300",children:t.reasonCode==="anti_flip_cooldown"?"anti_flip_cooldown":"duplicate_alias_cooldown"}),e.jsx("td",{className:"py-2.5 px-3 text-center",children:e.jsx("span",{className:"inline-flex items-center justify-center px-2 py-0.5 rounded bg-amber-500/15 text-amber-300 text-xs",children:t.blockedCount})})]},`${t.hourBucket}-${t.accountId}-${t.reasonCode}-${i}`))})]})})})]}),A&&e.jsxs("div",{className:"space-y-4",children:[e.jsxs("h3",{className:"text-lg font-bold text-white flex items-center gap-2",children:[e.jsx(Xt,{className:"w-5 h-5 text-teal-400"}),"User Behavior Tracking"]}),e.jsxs("div",{className:"grid grid-cols-3 gap-3",children:[e.jsx(v,{icon:Ie,label:"Events (7d)",value:R(A.totalEvents7d),color:"teal"}),e.jsx(v,{icon:mt,label:"Events (24h)",value:R(A.totalEvents24h),color:"amber"}),e.jsx(v,{icon:Be,label:"Avg Events / User",value:A.avgEventsPerUser,color:"sky"})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-4",children:[e.jsx($,{title:"Top Features",children:A.topFeatures.length===0?e.jsx("p",{className:"text-xs text-gray-600 text-center py-6",children:"No data yet"}):e.jsx("div",{className:"space-y-2.5",children:A.topFeatures.map((t,i)=>e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-[10px] text-gray-600 w-4 text-right",children:i+1}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center justify-between mb-0.5",children:[e.jsx("span",{className:"text-xs text-gray-300 truncate",title:t.feature,children:It(t.feature)}),e.jsxs("div",{className:"flex items-center gap-2 flex-shrink-0 ml-2",children:[e.jsxs("span",{className:"text-[10px] text-gray-500",children:[t.uniqueUsers,"u"]}),e.jsx("span",{className:"text-xs font-medium text-white",children:R(t.count)}),t.trend==="up"?e.jsx(Pe,{className:"w-3 h-3 text-emerald-400"}):t.trend==="down"?e.jsx(Fe,{className:"w-3 h-3 text-rose-400"}):e.jsx(Ce,{className:"w-3 h-3 text-gray-600"})]})]}),e.jsx("div",{className:"w-full h-1 bg-gray-800 rounded-full overflow-hidden",children:e.jsx("div",{className:"h-full rounded-full bg-teal-500/60 transition-all duration-700",style:{width:`${A.topFeatures[0]?t.count/A.topFeatures[0].count*100:0}%`}})})]})]},t.feature))})}),e.jsx($,{title:"Top Pages",children:A.topPages.length===0?e.jsx("p",{className:"text-xs text-gray-600 text-center py-6",children:"No data yet"}):e.jsx("div",{className:"space-y-2.5",children:A.topPages.map((t,i)=>e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-[10px] text-gray-600 w-4 text-right",children:i+1}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center justify-between mb-0.5",children:[e.jsx("span",{className:"text-xs text-gray-300 truncate",children:t.feature||"/"}),e.jsxs("div",{className:"flex items-center gap-2 flex-shrink-0 ml-2",children:[e.jsxs("span",{className:"text-[10px] text-gray-500",children:[t.uniqueUsers,"u"]}),e.jsx("span",{className:"text-xs font-medium text-white",children:R(t.count)}),t.trend==="up"?e.jsx(Pe,{className:"w-3 h-3 text-emerald-400"}):t.trend==="down"?e.jsx(Fe,{className:"w-3 h-3 text-rose-400"}):e.jsx(Ce,{className:"w-3 h-3 text-gray-600"})]})]}),e.jsx("div",{className:"w-full h-1 bg-gray-800 rounded-full overflow-hidden",children:e.jsx("div",{className:"h-full rounded-full bg-sky-500/60 transition-all duration-700",style:{width:`${A.topPages[0]?t.count/A.topPages[0].count*100:0}%`}})})]})]},t.feature))})}),e.jsx($,{title:"Top Assets",children:A.topAssets.length===0?e.jsx("p",{className:"text-xs text-gray-600 text-center py-6",children:"No data yet"}):e.jsx("div",{className:"space-y-2.5",children:A.topAssets.map((t,i)=>e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-[10px] text-gray-600 w-4 text-right",children:i+1}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center justify-between mb-0.5",children:[e.jsx("span",{className:"text-xs text-gray-300 truncate font-mono",children:t.feature}),e.jsxs("div",{className:"flex items-center gap-2 flex-shrink-0 ml-2",children:[e.jsxs("span",{className:"text-[10px] text-gray-500",children:[t.uniqueUsers,"u"]}),e.jsx("span",{className:"text-xs font-medium text-white",children:R(t.count)}),t.trend==="up"?e.jsx(Pe,{className:"w-3 h-3 text-emerald-400"}):t.trend==="down"?e.jsx(Fe,{className:"w-3 h-3 text-rose-400"}):e.jsx(Ce,{className:"w-3 h-3 text-gray-600"})]})]}),e.jsx("div",{className:"w-full h-1 bg-gray-800 rounded-full overflow-hidden",children:e.jsx("div",{className:"h-full rounded-full bg-amber-500/60 transition-all duration-700",style:{width:`${A.topAssets[0]?t.count/A.topAssets[0].count*100:0}%`}})})]})]},t.feature))})})]})]})]})]})}export{sa as default};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.