"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const m=require("../../conf/index.js"),A=require("../../api/commons.js");function p(t){return JSON.parse(JSON.stringify(t))}const u=process.env.VITE_REACT_APP_API_ROOT||m.Config.REACT_APP_API_ROOT||null,O=typeof window<"u"?window.location.origin:"",f={},l={},I=3*60*1e3;function P(t){return Object.keys(t).map(n=>encodeURIComponent(n)+"="+encodeURIComponent(t[n])).join("&")}function C(t,n=!1){const e=t,o=Date.now();if(l[e]&&o-l[e].timestamp<I)return Promise.resolve(p(l[e].data));if(f[e])return f[e].then(p);const g=A.get(t,{},n).then(a=>(l[e]={data:a,timestamp:Date.now()},n?{data:p(a),meta:l[e].meta}:p(a))).finally(()=>{delete f[e]});return f[e]=g,g}const E=({app:t,params:n})=>{const e=`${u||O}/api/${t}/categories${n?"?"+P(n):""}`;return C(e)},U=({app:t,type:n,params:e})=>{const o=`${u||""}/api/${t}/categories/${n}${e?"?"+P(e):""}`;return console.log("categories==>",o),C(o)},b=({source:t,app:n,params:e})=>{const o=`${u||O}/api/${n}/stats/${t}${e?"?"+P(e):""}`;return C(o)},j=({postType:t,taxonomy:n,category:e,taxonomyFilters:o,before:g,perPage:a,page:T,locale:h,after:S,ordering:_,orderingDirection:R})=>{const q=`${m.Config.REACT_APP_WP_API}/wp/v2/${t}`,r=new URLSearchParams,d=new Map,y=(s,i)=>{if(!s||i==null)return;const c=d.get(s)||[];Array.isArray(i)?i.forEach($=>{$!=null&&c.push(String($))}):c.push(String(i)),d.set(s,c)};o&&o instanceof Map&&o.forEach((s,i)=>{y(i,s)}),n&&e!=null&&y(n,e),d.forEach((s,i)=>{const c=Array.from(new Set(s));c.length!==0&&r.set(i,c.join(","))}),g&&r.append("before",g.toISOString()),a&&r.append("per_page",a.toString()),r.append("page",T.toString()),r.append("locale",h),S&&r.append("after",S.toISOString()),r.append("orderby",_),r.append("order",R);const w=r.toString().replace(/%2C/g,",");return A.get(`${q}?${w}`,{headers:{"Content-Type":"application/json"},credentials:"include"},!0)};exports.getCategories=E;exports.getCategory=U;exports.getCustomPosts=j;exports.getData=b;
