import{o as e}from"./chunk-mlkTr37E.js";import{t}from"./lodash-DulIlzb9.js";import{r as n}from"./cache-hsasTrVL.js";import{r}from"./cookies-sMX4awhg.js";import{t as i}from"./delay-CW5VuKve.js";import{i as a}from"./utils-DZAq82W9.js";import{t as o}from"./sha256-DckaqLPt.js";var s=e(i()),c=e(t()),l=e(o()),u=async(e,t=5e3)=>document.querySelector(e)?document.querySelector(e):new Promise((n,r)=>{setTimeout(()=>r(`WAIT_ELEMENT_TIME_OUT`),t);let i=new MutationObserver(()=>{document.querySelector(e)&&(i.disconnect(),n(document.querySelector(e)))});i.observe(document.body,{childList:!0,subtree:!0})}),d=async(e,t=`GET`,i=null)=>{if(!e)throw`MISSING_FETCH_URL`;let o=new n(e);if(t===`GET`){let e=await o.get();if(e)return e}let d=!!(t===`POST`&&i),f=d?a():(0,l.default)(e).toString(),p=`script-fetch-${f}`,m=`script-content-${f}`,h=`#${m}`,g=c.default.random(100,500,!1),_=d?2e3:500,v=document.querySelector(h);if(!v){let t=r(`csrftoken`),n={accept:`application/json`,"af-ac-enc-dat":null,"af-ac-enc-sz-token":null,"content-type":`application/json`,"cache-control":`no-cache`,priority:`u=1, i`,"sec-ch-ua-mobile":`?0`,"sec-ch-ua-platform":`"Windows"`,"sec-fetch-dest":`empty`,"sec-fetch-mode":`cors`,"sec-fetch-site":`same-origin`,"x-api-source":`pc`,"x-requested-with":`XMLHttpRequest`,"x-shopbff-version":`2`,"x-shopee-language":`vi`,"x-sz-sdk-version":`1.12.15`};t&&(n[`x-csrftoken`]=t);let a={headers:n,method:`GET`};d&&(a.method=`POST`,a.body=JSON.stringify(i));let o=`
        fetch('${e}', ${JSON.stringify(a)})
          .then((res) => res.json())
          .then((value) => {
              const script = document.createElement('script');
              script.type = type="application/json";
              script.id = '${m}';
              script.textContent = JSON.stringify(value);
              document.head.appendChild(script);
          })
          .catch(() => {
              const script = document.createElement('script');
              script.type = type="application/json";
              script.id = '${m}';
              script.textContent = JSON.stringify(null);
              document.head.appendChild(script);
          });

    `,c=d?`
      setTimeout(() => {
          ${o}
      }, ${g})
    `:o,l=document.createElement(`script`);l.type=`application/javascript`,l.id=p,l.textContent=c,document.head.appendChild(l),await(0,s.default)(_),l.remove(),await u(h,5e3).catch(()=>{})}if(v=document.querySelector(h),!v)return null;let y=JSON.parse(v.textContent);return t===`GET`&&await o.set(y),y},f=async(e,t={})=>(await fetch(e,{headers:t})).json();export{f as n,d as t};