import{r as I,_ as C}from"./index-iQt3bUih.js";const p=t=>{const e=t==null?void 0:t.trim();return e&&!/^-\s*(?:\+\d+)?$/.test(e)?e:void 0},b=t=>{const e=C();return e==="zh"?p(t.zh)??p(t.name)??t.id:e==="zh-CN"?p(t["zh-CN"])??p(t.zhCN)??p(t.zh)??p(t.name)??t.id:e==="ja"?p(t.ja)??p(t.name)??t.id:p(t.name)??t.id};function j(t,e){if(!t||!e)return;const r=e.replace(/^BOSS_/i,""),s=t.palById.get(e)??t.palById.get(r)??t.palByIdLower.get(e.toLowerCase())??t.palByIdLower.get(r.toLowerCase());if(s)return{entity:s,iconUrl:s.icon?f(s.icon):void 0};const i=t.humanByIdLower.get(e.toLowerCase())??t.humanByIdLower.get(r.toLowerCase());if(i)return{entity:i,iconUrl:i.icon?w(i.icon):void 0};const o=e.replace(/[Bb]oss\d*$/,"").replace(/\d+$/,"");if(o&&o!==e){const l=t.palById.get(o)??t.palByIdLower.get(o.toLowerCase());if(l)return{entity:l,iconUrl:l.icon?f(l.icon):void 0,unknown:!0};const m=t.humanByIdLower.get(o.toLowerCase());if(m)return{entity:m,iconUrl:m.icon?w(m.icon):void 0,unknown:!0}}const u=o||e.replace(/_\d+$/,"");return{entity:{id:e,name:u},iconUrl:void 0,unknown:!0}}const L="https://raw.githubusercontent.com/myshox/palserver-admin-ui/main/packages/web/public/game-data/";let n=null,d=null;const y=new Set;function S([t,e,r,s,i,o,u]){const l=t.map(a=>({...a,entityType:"pal"})),m=i.map(a=>({...a,entityType:"human",category:a.category??"Human NPC"})),c=e.map(a=>({...a,entityType:"item"})),g=[...l,...m];return{pals:l,characters:g,items:c,technologies:u,eggs:c.filter(a=>a.id.startsWith("PalEgg")),passives:r,activeSkills:s,humans:m,research:o,palById:new Map(l.map(a=>[a.id,a])),characterById:new Map(g.map(a=>[a.id,a])),itemById:new Map(c.map(a=>[a.id,a])),passiveById:new Map(r.map(a=>[a.id,a])),skillById:new Map(s.map(a=>[a.id,a])),palByIdLower:new Map(l.map(a=>[a.id.toLowerCase(),a])),humanByIdLower:new Map(m.map(a=>[a.id.toLowerCase(),a])),researchById:new Map(o.flatMap(a=>[[a.id,a],[a.id.toLowerCase(),a]]))}}function O(t,e){const r=new Map(e.map(s=>[s.id,s["zh-CN"]]));return t.map(s=>{const i=s["zh-CN"]??r.get(s.id);return i?{...s,"zh-CN":i}:s})}async function B(t,e){const r=s=>fetch(`${t}${s}`,e).then(i=>i.json());return Promise.all([r("pals.json"),r("items.json"),r("passives.json"),r("activeSkills.json"),r("humans.json").catch(()=>[]),r("research.json").catch(()=>[]),r("technologies.json").catch(()=>[])])}async function v(){return n||(d||(d=(async()=>(n=S(await B("/game-data/")),J(),n))()),d)}let N=!1;async function J(){if(!N){N=!0;try{const t=await B(L,{cache:"no-cache",signal:AbortSignal.timeout(15e3)}),e=(a,h)=>a.length>0?O(a,h??[]):h??[],r=[e(t[0],n==null?void 0:n.pals),e(t[1],n==null?void 0:n.items),e(t[2],n==null?void 0:n.passives),e(t[3],n==null?void 0:n.activeSkills),e(t[4],n==null?void 0:n.humans),e(t[5],n==null?void 0:n.research),e(t[6],n==null?void 0:n.technologies)],[s,i,o,u,l,m,c]=r,g=JSON.stringify(s)!==JSON.stringify(n==null?void 0:n.pals)||JSON.stringify(i)!==JSON.stringify(n==null?void 0:n.items)||JSON.stringify(o)!==JSON.stringify(n==null?void 0:n.passives)||JSON.stringify(u)!==JSON.stringify(n==null?void 0:n.activeSkills)||JSON.stringify(l)!==JSON.stringify(n==null?void 0:n.humans)||JSON.stringify(m)!==JSON.stringify(n==null?void 0:n.research)||JSON.stringify(c)!==JSON.stringify(n==null?void 0:n.technologies);Array.isArray(s)&&Array.isArray(i)&&s.length>0&&i.length>0&&g&&(n=S(r),y.forEach(a=>a(n)))}catch{}}}function k(){const[t,e]=I.useState(n);return I.useEffect(()=>(y.add(e),n||v().then(e).catch(()=>e(null)),()=>{y.delete(e)}),[]),t}const f=t=>`/game-data/pals/${t}`,z=(t,e)=>(e==null?void 0:e.entityType)==="human"?w(t):f(t),U=t=>`/game-data/items/${t}`,$=t=>`/game-data/${t}`,w=t=>`/game-data/humans/${t}`;export{p as a,z as c,b as d,j as f,U as i,f as p,$ as t,k as u};
