import{r as A,a as B,j as t,D as L}from"./index-CLr4QmRO.js";import"./react-yfL0ty4i.js";const w=["Typeless","Slash","Pierce","Bludgeon","Fire","Cold","Acid","Electric"];function _(c,a,x){var o,m,f,k;return(((m=(o=c==null?void 0:c[a])==null?void 0:o[x])==null?void 0:m.total_normal_damage)??0)+(((k=(f=c==null?void 0:c[a])==null?void 0:f[x])==null?void 0:k.total_crit_damage)??0)}function G(c){let a={attacks:0,failed:0,crits:0,normalDmg:0,maxNormal:0,critDmg:0,maxCrit:0};if(!c)return a;for(const x of Object.values(c))for(const o of Object.values(x))a.attacks+=o.total_attacks??0,a.failed+=o.failed_attacks??0,a.crits+=o.crits??0,a.normalDmg+=o.total_normal_damage??0,a.maxNormal=Math.max(a.maxNormal,o.max_normal_damage??0),a.critDmg+=o.total_crit_damage??0,a.maxCrit=Math.max(a.maxCrit,o.max_crit_damage??0);return a}function F(c,a){let x={attacks:0,failed:0};const o=c==null?void 0:c[a];if(!o)return x;for(const m of Object.values(o))x.attacks+=m.total_attacks??0,x.failed+=m.failed_attacks??0;return x}const Y=({id:c,charName:a,zIndex:x})=>{const[o,m]=A.useState(null),[f,k]=A.useState("session"),[h,R]=A.useState(null);A.useEffect(()=>{B(`/combat-stats/${encodeURIComponent(a)}`).then(m).catch(()=>{});const e=setInterval(()=>{B(`/combat-stats/${encodeURIComponent(a)}`).then(m).catch(()=>{})},1e4);return()=>clearInterval(e)},[a]);const p=o==null?void 0:o[f],j=(p==null?void 0:p.monsters)??{},S=Object.keys(j).filter(e=>e!=="__cloak_surges__").sort(),n=A.useMemo(()=>{let e={},l={},v=0,$=0;const T=h?[j[h]].filter(Boolean):S.map(u=>j[u]);for(const u of T)if(u){for(const[g,D]of Object.entries(u.offense??{})){e[g]||(e[g]={});for(const[y,E]of Object.entries(D)){e[g][y]||(e[g][y]={total_attacks:0,failed_attacks:0,crits:0,total_normal_damage:0,max_normal_damage:0,total_crit_damage:0,max_crit_damage:0});const i=e[g][y],d=E;i.total_attacks+=d.total_attacks??0,i.failed_attacks+=d.failed_attacks??0,i.crits+=d.crits??0,i.total_normal_damage+=d.total_normal_damage??0,i.max_normal_damage=Math.max(i.max_normal_damage,d.max_normal_damage??0),i.total_crit_damage+=d.total_crit_damage??0,i.max_crit_damage=Math.max(i.max_crit_damage,d.max_crit_damage??0)}}for(const[g,D]of Object.entries(u.defense??{})){l[g]||(l[g]={});for(const[y,E]of Object.entries(D)){l[g][y]||(l[g][y]={total_attacks:0,failed_attacks:0,crits:0,total_normal_damage:0,max_normal_damage:0,total_crit_damage:0,max_crit_damage:0});const i=l[g][y],d=E;i.total_attacks+=d.total_attacks??0,i.failed_attacks+=d.failed_attacks??0,i.total_normal_damage+=d.total_normal_damage??0,i.max_normal_damage=Math.max(i.max_normal_damage,d.max_normal_damage??0),i.total_crit_damage+=d.total_crit_damage??0,i.max_crit_damage=Math.max(i.max_crit_damage,d.max_crit_damage??0)}}v+=u.aetheria_surges??0,$+=u.cloak_surges??0}return j.__cloak_surges__&&!h&&($+=j.__cloak_surges__.cloak_surges??0),{offense:e,defense:l,aeth:v,cloak:$}},[j,S,h]),r=G(n.offense),b=F(n.defense,"MeleeMissile"),M=F(n.defense,"Magic");r.attacks>0&&((r.attacks-r.failed)/r.attacks*100).toFixed(0);const N=b.attacks>0?(b.failed/b.attacks*100).toFixed(0):"0",W=M.attacks>0?(M.failed/M.attacks*100).toFixed(0):"0",C=r.attacks-r.failed,O=C-r.crits,z=O>0?Math.round(r.normalDmg/O):0;r.crits>0&&Math.round(r.critDmg/r.crits);const I=C>0?(r.crits/C*100).toFixed(1):"0",s=e=>e===0?"":e.toLocaleString();return t.jsxs(L,{id:c,title:`Combat: ${a}`,zIndex:x,width:640,height:520,children:[t.jsxs("div",{style:{display:"flex",gap:4,padding:"4px 8px",borderBottom:"1px solid #333",alignItems:"center"},children:[t.jsx("button",{className:`ml-stats-range-btn ${f==="session"?"active":""}`,onClick:()=>k("session"),children:"Session"}),t.jsx("button",{className:`ml-stats-range-btn ${f==="lifetime"?"active":""}`,onClick:()=>k("lifetime"),children:"Lifetime"}),t.jsx("div",{style:{flex:1}}),f==="session"&&t.jsx("button",{style:{fontSize:"0.6rem",padding:"2px 8px",background:"rgba(204,68,68,0.15)",color:"#c66",border:"1px solid rgba(204,68,68,0.3)",borderRadius:3,cursor:"pointer"},onClick:()=>{confirm("Clear current session stats?")&&m(e=>e&&{...e,session:{total_damage_given:0,total_damage_received:0,total_kills:0,total_aetheria_surges:0,total_cloak_surges:0,monsters:{}}})},children:"Clear Session"})]}),t.jsxs("div",{style:{display:"flex",flex:1,overflow:"hidden"},children:[t.jsxs("div",{style:{width:240,borderRight:"1px solid #333",overflowY:"auto",fontSize:"0.72rem"},children:[t.jsxs("div",{style:{display:"flex",padding:"3px 6px",borderBottom:"1px solid #333",color:"#777",fontSize:"0.65rem",fontWeight:600},children:[t.jsx("span",{style:{width:14}}),t.jsx("span",{style:{flex:1},children:"Monster"}),t.jsx("span",{style:{width:40,textAlign:"right"},children:"Kills"}),t.jsx("span",{style:{width:55,textAlign:"right"},children:"Dmg"})]}),t.jsxs("div",{style:{display:"flex",padding:"3px 6px",cursor:"pointer",background:h===null?"#2a3a4a":"",borderBottom:"1px solid #222",color:"#ddd"},onClick:()=>R(null),children:[t.jsx("span",{style:{width:14,color:"#888"},children:h===null?"*":""}),t.jsx("span",{style:{flex:1},children:"All"}),t.jsx("span",{style:{width:40,textAlign:"right"},children:s((p==null?void 0:p.total_kills)??0)}),t.jsx("span",{style:{width:55,textAlign:"right"},children:s((p==null?void 0:p.total_damage_given)??0)})]}),S.map(e=>{const l=j[e];return t.jsxs("div",{style:{display:"flex",padding:"2px 6px",cursor:"pointer",background:h===e?"#2a3a4a":"",borderBottom:"1px solid #1a1a1a",color:"#ccc"},onClick:()=>R(e),children:[t.jsx("span",{style:{width:14,color:"#888"},children:h===e?"*":""}),t.jsx("span",{style:{flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:e}),t.jsx("span",{style:{width:40,textAlign:"right"},children:s(l.kill_count)}),t.jsx("span",{style:{width:55,textAlign:"right"},children:s(l.damage_given)})]},e)})]}),t.jsx("div",{style:{flex:1,overflowY:"auto",padding:6,fontSize:"0.72rem"},children:t.jsxs("table",{style:{width:"100%",borderCollapse:"collapse"},children:[t.jsx("thead",{children:t.jsxs("tr",{style:{color:"#777",fontSize:"0.65rem"},children:[t.jsx("th",{style:{textAlign:"left",padding:"1px 4px"}}),t.jsx("th",{style:{textAlign:"right",padding:"1px 3px"},children:"Given M/M"}),t.jsx("th",{style:{textAlign:"right",padding:"1px 3px"},children:"Given Mag"}),t.jsx("th",{style:{width:4}}),t.jsx("th",{style:{textAlign:"right",padding:"1px 3px"},children:"Recv M/M"}),t.jsx("th",{style:{textAlign:"right",padding:"1px 3px"},children:"Recv Mag"}),t.jsx("th",{style:{width:4}}),t.jsx("th",{style:{textAlign:"left",padding:"1px 3px"},children:"Stats"}),t.jsx("th",{style:{textAlign:"right",padding:"1px 3px"}})]})}),t.jsxs("tbody",{children:[w.map((e,l)=>{const v=[["Evades",b.attacks>0?`${s(b.attacks)} (${N}%)`:""],["Resists",M.attacks>0?`${s(M.attacks)} (${W}%)`:""],["A.Surges",n.aeth>0?`${s(n.aeth)}`:""],["C.Surges",n.cloak>0?`${s(n.cloak)}`:""],["",""],["",""],["Av/Mx",z>0?`${s(z)} / ${s(r.maxNormal)}`:""],["Crits",r.crits>0?`${s(r.crits)} (${I}%)`:""]][l]??["",""];return t.jsxs("tr",{children:[t.jsx("td",{style:{padding:"1px 4px",color:"#888"},children:e}),t.jsx("td",{style:{textAlign:"right",padding:"1px 3px",color:"#ccc"},children:s(_(n.offense,"MeleeMissile",e))}),t.jsx("td",{style:{textAlign:"right",padding:"1px 3px",color:"#ccc"},children:s(_(n.offense,"Magic",e))}),t.jsx("td",{}),t.jsx("td",{style:{textAlign:"right",padding:"1px 3px",color:"#ccc"},children:s(_(n.defense,"MeleeMissile",e))}),t.jsx("td",{style:{textAlign:"right",padding:"1px 3px",color:"#ccc"},children:s(_(n.defense,"Magic",e))}),t.jsx("td",{}),t.jsx("td",{style:{padding:"1px 3px",color:"#777",fontWeight:600,fontSize:"0.65rem"},children:v[0]}),t.jsx("td",{style:{textAlign:"right",padding:"1px 3px",color:"#ccc"},children:v[1]})]},e)}),t.jsx("tr",{children:t.jsx("td",{colSpan:9,style:{height:4}})}),t.jsxs("tr",{children:[t.jsx("td",{style:{padding:"1px 4px",color:"#888",fontWeight:600},children:"Total"}),t.jsx("td",{style:{textAlign:"right",padding:"1px 3px",color:"#ccc"},children:s(w.reduce((e,l)=>e+_(n.offense,"MeleeMissile",l),0))}),t.jsx("td",{style:{textAlign:"right",padding:"1px 3px",color:"#ccc"},children:s(w.reduce((e,l)=>e+_(n.offense,"Magic",l),0))}),t.jsx("td",{}),t.jsx("td",{style:{textAlign:"right",padding:"1px 3px",color:"#ccc"},children:s(w.reduce((e,l)=>e+_(n.defense,"MeleeMissile",l),0))}),t.jsx("td",{style:{textAlign:"right",padding:"1px 3px",color:"#ccc"},children:s(w.reduce((e,l)=>e+_(n.defense,"Magic",l),0))}),t.jsx("td",{}),t.jsx("td",{style:{padding:"1px 3px",color:"#777",fontWeight:600,fontSize:"0.65rem"},children:"Total"}),t.jsx("td",{style:{textAlign:"right",padding:"1px 3px",color:"#ccc"},children:s(r.normalDmg+r.critDmg)})]})]})]})})]})]})};export{Y as CombatStatsWindow};