import{jsxs as R,jsx as H}from"react/jsx-runtime";import{useState as D,useRef as M,useEffect as C,useCallback as $}from"react";import{l as j,p as S,g as W}from"./item-database-BBfxV-PC.js";import{c as Y}from"./utils-CMbmcP35.js";function U({itemId:m,showName:y=!0,iconSize:E=20,className:T}){const[b,L]=D(!1),[k,I]=D(!1),t=M(null),g=M(null),[u,f]=D(!1);C(()=>{j().then(()=>L(!0)).catch(()=>I(!0))},[]);const o=b?W(m):null,r=`/img/Icons/${m}.png`,a=$(()=>o?.rawDescription?S(o.rawDescription).map(n=>{const c=n.text.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#039;");return`<span style="color: #${n.color}">${c}</span>`}).join(""):"",[o]),A=$(e=>{if(!o||u)return;f(!0);const n=document.createElement("div");n.className="max-w-sm p-3 bg-black/95 border border-gray-700 rounded-md shadow-lg",n.style.cssText=`
            position: fixed;
            z-index: 9999;
            pointer-events: none;
        `;const c=a();n.innerHTML=`
            <div class="space-y-2">
                <div class="flex items-center gap-2">
                    <img src="${r}" alt="" class="w-8 h-8 object-contain" />
                    <div>
                        <p class="font-medium text-sm" style="color: #${o.color}; margin: 0;">
                            ${o.name}
                        </p>
                    </div>
                </div>
                ${o.rawDescription?`
                    <div class="text-xs border-t border-border pt-2" style="white-space: pre-wrap; word-wrap: break-word;">${c}</div>
                `:""}
            </div>
        `,document.body.appendChild(n),g.current=n,d(e)},[o,u,a,r]),d=$(e=>{const n=g.current;if(!n)return;const c=n.getBoundingClientRect(),v=window.innerWidth,w=window.innerHeight;let p=e.clientX,i=e.clientY+15;p+c.width>v-10&&(p=v-c.width-10),p<10&&(p=10),i+c.height>w-10&&(i=e.clientY-c.height-10),n.style.left=p+"px",n.style.top=i+"px"},[]),s=$(()=>{g.current&&u&&(document.body.removeChild(g.current),g.current=null,f(!1))},[u]);return R("span",{ref:t,className:Y("inline-flex items-center gap-2 px-1 py-0.5 rounded transition-colors",T),style:{display:"inline-flex",verticalAlign:"middle",alignItems:"center"},onMouseEnter:A,onMouseMove:d,onMouseLeave:s,children:[H("img",{src:r,alt:o?.name||`Item ${m}`,style:{width:E,height:E,objectFit:"contain",verticalAlign:"middle",cursor:"pointer"},onError:e=>{e.target.style.display="none"}}),y&&b&&o&&H("span",{className:"font-medium text-sm",style:{color:`#${o.color}`,cursor:"pointer"},"data-item-name":"true","data-item-id":m,children:o.name})]})}function V(m){const[y,E]=D(!1);C(()=>{j().then(()=>E(!0))},[]),C(()=>{if(!y)return;const T=()=>{const L=document.querySelector(m);if(!L)return;L.querySelectorAll('img[src*="/img/Icons/"]').forEach(I=>{const t=I;if(t.getAttribute("data-tooltip-enhanced")==="true")return;const u=(t.src||t.getAttribute("src")||"").match(/\/img\/Icons\/(\d+)\.png/);if(!u)return;const f=parseInt(u[1]),o=`/img/Icons/${f}.png`,r=W(f);if(!r)return;const a=t.parentElement;if(a&&a.nodeType===Node.ELEMENT_NODE&&a.classList.contains("inline-flex")&&a.classList.contains("items-center")&&a.querySelector("[data-item-name]")){t.setAttribute("data-tooltip-enhanced","true");return}const d=document.createElement("span");d.className="inline-flex items-center gap-2 px-1 py-0.5 rounded transition-colors",d.style.cssText="position: relative; display: inline-flex; vertical-align: middle; align-items: center;",t.parentNode?.replaceChild(d,t),d.appendChild(t),t.style.width="20px",t.style.height="20px",t.style.objectFit="contain",t.style.verticalAlign="middle",t.style.cursor="pointer";const s=document.createElement("span");s.textContent=r.name||"",s.setAttribute("data-item-name","true"),s.setAttribute("data-item-id",f.toString()),s.className="font-medium text-sm",s.style.cssText=`color: #${r.color}; cursor: pointer;`,d.appendChild(s),t.setAttribute("data-tooltip-enhanced","true");let e=null,n=!1;const c=()=>r.rawDescription?S(r.rawDescription).map(l=>{const h=l.text.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#039;");return`<span style="color: #${l.color}">${h}</span>`}).join(""):"",v=i=>{const l=i;if(n)return;n=!0,e=document.createElement("div"),e.className="max-w-sm p-3 bg-black/95 border border-gray-700 rounded-md shadow-lg",e.style.cssText=`
                        position: fixed;
                        z-index: 9999;
                        pointer-events: none;
                    `;const h=c();e.innerHTML=`
                        <div class="space-y-2">
                            <div class="flex items-center gap-2">
                                <img src="${o}" alt="" class="w-8 h-8 object-contain" />
                                <div>
                                    <p class="font-medium text-sm" style="color: #${r.color}; margin: 0;">
                                        ${r.name}
                                    </p>
                                </div>
                            </div>
                            ${r.rawDescription?`
                                <div class="text-xs border-t border-border pt-2" style="white-space: pre-wrap; word-wrap: break-word;">${h}</div>
                            `:""}
                        </div>
                    `,document.body.appendChild(e),w(l)},w=i=>{if(!e)return;const l=e.getBoundingClientRect(),h=window.innerWidth,q=window.innerHeight;let x=i.clientX,N=i.clientY+15;x+l.width>h-10&&(x=h-l.width-10),x<10&&(x=10),N+l.height>q-10&&(N=i.clientY-l.height-10),e.style.left=x+"px",e.style.top=N+"px"},p=()=>{e&&n&&(document.body.removeChild(e),e=null,n=!1)};t.addEventListener("mouseenter",v),t.addEventListener("mousemove",i=>w(i)),t.addEventListener("mouseleave",p),s.addEventListener("mouseenter",v),s.addEventListener("mousemove",i=>w(i)),s.addEventListener("mouseleave",p)})};T();const b=new MutationObserver(()=>{setTimeout(T,100)});return b.observe(document.body,{childList:!0,subtree:!0}),()=>b.disconnect()},[y,m])}function X(){return V(".prose"),null}export{U as I,X as N};
