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