1import{dT as Ue,a as qe,c as Qe,r as d,j as e,d as ce,e as Ne,f as we,i as X,Y as Ve,h as de,I as O,$ as ee,a0 as te,a1 as se,a2 as ae,a3 as v,B as w,L as He,W as Ye,ab as p,aC as _e,as as K,Z as ve,aK as je,ci as be,V as xe,o as me,c1 as Ge,c2 as re,c3 as ne,ah as ie,c4 as oe}from"./index-DwBWDKUZ.js";import{a as Ke}from"./AdminLayout-CUJ1KAUs.js";import{f as We}from"./formatDistanceStrict-DH-xqG09.js";import"./separator-3IJlx7Jr.js";import"./radio-CYrbeFui.js";import"./shopping-cart-BS4tH7dF.js";import"./ban-2u0CnJmK.js";import"./message-square-ClqgYCnY.js";import"./globe-5NMmuIgN.js";import"./qr-code-c27LO0Y3.js";import"./zap-B9JmuJoQ.js";import"./useDebounce-Dswy9wwM.js";import"./undo-2-DrAGwRTv.js";import"./target-sTphCb1S.js";import"./gift-DTSOrbmf.js";import"./store-bkBmVJSB.js";import"./book-open-zG6yZAjB.js";import"./circle-plus-q9MabApK.js";import"./link-2-yb_9D2cc.js";import"./index-EBeZJwww.js";import"./database-CSQWWsVg.js";import"./arrow-left-right-CBpwBwL4.js";import"./layout-dashboard-Bx09MTND.js";import"./privateRealtimeChannels-LIJV5W85.js";import"./external-link-aOCC2dcc.js";import"./index-CvvDEDzH.js";import"./index-Cj1mIu5t.js";import"./calendar-days-D-EDctJU.js";import"./shield-86TK9aig.js";function le(r,n){return We(r,Ue(r),n)}const Ze={picker_open:"bg-sky-500/15 hover:bg-sky-500/15 text-sky-700 dark:text-sky-400",day_click:"bg-violet-500/15 hover:bg-violet-500/15 text-violet-700 dark:text-violet-400",search_submit:"bg-emerald-500/15 hover:bg-emerald-500/15 text-emerald-700 dark:text-emerald-400",fingerprint_mismatch:"bg-red-500/15 hover:bg-red-500/15 text-red-700 dark:text-red-400",payload_built:"bg-indigo-500/15 hover:bg-indigo-500/15 text-indigo-700 dark:text-indigo-400",email_dispatch:"bg-teal-500/15 hover:bg-teal-500/15 text-teal-700 dark:text-teal-400",ics_export:"bg-orange-500/15 hover:bg-orange-500/15 text-orange-700 dark:text-orange-400",step_drift_detected:"bg-red-600/20 hover:bg-red-600/20 text-red-800 dark:text-red-300",step_drift_corrected:"bg-amber-500/15 hover:bg-amber-500/15 text-amber-800 dark:text-amber-300",rcm_payload_drift:"bg-rose-600/20 hover:bg-rose-600/20 text-rose-800 dark:text-rose-300"},Je={picker_open:"Picker opened",day_click:"Day clicked",search_submit:"Search submitted",fingerprint_mismatch:"Date mismatch",payload_built:"RCM payload built",email_dispatch:"Email dispatched",ics_export:"Calendar (ICS) export",step_drift_detected:"Step drift detected",step_drift_corrected:"Step drift auto-corrected",rcm_payload_drift:"RCM payload drift"},D=100;function Et(){const r=qe(),{toast:n}=Qe(),[t,m]=d.useState([]),[i,c]=d.useState(!1),[o,f]=d.useState(null),[u,S]=d.useState(0),[_,k]=d.useState(""),[$,q]=d.useState(""),[T,H]=d.useState(""),[E,Q]=d.useState(""),[C,z]=d.useState(""),[N,j]=d.useState("all"),[g,V]=d.useState("all"),[A,he]=d.useState(!1),[L,Ce]=d.useState("72"),[F,De]=d.useState(""),[B,$e]=d.useState(""),[Ie,Te]=d.useState(new Set),[b,Ee]=d.useState(null),Le=()=>L==="custom"?{since:F?new Date(F+"T00:00:00").toISOString():null,until:B?new Date(B+"T23:59:59.999").toISOString():null}:{since:new Date(Date.now()-parseInt(L,10)*3600*1e3).toISOString(),until:null},Y=async(s=u)=>{c(!0);try{const x=s*D,l=x+D-1;let a=me.from("date_picker_traces").select("*",{count:"estimated"}).order("created_at",{ascending:!1}).range(x,l);if(L==="custom")F&&(a=a.gte("created_at",new Date(F+"T00:00:00").toISOString())),B&&(a=a.lte("created_at",new Date(B+"T23:59:59.999").toISOString()));else{const Re=new Date(Date.now()-parseInt(L,10)*3600*1e3).toISOString();a=a.gte("created_at",Re)}_.trim()&&(a=a.ilike("email",`%${_.trim()}%`)),$.trim()&&(a=a.ilike("session_id",`%${$.trim()}%`)),T.trim()&&(a=a.filter("payload->>orderID","ilike",`%${T.trim()}%`)),E.trim()&&(a=a.filter("payload->>where","ilike",`%${E.trim()}%`)),C.trim()&&(a=a.filter("payload->>source","ilike",`%${C.trim()}%`)),A?a=a.eq("event_name","fingerprint_mismatch"):N!=="all"&&(a=a.eq("event_name",N)),g!=="all"&&(a=a.or(`payload->>pickerId.ilike.%${g}%,payload->>which.eq.${g}`));const{since:y,until:h}=Le(),M=A?"fingerprint_mismatch":N!=="all"?N:null,[P,R]=await Promise.all([a,y?me.rpc("get_date_picker_trace_summary",{p_since:y,p_until:h,p_event_name:M}):Promise.resolve({data:null,error:null})]),{data:J,error:ge,count:Be}=P;if(ge)throw ge;m(J??[]),f(Be??null);const U=R==null?void 0:R.data;Ee(U?{total:Number(U.total||0),mismatches:Number(U.mismatches||0),uniqueOrderIds:Number(U.uniqueOrderIds||0),uniqueSessions:Number(U.uniqueSessions||0),lastEventAt:U.lastEventAt??null}:null)}catch(x){n({title:"Failed to load traces",description:x.message,variant:"destructive"})}finally{c(!1)}};d.useEffect(()=>{S(0);const s=setTimeout(()=>{Y(0)},300);return()=>clearTimeout(s)}
1,[_,$,T,E,C,N,g,A,L,F,B]),d.useEffect(()=>{Y(u)},[u]);const Me=s=>{Te(x=>{const l=new Set(x);return l.has(s)?l.delete(s):l.add(s),l})},W=async(s,x)=>{try{await navigator.clipboard.writeText(s),n({title:`${x} copied`,description:s})}catch{n({title:"Copy failed",variant:"destructive"})}},Z=d.useMemo(()=>(b==null?void 0:b.mismatches)??t.filter(s=>s.event_name==="fingerprint_mismatch").length,[b,t]),Pe=d.useMemo(()=>{var x;if(b)return b.uniqueOrderIds;const s=new Set;for(const l of t){const a=(x=l.payload)==null?void 0:x.orderID;a&&s.add(String(a))}return s.size},[b,t]),pe=(b==null?void 0:b.lastEventAt)??(t.length?t[0].created_at:null),fe=pe?le(new Date(pe),{addSuffix:!0}):null,I=d.useMemo(()=>{var l;const s=new Map;for(const a of t){const y=a.session_id??a.email??a.user_id??a.id;let h=s.get(y);h||(h={key:y,label:a.session_id??a.email??a.user_id??a.id,email:a.email,sessionId:a.session_id,events:[],lastAt:a.created_at,sides:new Set,mismatchCount:0,orderID:null,country:ke(a.locale)},s.set(y,h)),h.events.push(a),a.created_at>h.lastAt&&(h.lastAt=a.created_at),!h.email&&a.email&&(h.email=a.email),h.country||(h.country=ke(a.locale));const M=ue(a.payload);M&&h.sides.add(M),a.event_name==="fingerprint_mismatch"&&h.mismatchCount++;const P=(l=a.payload)==null?void 0:l.orderID;P&&!h.orderID&&(h.orderID=String(P))}const x=Array.from(s.values());return x.sort((a,y)=>a.lastAt<y.lastAt?1:-1),x},[t]),[Oe,G]=d.useState(new Set);d.useEffect(()=>{const s=new Set;I[0]&&s.add(I[0].key);for(const x of I)x.mismatchCount>0&&s.add(x.key);G(s)},[I]);const ze=s=>{G(x=>{const l=new Set(x);return l.has(s)?l.delete(s):l.add(s),l})},Ae=()=>G(new Set(I.map(s=>s.key))),Fe=()=>G(new Set);return e.jsx(Ke,{title:"Date Picker Traces",subtitle:"Forensic log of date-picker events for debugging wrong-date reports",activeTab:"date-picker-traces",onTabChange:s=>r(`/admin?tab=${s}`),children:e.jsxs("div",{className:"space-y-6",children:[e.jsx(st,{}),e.jsxs(ce,{children:[e.jsxs(Ne,{className:"flex flex-row items-center justify-between",children:[e.jsx(we,{className:"text-base",children:"Filters"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(X,{htmlFor:"mismatch-only",className:"text-xs text-muted-foreground",children:"Mismatches only"}),e.jsx(Ve,{id:"mismatch-only",checked:A,onCheckedChange:he})]})]}),e.jsxs(de,{className:"space-y-3",children:[e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-4 gap-3",children:[e.jsx(O,{placeholder:"Email containsâ¦",value:_,onChange:s=>k(s.target.value)}),e.jsx(O,{placeholder:"Session id containsâ¦",value:$,onChange:s=>q(s.target.value)}),e.jsx(O,{placeholder:"Order ID containsâ¦",value:T,onChange:s=>H(s.target.value)}),e.jsx(O,{placeholder:"Where contains⦠(e.g. member_save)",value:E,onChange:s=>Q(s.target.value)})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-5 gap-3",children:[e.jsx(O,{placeholder:"Source contains⦠(e.g. DesktopSearch)",value:C,onChange:s=>z(s.target.value)}),e.jsxs(ee,{value:g,onValueChange:V,children:[e.jsx(te,{children:e.jsx(se,{})}),e.jsxs(ae,{children:[e.jsx(v,{value:"all",children:"Pickup & dropoff"}),e.jsx(v,{value:"pickup",children:"Pickup only"}),e.jsx(v,{value:"dropoff",children:"Dropoff only"})]})]}),e.jsxs(ee,{value:N,onValueChange:j,disabled:A,children:[e.jsx(te,{children:e.jsx(se,{})}),e.jsxs(ae,{children:[e.jsx(v,{value:"all",children:"All events"}),e.jsx(v,{value:"picker_open",children:"Picker open"}),e.jsx(v,{value:"day_click",children:"Day click"}),e.jsx(v,{value:"search_submit",children:"Search submit"}),e.jsx(v,{value:"payload_built",children:"RCM payload built"}),e.jsx(v,{value:"email_dispatch",children:"Email dispatched"}),e.jsx(v,{value:"ics_export",children:"Calendar (ICS) export"}),e.jsx(v,{value:"fingerprint_mismatch",children:"Fingerprint mismatch"})]})]}),e.jsxs(ee,{value:L,onValueChange:Ce,children:[e.jsx(te,{children:e.jsx(se,{})}),e.jsxs(ae,{children:[e.jsx(v,{value:"6",children:"Last 6 hours"}),e.jsx(v,{value:"24",children:"Last 24 hours"}),e.jsx(v,{value:"72",children:"Last 3 days"}),e.jsx(v,{value:"168",children:"Last 7 days"}),e.jsx(v,{value:"720",children:"Last 30 days"}),e.jsx(v,{value:"custom",children:"Custom rangeâ¦"})]})]}),e.jsxs(w,{onClick:()=>Y(0),disabled:i,className:"w-full",children:[i?e.jsx(He,{className:"w-4 h-4 mr-2 animate-spin"}):e.jsx(Ye,{className:"w-4 h-4 mr-2"}),"Search"]})]}),L==="custom"&&e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-3",children:[e.jsxs("div",{children:[e.jsx(X,{className:"text-xs text-muted-foreground",children:"From"}),e.jsx(O,{type:"date",value:F,onChange:s=>De(s.target.value)})]}),e.jsxs("div",{children:[e.jsx(X,{className:"text-xs text-muted-foreground",children:"To"}),e.jsx(O,{type:"date",value:B,onChange:s=>$e(s.target.value)})]})]})]})]}),e.jsxs("div",{className:"flex items-center gap-3 text-sm flex-wrap",children:[e.jsxs(p,{variant:"outline",children:[t.length," on page"]}
1),b?e.jsxs(p,{variant:"outline",children:[b.total.toLocaleString()," in range"]}):o!=null?e.jsxs(p,{variant:"outline",children:["~",o.toLocaleString()," total (estimated)"]}):null,e.jsxs(p,{variant:"outline",children:["Page ",u+1,o!=null?` of ~${Math.max(1,Math.ceil(o/D))}`:""]}),e.jsx(p,{variant:"outline",children:b?`${b.uniqueSessions.toLocaleString()} sessions in range`:`${I.length} session${I.length===1?"":"s"} on page`}),e.jsxs(p,{variant:"outline",children:[Pe.toLocaleString()," unique order IDs ",b?"in range":"on page"]}),Z>0&&e.jsxs(p,{className:"bg-red-500/15 hover:bg-red-500/15 text-red-700 dark:text-red-400",children:[Z.toLocaleString()," mismatch",Z===1?"":"es"," ",b?"in range":"on page"]}),fe&&e.jsxs("span",{className:"text-xs text-muted-foreground",children:["Last event: ",fe]}),e.jsxs("div",{className:"ml-auto flex items-center gap-1",children:[e.jsx(w,{variant:"ghost",size:"sm",onClick:Ae,children:"Expand all"}),e.jsx(w,{variant:"ghost",size:"sm",onClick:Fe,children:"Collapse all"}),e.jsxs(w,{variant:"ghost",size:"sm",onClick:()=>Y(u),disabled:i,children:[e.jsx(_e,{className:K("w-4 h-4 mr-1",i&&"animate-spin")})," Refresh"]})]})]}),(u>0||t.length>=D||o!=null&&o>D)&&e.jsx(ye,{page:u,rowsOnPage:t.length,pageSize:D,totalCount:o,loading:i,onPage:S}),e.jsx(ce,{children:e.jsx(de,{className:"p-0",children:t.length===0&&!i?e.jsxs("div",{className:"p-8 text-center text-sm text-muted-foreground space-y-3",children:[e.jsx("div",{children:"No events match the current filters."}),e.jsxs("div",{className:"text-xs",children:["Anonymous (not-signed-in) visitors are included by default â they appear as",e.jsx("span",{className:"font-mono",children:" guest"}),'. If you see "0 total" even with all filters cleared, your account may not have ',e.jsx("span",{className:"font-mono",children:"admin"})," /",e.jsx("span",{className:"font-mono",children:" super_admin"})," role (the table is RLS-protected)."]}),(_||$||T||E||C||N!=="all"||g!=="all"||A)&&e.jsx(w,{variant:"outline",size:"sm",onClick:()=>{k(""),q(""),H(""),Q(""),z(""),j("all"),V("all"),he(!1)},children:"Clear all filters"})]}):e.jsx("div",{className:"divide-y-2 divide-border",children:I.map(s=>{const x=Oe.has(s.key);return e.jsxs("div",{children:[e.jsxs("button",{onClick:()=>ze(s.key),className:"w-full text-left px-4 py-3 hover:bg-muted/50 flex items-start gap-3 bg-muted/20",children:[x?e.jsx(ve,{className:"w-4 h-4 mt-0.5 shrink-0"}):e.jsx(je,{className:"w-4 h-4 mt-0.5 shrink-0"}),e.jsxs("div",{className:"flex-1 min-w-0 flex items-center gap-2 flex-wrap",children:[s.sessionId?e.jsxs("span",{role:"button",onClick:l=>{l.stopPropagation(),W(s.sessionId,"Session ID")},className:"font-mono text-xs hover:underline",title:"Click to copy",children:[s.sessionId.slice(0,18),"â¦"]}):e.jsx("span",{className:"font-mono text-xs text-muted-foreground",children:"no session"}),e.jsxs("span",{className:"text-sm text-foreground",children:["· ",s.email??"guest"]}),s.country&&e.jsx(p,{variant:"outline",className:"text-[10px] font-normal",children:s.country}),e.jsxs(p,{variant:"outline",className:"text-[10px]",children:[s.events.length," event",s.events.length===1?"":"s"]}),s.sides.has("pickup")&&e.jsx(p,{className:"text-[10px] bg-emerald-500/15 hover:bg-emerald-500/15 text-emerald-700 dark:text-emerald-400",children:"Pickup"}),s.sides.has("dropoff")&&e.jsx(p,{className:"text-[10px] bg-amber-500/15 hover:bg-amber-500/15 text-amber-800 dark:text-amber-300",children:"Dropoff"}),s.mismatchCount>0&&e.jsxs(p,{className:"text-[10px] bg-red-500/15 hover:bg-red-500/15 text-red-700 dark:text-red-400",children:[s.mismatchCount," mismatch",s.mismatchCount===1?"":"es"]}),s.orderID&&e.jsxs("span",{role:"button",onClick:l=>{l.stopPropagation(),W(s.orderID,"Order ID")},className:"inline-flex items-center gap-1 rounded bg-foreground
1/5 px-2 py-0.5 text-[11px] font-mono hover:bg-foreground/10",title:"Click to copy",children:["#",s.orderID," ",e.jsx(be,{className:"w-3 h-3 opacity-60"})]}),e.jsx("span",{className:"ml-auto text-xs text-muted-foreground",children:le(new Date(s.lastAt),{addSuffix:!0})})]})]}),x&&e.jsx("div",{className:"pl-8 border-l-2 border-border/60 ml-4 mb-2 divide-y divide-border/60",children:s.events.map(l=>{const a=Ie.has(l.id),y=l.payload||{},h=y.orderID?String(y.orderID):null,M=y.where?String(y.where):null,P=y.which?String(y.which):null,R=ue(y);return e.jsxs("div",{className:"text-sm",children:[e.jsxs("button",{onClick:()=>Me(l.id),className:"w-full text-left px-4 py-3 hover:bg-muted/50 flex items-start gap-3",children:[a?e.jsx(ve,{className:"w-4 h-4 mt-0.5 shrink-0"}):e.jsx(je,{className:"w-4 h-4 mt-0.5 shrink-0"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[e.jsx(p,{className:K("font-mono text-[10px]",Ze[l.event_name]??"bg-muted"),children:Je[l.event_name]??l.event_name}),R==="pickup"&&e.jsx(p,{className:"text-[10px] bg-emerald-500/15 hover:bg-emerald-500/15 text-emerald-700 dark:text-emerald-400",children:"Pickup"}),R==="dropoff"&&e.jsx(p,{className:"text-[10px] bg-amber-500/15 hover:bg-amber-500/15 text-amber-800 dark:text-amber-300",children:"Dropoff"}),e.jsx("span",{className:"text-muted-foreground text-xs",children:xe(new Date(l.created_at),"dd MMM HH:mm:ss")}),e.jsxs("span",{className:"text-muted-foreground text-xs",children:["· ",le(new Date(l.created_at),{addSuffix:!0})]}),h&&e.jsxs("span",{role:"button",onClick:J=>{J.stopPropagation(),W(h,"Order ID")},className:"inline-flex items-center gap-1 rounded bg-foreground
1/5 px-2 py-0.5 text-[11px] font-mono hover:bg-foreground/10",title:"Click to copy",children:["#",h," ",e.jsx(be,{className:"w-3 h-3 opacity-60"})]}),M&&e.jsxs("span",{className:"inline-flex items-center rounded bg-amber-500/15 hover:bg-amber-500/15 text-amber-800 dark:text-amber-300 px-2 py-0.5 text-[11px] font-mono",children:[M.replace("BookingSuccess.",""),P?` · ${P}`:""]})]}),e.jsx(tt,{row:l}),e.jsx(Xe,{row:l})]})]}),a&&e.jsx("div",{className:"px-4 pb-4 pl-11",children:e.jsx("pre",{className:"text-xs bg-muted/40 rounded p-3 overflow-auto whitespace-pre-wrap break-all",children:JSON.stringify({payload:l.payload,session_id:l.session_id,user_id:l.user_id,ua:l.ua,locale:l.locale,tz_offset_minutes:l.tz_offset_minutes,viewport_w:l.viewport_w,ip:l.ip},null,2)})})]},l.id)})})]},s.key)})})})}),(u>0||t.length>=D||o!=null&&o>D)&&e.jsx(ye,{page:u,rowsOnPage:t.length,pageSize:D,totalCount:o,loading:i,onPage:S})]})})}function ye({page:r,rowsOnPage:n,pageSize:t,totalCount:m,loading:i,onPage:c}){const o=m!=null&&m>0,f=o?Math.max(0,Math.ceil(m/t)-1):null,u=o?r<f:n>=t,S=r>0;return e.jsxs("div",{className:"flex items-center justify-between gap-3 py-2 border-y bg-muted/20 px-4 rounded",children:[e.jsx("div",{className:"text-xs text-muted-foreground",children:o?e.jsxs(e.Fragment,{children:["Showing ",e.jsx("b",{children:r*t+1}),"â",e.jsx("b",{children:Math.min((r+1)*t,m)})," of ~",e.jsx("b",{children:m.toLocaleString()})]}):e.jsxs(e.Fragment,{children:["Page ",e.jsx("b",{children:r+1})," · ",n," event",n===1?"":"s"," on this page"]})}),e.jsxs("div",{className:"flex items-center gap-2",children:[o&&e.jsx(w,{variant:"outline",size:"sm",onClick:()=>c(0),disabled:!S||i,children:"« First"}),e.jsx(w,{variant:"outline",size:"sm",onClick:()=>c(Math.max(0,r-1)),disabled:!S||i,children:"â Prev"}),e.jsxs("span",{className:"text-xs text-muted-foreground px-2",children:["Page ",r+1,o?` of ${f+1}`:""]}),e.jsx(w,{variant:"outline",size:"sm",onClick:()=>c(r+1),disabled:!u||i,children:"Next â"}),o&&e.jsx(w,{variant:"outline",size:"sm",onClick:()=>c(f),disabled:!u||i,children:"Last »"})]})]})}function Xe({row:r}){const n=r.payload||{},t=i=>n[i];if(r.event_name==="day_click"){const i=t("rawIso");let c="";if(i)try{c=xe(new Date(i),"EEE dd MMM yyyy")}catch{}const o=t("dayKeyEmitted"),f=t("previousDate"),u=t("rejectedBy"),S=t("canonicalParity")===!1;return e.jsx(Ge,{delayDuration:150,children:e.jsxs("div",{className:"text-xs text-muted-foreground mt-1 flex items-center gap-2 flex-wrap",children:[e.jsx("span",{className:"font-mono",children:String(t("label")??t("pickerId")??"")}),c&&e.jsxs(re,{children:[e.jsx(ne,{asChild:!0,children:e.jsxs("span",{className:"inline-flex items-center gap-1 cursor-help border-b border-dotted border-muted-foreground/40",children:["· clicked ",e.jsx("span",{className:"font-mono",children:c}),e.jsx(ie,{className:"h-3 w-3 opacity-60"})]})}),e.jsx(oe,{className:"max-w-xs",children:"The calendar tile the user physically tapped, shown in their browser's local timezone."})]}),e.jsxs(re,{children:[e.jsx(ne,{asChild:!0,children:e.jsxs("span",{className:"inline-flex items-center gap-1 cursor-help border-b border-dotted border-muted-foreground/40",children:["· emitted ",e.jsx("span",{className:"font-mono text-foreground",children:o??"(rejected)"}),e.jsx(ie,{className:"h-3 w-3 opacity-60"})]})}),e.jsx(oe,{className:"max-w-xs",children:"The canonical YYYY-MM-DD day-key the app saved into the booking form. This is what gets sent to RCM â the source of truth."})]}),f&&e.jsxs(re,{children:[e.jsx(ne,{asChild:!0,children:e.jsxs("span",{className:"inline-flex items-center gap-1 cursor-help border-b border-dotted border-muted-foreground/40",children:["· was ",e.jsx("span",{className:"font-mono",children:String(f)}),e.jsx(ie,{className:"h-3 w-3 opacity-60"})]})}),e.jsxs(oe,{className:"max-w-xs",children:["The previous value of this date field before the user changed it. Shows the edit as: was X â now ",o??"?","."]})]}),u&&e.jsxs("span",{className:"text-red-600",children:["rejected by ",String(u)]}),S&&e.jsx(p,{className:"bg-red-500/15 hover:bg-red-500/15 text-red-700 text-[10px]",children:"parity broken"})]})})}if(r.event_name==="search_submit"){const i=t("pickUpDateUrl")??t("pickupDateUrl"),c=t("dropOffDateUrl")??t("dropoffDateUrl"),o=t("pickUpTime")??t("pickupTime"),f=t("dropOffTime")??t("dropoffTime"),u=t("campaignCode")||t("campaigncode");return e.jsxs("div",{className:"text-xs text-muted-foreground mt-1 font-mono",children:[String(t("source")??"")," · ",String(i??""),o?` ${o}`:""," â ",String(c??""),f?` ${f}`:"",u?` · campaign ${u}`:""]})}if(r.event_name==="fingerprint_mismatch"){const i=t("mismatches")||[];if(i.length===0){const c=t("primaryCanonical"),o=t("fallbackCanonical");if(c&&o)return e.jsxs("div",{className:"text-xs text-red-600 mt-1 font-mono",children:["RCM said ",e.jsx("span",{className:"font-bold",children:String(c)})," · payload had ",e.jsx("span",{className:"font-bold",children:String(o)})]})}return e.jsx("div",{className:"text-xs text-red-600 mt-1 font-mono space-y-0.5",children:i.map((c,o)=>e.jsxs("div",{children:[c.field,": expected ",e.jsx("span",{className:"font-bold",children:c.expected}),", got ",e.jsx("span",{className:"font-bold",children:c.got})]},o))})}const m=t("surface");return e.jsxs("div",{className:"text-xs text-muted-foreground mt-1 font-mono",children:[String(t("label")??t("pickerId")??"")," · current ",String(t("currentDate")??"â")," · min ",String(t("minDate")??"â")," · max ",String(t("maxDate")??"â"),m?` · ${m}
1`:""]})}function ke(r){if(!r)return null;const n=r.match(/[-_]([A-Za-z]{2})\b/);if(!n)return null;const t=n[1].toUpperCase(),m=String.fromCodePoint(...t.split("").map(c=>127462+c.charCodeAt(0)-65));let i=t;try{i=new Intl.DisplayNames(["en"],{type:"region"}).of(t)??t}catch{}return`${m} ${i}`}function et(r){if(r==null)return"";const n=r>=0?"+":"-",t=Math.abs(r),m=Math.floor(t/60),i=t%60;return`UTC${n}${m}${i?":"+String(i).padStart(2,"0"):""}`}function ue(r){const n=String((r==null?void 0:r.pickerId)??"").toLowerCase();if(n.includes("pickup"))return"pickup";if(n.includes("dropoff"))return"dropoff";const t=String((r==null?void 0:r.which)??"").toLowerCase();if(t==="pickup"||t==="dropoff")return t;const m=String((r==null?void 0:r.label)??"").toLowerCase();return m.includes("pickup")||m.includes("pick up")?"pickup":m.includes("return")||m.includes("drop")?"dropoff":null}function Se(r){return ue(r)??"a date"}function tt({row:r}){const n=r.payload||{},t=r.email||(r.session_id?`session ${r.session_id.slice(0,8)}â¦`:"a visitor"),m=et(r.tz_offset_minutes);let i="";if(r.event_name==="picker_open")i=`${t} opened the ${Se(n)} calendar${n.currentDate?`, currently set to ${n.currentDate}`:""}.`;else if(r.event_name==="day_click"){const c=Se(n);let o=n.dayKeyEmitted||"";if(!o&&n.rawIso)try{o=xe(new Date(n.rawIso),"EEE dd MMM yyyy")}catch{}if(n.rejectedBy)i=`${t} tried to pick ${o||"a day"} for ${c} but it was blocked (${n.rejectedBy}).`;else if(n.canonicalParity===!1)i=`${t} picked ${o} for ${c} â old and new code disagreed (legacy said ${n.legacyDayKey}). Investigate.`;else{const f=n.previousDate?` (was ${n.previousDate})`:"";i=`${t} picked ${o} for ${c}${f}. Saved correctly.`}}else if(r.event_name==="search_submit"){const c=n.pickUpDateUrl??n.pickupDateUrl??"?",o=n.dropOffDateUrl??n.dropoffDateUrl??"?";i=`${t} submitted a search for ${c} â ${o}.`}else if(r.event_name==="fingerprint_mismatch"){const c=n.where?String(n.where).replace("BookingSuccess.",""):"save",o=n.which?` (${n.which})`:"",f=n.orderID?` on order #${n.orderID}`:"",u=n.mismatches||[];if(u.length){const S=u[0];i=`Date drift detected during ${c}${o}${f}: ${S.field} expected ${S.expected} but got ${S.got}.`}else n.primaryCanonical&&n.fallbackCanonical?i=`Date drift${f}: RCM said ${n.primaryCanonical}, our payload had ${n.fallbackCanonical}. RCM wins.`:i=`Date drift detected during ${c}${o}${f}.`}else i=`${r.event_name} event from ${t}.`;return m&&(i+=` (browser ${m})`),e.jsx("div",{className:"text-xs text-foreground mt-1",children:i})}function st(){const[r,n]=d.useState(!0),[t,m]=d.useState([]),[i,c]=d.useState(0),[o,f]=d.useState(0),[u,S]=d.useState([]),_=async()=>{var k,$,q;try{const T=new Date(Date.now()-864e5).toISOString(),H=new Date(Date.now()-5*60*1e3).toISOString(),{data:E,error:Q}=await me.from("date_picker_traces").select("event_name, payload, created_at").in("event_name",["step_drift_detected","rcm_payload_drift","fingerprint_mismatch"]).gte("created_at",T).order("created_at",{ascending:!1}).limit(1e3);if(Q)throw Q;const C=E||[];f(C.length),c(C.filter(j=>j.created_at>=H).length);const z=new Map,N=new Map;for(const j of C){const g=((k=j.payload)==null?void 0:k.page)||(($=j.payload)==null?void 0:$.where)||"unknown";z.set(g,(z.get(g)||0)+1);const V=((q=j.payload)==null?void 0:q.tz_name)||"unknown";N.set(V,(N.get(V)||0)+1)}m(Array.from(z.entries()).map(([j,g])=>({page:j,count:g})).sort((j,g)=>g.count-j.count).slice(0,6)),S(Array.from(N.entries()).map(([j,g])=>({tz:j,count:g})).sort((j,g)=>g.count-j.count).slice(0,4))}catch{}finally{n(!1)}};return d.useEffect(()=>{_();const k=setInterval(_,6e4);return()=>clearInterval(k)},[]),e.jsxs(ce,{className:"border-red-200/70 dark:border-red-900/40",children:[e.jsx(Ne,{className:"pb-3",children:e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsx(we,{className:"text-base",children:"Live date drift"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(p,{className:K("text-xs",i>0?"bg-red-600/20 text-red-800 dark:text-red-300":"bg-emerald-500/15 text-emerald-700 dark:text-emerald-400"),children:i>0?`Active: ${i} in last 5 min`:"No drift in last 5 min"}),e.jsxs(p,{variant:"outline",className:"text-xs",children:[o," in last 24h"]}),e.jsx(w,{variant:"ghost",size:"sm",onClick:_,disabled:r,children:e.jsx(_e,{className:K("h-3.5 w-3.5",r&&"animate-spin")})})]})]})}),e.jsx(de,{className:"pt-0",children:e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-xs font-medium text-muted-foreground mb-2",children:"By page (24h)"}),t.length===0?e.jsx("div",{className:"text-xs text-muted-foreground",children:"No drift detected."}):e.jsx("div",{className:"flex flex-wrap gap-1.5",children:t.map(k=>e.jsxs(p,{variant:"secondary",className:"text-xs",children:[k.page," · ",k.count]},k.page))})]}),e.jsxs("div",{children:[e.jsx("div",{className:"text-xs font-medium text-muted-foreground mb-2",children:"Top timezones (24h)"}),u.length===0?e.jsx("div",{className:"text-xs text-muted-foreground",children:"â"}):e.jsx("div",{className:"flex flex-wrap gap-1.5",children:u.map(k=>e.jsxs(p,{variant:"outline",className:"text-xs",children:[k.tz," · ",k.count]},k.tz))})]})]})})]})}export{Et 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.