1import{u as H,a as q,r as l,s as f,j as e}from"./index-DuapSmdQ.js";function z(r){const o=new Date(r.toLocaleString("en-US",{timeZone:"America/New_York"})),s=new Date(Date.UTC(o.getFullYear(),o.getMonth(),o.getDate())),d=(s.getUTCDay()+6)%7;s.setUTCDate(s.getUTCDate()-d+3);const p=new Date(Date.UTC(s.getUTCFullYear(),0,4)),g=1+Math.round(((s.getTime()-p.getTime())/864e5-3+(p.getUTCDay()+6)%7)/7);return`${s.getUTCFullYear()}-W${String(g).padStart(2,"0")}`}function X(r){const[o,s]=r.split("-W").map(Number),d=new Date(Date.UTC(o,0,4)),p=(d.getUTCDay()+6)%7,g=new Date(d);g.setUTCDate(d.getUTCDate()-p);const i=new Date(g);i.setUTCDate(g.getUTCDate()+(s-1)*7);const v=new Date(i.getTime()+5*3600*1e3),c=new Date(v.getTime()+168*3600*1e3);return{start:v,end:c}}function ee(){const{user:r,isAdmin:o,loading:s,adminLoading:d,signOut:p}=H(),g=q(),[i,v]=l.useState(z(new Date)),[c,U]=l.useState(new Set),[W,N]=l.useState([]),[$,E]=l.useState([]),[M,F]=l.useState([]),[h,I]=l.useState([]),[m,P]=l.useState([]),[L,G]=l.useState(!1);l.useEffect(()=>{if(!o)return;const{start:t,end:n}=X(i);(async()=>{const[a,y,D,V]=await Promise.all([f.from("lb_agents").select("id,display_name,canonical_name,hierarchy_agent_id,created_at").is("hierarchy_agent_id",null).order("created_at",{ascending:!1}).limit(500),f.from("lb_deals").select("id,agent_id,alp,lead_type,posted_at").gte("posted_at",t.toISOString()).lt("posted_at",n.toISOString()).limit(5e3),f.from("agents").select("id,name,role,sa_name,ga_name,active").limit(2e3),f.from("roster_audit_log").select("*").eq("week_key",i).order("created_at",{ascending:!1}).limit(1e3)]);N(a.data??[]),E(y.data??[]),F(D.data??[]);const B=V.data??[];I(B.filter(T=>T.change_type==="rename")),P(B.filter(T=>["sa_change","ga_change","parent_sa_change","role_change"].includes(T.change_type)))})()},[o,i]);const O=l.useMemo(()=>{const t=new Date,n=[];for(let a=0;a<12;a++){const y=new Date(t.getTime()-a*7*24*3600*1e3);n.push(z(y))}return Array.from(new Set(n))},[]),x=l.useMemo(()=>{const t=new Map;return $.forEach(n=>{const a=t.get(n.agent_id)??{alp:0,count:0};t.set(n.agent_id,{alp:a.alp+(n.alp??0),count:a.count+1})}),W.map(n=>({...n,...t.get(n.id)??{alp:0,count:0}})).filter(n=>n.count>0).sort((n,a)=>a.alp-n.alp)},[W,$]),u=l.useMemo(()=>M.filter(t=>{if(t.active===!1)return!1;const n=(t.role??"").toUpperCase();if(["MGA","SGA","RGA"].includes(n))return!1;const a=t.name.toLowerCase();if(a==="brandon kawachi"||a==="spencer mayo")return!1;const y=!t.sa_name||t.sa_name.trim()==="",D=!t.ga_name||t.ga_name.trim()==="";return n==="GA"?y:D}).sort((t,n)=>t.name.localeCompare(n.name)),[M]),Y=x.length+u.length+h.length+m.length,j=c.size===0;l.useEffect(()=>{U(new Set)},[i]);function w(t){U(n=>{const a=new Set(n);return a.has(t)?a.delete(t):a.add(t),a})}async function K(){G(!0);const t=[`Weekly Validation Report â ${i}`,`Unmatched agents with deals: ${x.length}`,`Roster missing SA/GA: ${u.length}`,`Renames: ${h.length}`,`Mapping changes: ${m.length}`,`Reviewed items: ${c.size}`].join(` 2`);await f.from("notifications").insert({recipient:r?.email??"[email protected]",type:"weekly_validation_saved",title:`Weekly validation reviewed for ${i}`,body:t,meta:{week_key:i,unmatched_count:x.length,missing_manager_count:u.length,rename_count:h.length,mapping_change_count:m.length,acknowledged:Array.from(c)}}),G(!1),alert(`Saved review for ${i}.`)}return s||d?e.jsx("div",{style:A,children:"Loadingâ¦"}):r?o?e.jsx("div",{style:A,children:e.jsxs("div",{style:{maxWidth:1100,margin:"0 auto"},children:[e.jsxs("header",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:24,borderBottom:"1px solid rgba(217,173,92,0.3)",paddingBottom:16,flexWrap:"wrap",gap:12},children:[e.jsxs("div",{children:[e.jsx("div",{style:{color:"var(--ax-muted)",fontSize:10,letterSpacing:"0.35em"},children:"APEX MOB · ADMIN"}),e.jsx("h1",{style:{fontFamily:"'Cinzel',serif",color:"var(--ax-gold-text)",letterSpacing:"0.15em",fontSize:"1.6rem",margin:"6px 0 0"},children:"Weekly Validation Report"}),e.jsx("div",{style:{color:"var(--ax-muted)",fontSize:12,marginTop:4},children:"Review unmatched agents and renames before saving the week."})]}),e.jsxs("div",{style:{display:"flex",gap:8,flexWrap:"wrap",alignItems:"center"},children:[e.jsx("select",{value:i,onChange:t=>v(t.target.value),style:J,children:O.map(t=>e.jsxs("option",{value:t,children:[t,t===z(new Date)?" (current)":""]},t))}),e.jsx("button",{onClick:()=>g({to:"/admin"}),style:Z,children:"â Admin"}),e.jsx("button",{onClick:K,disabled:L||j,style:{...R,opacity:j?.5:1,cursor:j?"not-allowed":"pointer"},title:j?"Review at least one item first":"Save this week's review",children:L?"Savingâ¦":`Save review (${c.size})`})]})]}),e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit,minmax(180px,1fr))",gap:12,marginBottom:20},children:[e.jsx(b,{label:"Unmatched w/ deals",value:x.length,tone:x.length?"warn":"ok"}),e.jsx(b,{label:"Missing SA/GA",value:u.length,tone:u.length?"warn":"ok"}),e.jsx(b,{label:"Renames",value:h.length,tone:h.length?"info":"ok"}),e.jsx(b,{label:"Mapping changes",value:m.length,tone:m.length?"info":"ok"})]}),Y===0&&e.jsxs("div",{style:{...C,textAlign:"center",color:"var(--ax-success)"},children:["â Nothing to validate for ",i,"."]}),e.jsx(S,{title:`Unmatched ALP names with deals this week (${x.length})`,help:"Leaderboard names that posted this week but have no roster link. Confirm their SA/GA in the Roster before saving.",children:x.length===0?e.jsx(k,{text:"All ALP names are linked to the roster."}):e.jsx("div",{style:{display:"grid",gap:6},children:x.map(t=>{const n=`lb:${t.id}`;return e.jsxs(_,{acked:c.has(n),onToggle:()=>w(n),children:[e.jsx("div",{style:{color:"var(--ax-gold-text)",fontWeight:600},children:t.canonical_name??t.display_name??"(unnamed)"}),e.jsxs("div",{style:{color:"var(--ax-body)",fontSize:13},children:[t.count," deal",t.count===1?"":"s"," · ",t.alp.toLocaleStr
2ing()," ALP"]})]},n)})})}),e.jsx(S,{title:`Roster agents missing SA or GA (${u.length})`,help:"Active agents without a full hierarchy. Assign in the Roster.",children:u.length===0?e.jsx(k,{text:"All active agents have SA and GA assigned."}):e.jsx("div",{style:{display:"grid",gap:6},children:u.map(t=>{const n=`mgr:${t.id}`,a=[!t.sa_name||t.sa_name.trim()===""?"SA":null,!t.ga_name||t.ga_name.trim()===""?"GA":null].filter(Boolean).join(" + ");return e.jsxs(_,{acked:c.has(n),onToggle:()=>w(n),children:[e.jsxs("div",{style:{color:"var(--ax-gold-text)",fontWeight:600},children:[t.name," ",e.jsxs("span",{style:{color:"var(--ax-muted)"},children:["· ",t.role??"unset"]})]}),e.jsxs("div",{style:{color:"var(--ax-body)",fontSize:13},children:["Missing ",a]})]},n)})})}),e.jsx(S,{title:`Renames this week (${h.length})`,help:"Every roster name change recorded this week. Confirm each is intentional.",children:h.length===0?e.jsx(k,{text:"No renames recorded."}):e.jsx("div",{style:{display:"grid",gap:6},children:h.map(t=>{const n=`rn:${t.id}`;return e.jsxs(_,{acked:c.has(n),onToggle:()=>w(n),children:[e.jsx("div",{style:{color:"var(--ax-gold-text)",fontWeight:600},children:t.agent_name??"(unknown)"}),e.jsxs("div",{style:{color:"var(--ax-body)",fontSize:13},children:[e.jsx("span",{style:{color:"var(--ax-danger)"},children:t.old_value??"â
"}),e.jsx("span",{style:{color:"var(--ax-muted)"},children:" â "}),e.jsx("span",{style:{color:"var(--ax-success)"},children:t.new_value??"â
"}),e.jsxs("span",{style:{color:"var(--ax-muted)"},children:[" · ",t.changed_by??"system"," · ",new Date(t.created_at).toLocaleString()]})]})]},n)})})}),e.jsx(S,{title:`Mapping changes this week (${m.length})`,help:"SA/GA/role reassignments recorded this week.",children:m.length===0?e.jsx(k,{text:"No mapping changes recorded."}):e.jsx("div",{style:{display:"grid",gap:6},children:m.map(t=>{const n=`map:${t.id}`;return e.jsxs(_,{acked:c.has(n),onToggle:()=>w(n),children:[e.jsxs("div",{style:{color:"var(--ax-gold-text)",fontWeight:600},children:[t.agent_name??"(unknown)"," ",e.jsxs("span",{style:{color:"var(--ax-muted)"},children:["· ",t.field]})]}),e.jsxs("div",{style:{color:"var(--ax-body)",fontSize:13},children:[e.jsx("span",{style:{color:"var(--ax-danger)"},children:t.old_value??"â
"}),e.jsx("span",{style:{color:"var(--ax-muted)"},children:" â "}),e.jsx("span",{style:{color:"var(--ax-success)"},children:t.new_value??"â
"}),e.jsxs("span",{style:{color:"var(--ax-muted)"},children:[" · ",t.changed_by??"system"," · ",new Date(t.created_at).toLocaleString()]})]})]},n)})})})]})}):e.jsxs("div",{style:A,children:[e.jsx("p",{children:"Not authorized."}),e.jsx("button",{onClick:()=>p().then(()=>g({to:"/"})),style:R,children:"Sign Out"})]}):e.jsxs("div",{style:A,children:[e.jsx("p",{children:"Please sign in."}),e.jsx("button",{onClick:()=>g({to:"/"}),style:R,children:"Home"})]})}function S({title:r,help:o,children:s}){return e.jsxs("section",{style:{marginBottom:24},children:[e.jsx("h2",{style:{fontFamily:"'Cinzel',serif",color:"var(--ax-gold-text)",letterSpacing:"0.12em",fontSize:"1rem",marginBottom:4},children:r}),e.jsx("div",{style:{color:"var(--ax-muted)",fontSize:12,marginBottom:10},children:o}),s]})}function _({acked:r,onToggle:o,children:s}){return e.jsxs("div",{style:{...C,display:"flex",gap:12,alignItems:"flex-start",borderColor:r?"rgba(122,192,74,0.4)":"rgba(217,173,92,0.2)",background:r?"#0f1a0f":"#141414"},children:[e.jsx("input",{type:"checkbox",checked:r,onChange:o,style:{marginTop:4,accentColor:"var(--ax-gold)"}}),e.jsx("div",{style:{flex:1},children:s})]})}function k({text:r}){return e.jsxs("div",{style:{...C,color:"var(--ax-success)",fontSize:13,textAlign:"center"},children:["â ",r]})}function b({label:r,value:o,tone:s}){const d=s==="warn"?"var(--ax-danger)":s==="info"?"#7ac0f4":"var(--ax-success)";return e.jsxs("div",{style:{...C,textAlign:"center"},children:[e.jsx("div",{style:{color:d,fontFamily:"'Cinzel',serif",fontSize:28,fontWeight:700},children:o}),e.jsx("div",{style:{color:"var(--ax-muted)",fontSize:10,letterSpacing:"0.2em",textTransform:"uppercase",marginTop:4},children:r})]})}const A={background:"var(--ax-page)",color:"var(--ax-text)",minHeight:"100vh",padding:"32px 24px",fontFamily:"'Lato',sans-serif"},C={background:"var(--ax-card)",padding:14,border:"1px solid var(--ax-line)",borderRadius:2},R={background:"var(--ax-gold)",color:"#000",border:"none",padding:"10px 18px",fontFamily:"'Cinzel',serif",fontSize:11,letterSpacing:"0.2em",textTransform:"uppercase",cursor:"pointer",fontWeight:700},Z={background:"transparent",color:"var(--ax-gold)",border:"1px solid var(--ax-gold)",padding:"10px 18px",fontFamily:"'Cinzel',serif",fontSize:11,letterSpacing:"0.2em",textTransform:"uppercase",cursor:"pointer"},J={background:"var(--ax-card)",color:"var(--ax-gold-text)",border:"1px solid rgba(217,173,92,0.3)",padding:"8px 10px",fontSize:13,borderRadius:2};export{ee as component};
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.