import{_ as c,n as s}from"./thirdweb-Co3M1EyP.js";import{a as d}from"./uint8-array-DZKEMhA1.js";const f="data:application/json;base64";function u(r){return!!r.toLowerCase().startsWith(f)}function l(r){const a=r.indexOf(","),o=r.slice(a+1);return d(o)}const h="data:application/json;utf-8";function w(r){return!!r.toLowerCase().startsWith(h)}function m(r){const a=r.indexOf(","),o=r.slice(a+1);try{return decodeURIComponent(o)}catch{return o}}async function T(r){const{client:a,tokenId:o,tokenUri:e}=r;if(u(e))try{return JSON.parse(l(e))}catch(t){throw console.error("Failed to fetch base64 encoded NFT",{tokenId:o,tokenUri:e},t),t}if(w(e))try{return JSON.parse(m(e))}catch(t){throw console.error("Failed to fetch utf8 encoded NFT",{tokenId:o,tokenUri:e},t),t}const{download:n}=await c(async()=>{const{download:t}=await import("./thirdweb-Co3M1EyP.js").then(i=>i.cj);return{download:t}},[]);try{if(!e.includes("{id}"))return await(await n({client:a,uri:e})).json()}catch(t){throw console.error("Failed to fetch non-dynamic NFT",{tokenId:o,tokenUri:e},t),t}try{try{return await(await n({client:a,uri:e.replace("{id}",s(o,{size:32}).slice(2))})).json()}catch{return await(await n({client:a,uri:e.replace("{id}",o.toString())})).json()}}catch(t){throw console.error("Failed to fetch dynamic NFT",{tokenId:o,tokenUri:e},t),t}}export{T as f};
