import{r as g,a as F,j as n,D as P}from"./index-BNR09N5o.js";import"./react-DlyoauG8.js";function X(e){var l,d;if(!e)return e;const t=c=>c!=null&&c!==-1&&c!==-1?c:void 0,s=e.IntValues||{};return{item_id:e.item_id??e.Id??0,name:e.name??e.Name??((l=e.StringValues)==null?void 0:l["1"])??"Unknown",icon:e.icon??e.Icon??0,object_class:e.object_class??e.ObjectClass??0,current_wielded_location:e.current_wielded_location??t(e.CurrentWieldedLocation)??t(Number(s[10]))??0,container_id:e.container_id??e.ContainerId??0,items_capacity:e.items_capacity??t(e.ItemsCapacity)??t(Number(s[6]))??((d=e.enhanced_properties)==null?void 0:d.ItemSlots_Decal)??void 0,value:e.value??t(e.Value)??t(Number(s[19]))??0,burden:e.burden??t(e.Burden)??t(Number(s[5]))??0,armor_level:e.armor_level??t(e.ArmorLevel),max_damage:e.max_damage??t(e.MaxDamage),material:e.material??e.material_name??e.Material??void 0,item_set:e.item_set??e.ItemSet??void 0,imbue:e.imbue??e.Imbue??void 0,tinks:e.tinks??t(e.Tinks),workmanship:e.workmanship??t(e.Workmanship),equip_skill:e.equip_skill??e.equip_skill_name??e.EquipSkill??void 0,wield_level:e.wield_level??t(e.WieldLevel),skill_level:e.skill_level??t(e.SkillLevel),lore_requirement:e.lore_requirement??t(e.LoreRequirement),attack_bonus:e.attack_bonus??t(e.AttackBonus),melee_defense_bonus:e.melee_defense_bonus??t(e.MeleeDefenseBonus),magic_defense_bonus:e.magic_defense_bonus??t(e.MagicDBonus),damage_bonus:e.damage_bonus??t(e.DamageBonus),damage_rating:e.damage_rating??t(e.DamRating),crit_rating:e.crit_rating??t(e.CritRating),heal_boost_rating:e.heal_boost_rating??t(e.HealBoostRating),current_mana:e.current_mana??t(Number(s[218103815]))??void 0,max_mana:e.max_mana??t(Number(s[218103814]))??void 0,spellcraft:e.spellcraft??void 0,damage_range:e.damage_range??void 0,damage_type:e.damage_type??void 0,speed_text:e.speed_text??void 0,mana_display:e.mana_display??void 0,spells:e.spells??void 0,icon_overlay_id:e.icon_overlay_id??t(Number(s[218103849]))??void 0,icon_underlay_id:e.icon_underlay_id??t(Number(s[218103850]))??void 0,_raw:e}}function E(e){return!e||e<=0?"06000133":(e+100663296).toString(16).toUpperCase().padStart(8,"0")}const I={32768:{name:"Neck",row:1,col:1},1:{name:"Head",row:1,col:3},268435456:{name:"Sigil",row:1,col:5},536870912:{name:"Sigil",row:1,col:6},1073741824:{name:"Sigil",row:1,col:7},67108864:{name:"Trinket",row:2,col:1},2048:{name:"U.Arm",row:2,col:2},512:{name:"Chest",row:2,col:3},134217728:{name:"Cloak",row:2,col:7},65536:{name:"Brace L",row:3,col:1},4096:{name:"L.Arm",row:3,col:2},1024:{name:"Abdomen",row:3,col:3},8192:{name:"U.Leg",row:3,col:4},131072:{name:"Brace R",row:3,col:5},2:{name:"Shirt",row:3,col:7},262144:{name:"Ring L",row:4,col:1},32:{name:"Hands",row:4,col:2},16384:{name:"L.Leg",row:4,col:4},524288:{name:"Ring R",row:4,col:5},4:{name:"Pants",row:4,col:7},256:{name:"Feet",row:5,col:4},2097152:{name:"Shield",row:6,col:1},1048576:{name:"Melee",row:6,col:3},4194304:{name:"Missile",row:6,col:3},16777216:{name:"Held",row:6,col:3},33554432:{name:"2H",row:6,col:3},8388608:{name:"Ammo",row:6,col:7}},M={},G=[32768,67108864,65536,131072,262144,524288],J=[1,512,2048,1024,4096,8192,16384,32,256],Z=[2,4,134217728,268435456,536870912,1073741824],ee=[2097152,1048576,4194304,16777216,33554432,8388608];(()=>{const e=new Set;Object.entries(I).forEach(([t,s])=>{const l=`${s.row}-${s.col}`,d=parseInt(t);e.has(l)||(e.add(l),G.includes(d)?M[l]="#3a2555":J.includes(d)?M[l]="#1e2e55":Z.includes(d)?M[l]="#1e3e3e":ee.includes(d)?M[l]="#142040":M[l]="#2a2a2a")})})();const $="#af7a30";function z({item:e,size:t=36}){const s={position:"absolute",top:0,left:0,width:t,height:t,border:"none",background:"transparent",imageRendering:"pixelated"},l=e.icon_underlay_id&&e.icon_underlay_id>100?`/icons/${E(e.icon_underlay_id)}.png`:null,d=e.icon_overlay_id&&e.icon_overlay_id>100?`/icons/${E(e.icon_overlay_id)}.png`:null;return n.jsxs("div",{style:{width:t,height:t,position:"relative"},children:[l&&n.jsx("img",{src:l,alt:"",style:{...s,zIndex:1},onError:c=>{c.target.style.display="none"}}),n.jsx("img",{src:`/icons/${E(e.icon)}.png`,alt:e.name,style:{...s,zIndex:2},onError:c=>{c.target.src="/icons/06000133.png"}}),d&&n.jsx("img",{src:d,alt:"",style:{...s,zIndex:3},onError:c=>{c.target.style.display="none"}})]})}function ne({item:e,x:t,y:s}){var b,f;const l=p=>p!=null&&p!==-1&&p!==-1,d=p=>p.toLocaleString(),c=p=>`${((p-1)*100).toFixed(1)}%`;return n.jsxs("div",{style:{position:"fixed",left:t+14,top:s+14,background:"rgba(0,0,0,0.96)",border:"1px solid #555",borderRadius:4,padding:"8px 12px",zIndex:99999,minWidth:200,maxWidth:340,fontSize:13,color:"#ddd",pointerEvents:"none",lineHeight:1.6,fontFamily:'-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,sans-serif'},children:[n.jsx("div",{style:{color:"#ffcc00",fontWeight:"bold",fontSize:14,marginBottom:4},children:e.name}),n.jsxs("div",{style:{color:"#aaa"},children:["Value: ",d(e.value)," · Burden: ",e.burden]}),e.workmanship&&n.jsxs("div",{style:{color:"#aaa"},children:["Workmanship: ",e.workmanship]}),e.material&&n.jsxs("div",{style:{color:"#88ff88"},children:["Material: ",e.material]}),l(e.armor_level)&&n.jsxs("div",{style:{color:"#88ff88"},children:["Armor Level: ",e.armor_level]}),l(e.max_damage)&&n.jsxs("div",{style:{color:"#88ff88"},children:["Max Damage: ",e.max_damage]}),e.damage_range&&n.jsxs("div",{style:{color:"#88ff88"},children:["Damage: ",e.damage_range,e.damage_type?`, ${e.damage_type}`:""]}),l(e.attack_bonus)&&e.attack_bonus!==1&&n.jsxs("div",{style:{color:"#88ff88"},children:["Attack: +",c(e.attack_bonus)]}),l(e.melee_defense_bonus)&&e.melee_defense_bonus!==1&&n.jsxs("div",{style:{color:"#88ff88"},children:["Melee Def: +",c(e.melee_defense_bonus)]}),l(e.magic_defense_bonus)&&e.magic_defense_bonus!==1&&n.jsxs("div",{style:{color:"#88ff88"},children:["Magic Def: +",c(e.magic_defense_bonus)]}),e.equip_skill&&n.jsxs("div",{style:{color:"#ddd"},children:["Skill: ",e.equip_skill]}),l(e.wield_level)&&n.jsxs("div",{style:{color:"#ffaa00"},children:["Wield Level: ",e.wield_level]}),l(e.lore_requirement)&&n.jsxs("div",{style:{color:"#ffaa00"},children:["Lore: ",e.lore_requirement]}),e.imbue&&n.jsxs("div",{style:{color:"#88ff88"},children:["Imbue: ",e.imbue]}),e.item_set&&n.jsxs("div",{style:{color:"#88ff88"},children:["Set: ",e.item_set]}),l(e.tinks)&&n.jsxs("div",{style:{color:"#88ff88"},children:["Tinks: ",e.tinks]}),l(e.damage_rating)&&n.jsxs("div",{children:["Damage Rating: ",e.damage_rating]}),l(e.crit_rating)&&n.jsxs("div",{children:["Crit Rating: ",e.crit_rating]}),l(e.heal_boost_rating)&&n.jsxs("div",{children:["Heal Boost: ",e.heal_boost_rating]}),e.spellcraft&&n.jsxs("div",{style:{color:"#dda0dd"},children:["Spellcraft: ",e.spellcraft]}),l(e.current_mana)&&l(e.max_mana)&&n.jsxs("div",{style:{color:"#98d7ff"},children:["Mana: ",e.current_mana," / ",e.max_mana]}),((f=(b=e.spells)==null?void 0:b.spells)==null?void 0:f.length)>0&&n.jsxs("div",{style:{color:"#4a90e2",marginTop:4,fontSize:12},children:["Spells: ",e.spells.spells.map(p=>p.name).join(", ")]})]})}function V({iconSrc:e,isActive:t,fillPct:s,label:l,onClick:d}){const c=s>90?"#b7432c":s>70?"#d8a431":"#00ff00";return n.jsxs("div",{onClick:d,title:l,style:{display:"flex",alignItems:"flex-start",gap:2,cursor:"pointer",flexShrink:0,marginTop:3,position:"relative"},children:[t&&n.jsx("span",{style:{position:"absolute",left:-11,top:8,color:$,fontSize:10},children:"▶"}),n.jsx("div",{style:{width:30,height:30,border:t?"1px solid #00ff00":"1px solid #333",boxShadow:t?"0 0 4px #00ff00":"none",background:"#000",display:"flex",alignItems:"center",justifyContent:"center"},children:n.jsx("img",{src:e,alt:"",style:{width:26,height:26,objectFit:"contain",imageRendering:"pixelated"},onError:b=>{b.target.src="/icons/06001080.png"}})}),n.jsx("div",{style:{width:7,height:30,background:"#222",border:"1px solid #666",position:"relative",overflow:"hidden",borderRadius:2},title:`${Math.round(s)}% full`,children:n.jsx("div",{style:{position:"absolute",bottom:0,left:0,right:0,height:`${s}%`,background:c,minHeight:s>0?2:0}})})]})}const ae=({id:e,charName:t,zIndex:s})=>{var T,O,U;const[l,d]=g.useState([]),[c,b]=g.useState(!0),[f,p]=g.useState(null),[L,D]=g.useState(null),[m,Y]=g.useState(null),[te,ie]=g.useState(null);g.useEffect(()=>{b(!0),Promise.all([F(`/inventory/${encodeURIComponent(t)}?limit=1000`).catch(()=>({items:[]})),F(`/character-stats/${encodeURIComponent(t)}`).catch(()=>null)]).then(([o,i])=>{const a=o.items??[];d(a.map(X)),Y(i)}).finally(()=>b(!1))},[t]);const h=g.useCallback((o,i)=>{D(o&&i?{item:o,x:i.clientX,y:i.clientY}:null)},[]),K=g.useMemo(()=>{const o=new Set,i=[];return Object.entries(I).forEach(([a,u])=>{const _=`${u.row}-${u.col}`;o.has(_)||(o.add(_),i.push({key:_,...u,mask:parseInt(a)}))}),i},[]),{equippedMap:A,containers:w,packItems:B}=g.useMemo(()=>{const o=new Map,i=[],a=new Set,u=new Map;l.forEach(r=>{r.object_class===10&&(i.push(r),a.add(r.item_id))}),i.sort((r,v)=>(r.item_id>>>0)-(v.item_id>>>0));let _=null;return l.forEach(r=>{r.current_wielded_location>0&&r.container_id&&!a.has(r.container_id)&&(_=r.container_id)}),l.forEach(r=>{if(a.has(r.item_id))return;const v=r.current_wielded_location;if(v>0)if(r.object_class===2)Object.entries(I).forEach(([S,x])=>{if((v&parseInt(S))===parseInt(S)){const y=`${x.row}-${x.col}`;o.has(y)||o.set(y,r)}});else{let S=!1;if(I[v]){const x=I[v],y=`${x.row}-${x.col}`;o.has(y)||(o.set(y,r),S=!0)}if(!S){for(const[x,y]of Object.entries(I))if((v&parseInt(x))===parseInt(x)){const N=`${y.row}-${y.col}`;if(!o.has(N)){o.set(N,r),S=!0;break}}}}else{let k=r.container_id||0;_&&k===_&&(k=0),u.has(k)||u.set(k,[]),u.get(k).push(r)}}),{equippedMap:o,containers:i,packItems:u}},[l]);let j=B.get(0)??[],q=0;if(j.length===0){let o=0;for(const[i,a]of B.entries())!w.some(u=>u.item_id===i)&&a.length>o&&(o=a.length,q=i);j=B.get(q)??[]}const W=f!==null?B.get(f)??[]:j,H=(m==null?void 0:m.burden_units)??((T=m==null?void 0:m.stats_data)==null?void 0:T.burden_units)??0,C=(m==null?void 0:m.encumbrance_capacity)??((O=m==null?void 0:m.stats_data)==null?void 0:O.encumbrance_capacity)??0,R=C>0?Math.min(200,H/C*100):0,Q=R>150?"#b7432c":R>100?"#d8a431":"#2e8b57";return c?n.jsx(P,{id:e,title:`Inventory: ${t}`,zIndex:s,width:572,height:720,children:n.jsx("div",{style:{padding:20,color:"#666",fontStyle:"italic"},children:"Loading inventory..."})}):n.jsxs(P,{id:e,title:`Inventory: ${t}`,zIndex:s,width:572,height:720,children:[n.jsxs("div",{style:{display:"flex",flex:1,overflow:"hidden",background:"rgba(14,14,14,0.96)",fontFamily:'-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,sans-serif',fontSize:13},children:[n.jsxs("div",{style:{width:316,display:"flex",flexDirection:"column",overflow:"hidden"},children:[n.jsx("div",{style:{position:"relative",height:270,minHeight:270,background:"#0a0a0a",borderBottom:`1px solid ${$}`},children:K.map(o=>{const i=A.get(o.key),a=M[o.key]??"#2a2a2a";return n.jsx("div",{style:{position:"absolute",left:(o.col-1)*44+4,top:(o.row-1)*44+4,width:36,height:36,background:i?"#5a5a62":a,border:i?"2px solid #00ffff":"2px outset #6a6a72",boxShadow:i?"0 0 5px #00ffff, inset 0 0 5px rgba(0,255,255,0.2)":"none",display:"flex",alignItems:"center",justifyContent:"center",cursor:i?"pointer":"default"},onMouseEnter:u=>i&&h(i,u),onMouseMove:u=>i&&h(i,u),onMouseLeave:()=>h(null),children:i?n.jsx(z,{item:i,size:32}):n.jsx("img",{src:"/icons/06000133.png",alt:"",style:{width:28,height:28,opacity:.15,filter:"grayscale(100%)",imageRendering:"pixelated"}})},o.key)})}),n.jsxs("div",{style:{padding:"3px 6px",fontSize:11,color:"#ccc",background:"#111",borderBottom:`1px solid ${$}`},children:["Contents of ",f!==null?((U=w.find(o=>o.item_id===f))==null?void 0:U.name)??"Pack":"Backpack"]}),n.jsxs("div",{style:{flex:1,overflowY:"auto",display:"grid",gridTemplateColumns:"repeat(6, 36px)",gridAutoRows:36,gap:2,padding:4,alignContent:"start"},children:[W.map((o,i)=>n.jsx("div",{style:{width:36,height:36,background:"linear-gradient(135deg, #3d007a 0%, #1a0033 100%)",border:"1px solid #4a148c",display:"flex",alignItems:"center",justifyContent:"center",cursor:"pointer"},onMouseEnter:a=>h(o,a),onMouseMove:a=>h(o,a),onMouseLeave:()=>h(null),children:n.jsx(z,{item:o,size:32})},o.item_id??i)),Array.from({length:Math.max(0,24-W.length)}).map((o,i)=>n.jsx("div",{style:{width:36,height:36,background:"#0a0a0a",border:"1px solid #1a1a1a"}},`e${i}`))]})]}),n.jsxs("div",{style:{width:42,display:"flex",flexDirection:"column",alignItems:"center",padding:"4px 2px",borderLeft:`1px solid ${$}`,borderRight:`1px solid ${$}`},children:[n.jsx("div",{style:{textAlign:"center",fontSize:8,color:"#ccc",marginBottom:2},children:C>0?`${Math.floor(R)}%`:"Burden"}),n.jsx("div",{style:{width:14,height:40,background:"#111",border:"1px solid #555",position:"relative",overflow:"hidden",marginBottom:6,flexShrink:0},title:C>0?`${H.toLocaleString()} / ${C.toLocaleString()}`:`Burden: ${l.reduce((o,i)=>o+(i.burden??0),0).toLocaleString()}`,children:n.jsx("div",{style:{position:"absolute",bottom:0,left:0,right:0,height:`${R/2}%`,background:Q,transition:"height 0.3s"}})}),n.jsx(V,{iconSrc:"/icons/0600127E.png",isActive:f===null,fillPct:j.length>0?Math.min(100,j.length/102*100):0,label:`Backpack (${j.length}/102)`,onClick:()=>p(null)}),w.map(o=>{const i=o.item_id,a=l.filter(r=>r.container_id===i&&r.item_id!==i).length,u=o.items_capacity||24,_=u>0?Math.min(100,a/u*100):0;return n.jsx(V,{iconSrc:`/icons/${E(o.icon)}.png`,isActive:f===i,fillPct:_,label:`${o.name} (${a}/${u})`,onClick:()=>p(i)},i)})]}),n.jsxs("div",{style:{flex:1,display:"flex",flexDirection:"column",overflow:"hidden",minWidth:160},children:[n.jsx("div",{style:{padding:"4px 8px",fontSize:"0.72rem",fontWeight:600,color:"#aaa",background:"#111",borderBottom:`1px solid ${$}`},children:"Mana"}),n.jsxs("div",{style:{flex:1,overflowY:"auto",padding:"2px 0"},children:[Array.from(A.values()).filter(o=>o.current_mana>0||o.max_mana>0).sort((o,i)=>(o.current_mana??999999)-(i.current_mana??999999)).map((o,i)=>n.jsxs("div",{style:{display:"flex",alignItems:"center",gap:4,padding:"2px 4px",borderBottom:"1px solid #1a1a1a",cursor:"pointer"},onMouseEnter:a=>h(o,a),onMouseMove:a=>h(o,a),onMouseLeave:()=>h(null),children:[n.jsx("div",{style:{width:20,height:20,flexShrink:0},children:n.jsx(z,{item:o,size:20})}),n.jsx("div",{style:{width:8,height:8,borderRadius:"50%",background:o.current_mana>0?"#4c4":"#c44",flexShrink:0}}),n.jsx("div",{style:{flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontSize:"0.68rem",color:"#ccc"},children:o.name}),n.jsxs("div",{style:{fontSize:"0.65rem",color:"#88bbff",whiteSpace:"nowrap",fontVariantNumeric:"tabular-nums"},children:[o.current_mana??0,"/",o.max_mana??0]}),n.jsx("div",{style:{fontSize:"0.63rem",color:"#9c9",whiteSpace:"nowrap",fontVariantNumeric:"tabular-nums",minWidth:42,textAlign:"right"},children:o.max_mana>0?oe(o.current_mana??0,o.max_mana??0):""})]},i)),Array.from(A.values()).filter(o=>o.current_mana>0||o.max_mana>0).length===0&&n.jsx("div",{style:{padding:12,color:"#555",textAlign:"center",fontSize:"0.7rem"},children:"No mana items equipped"})]})]})]}),L&&n.jsx(ne,{item:L.item,x:L.x,y:L.y})]})};function oe(e,t){if(t<=0||e<=0)return"0h00m";const s=e*20,l=Math.floor(s/3600),d=Math.floor(s%3600/60);return`~${l}h${String(d).padStart(2,"0")}m`}export{ae as InventoryWindow};