| 1 |
import*as lpUtils from"lpAssetsJsPath/utils.js";import{lpStatsState,LP_STATS_RANGE_RESOLVED}from"./state.js";export const getStatsConfig=()=>window.lpAdminStatisticSettings||{};export const getStatsI18n=(t,s="")=>{const{i18n:e={}}=getStatsConfig();return e[t]||s};export const lpStatsFetch=(t,s={},e={})=>{const o=window.lpDataAdmin||{},r=getStatsConfig().restNamespace||"lp/v1/statistics",a=lpUtils.lpAddQueryArgs(`${o.lp_rest_url||"/wp-json/"}${r}/${t}`,{...lpStatsState.get(),...s}),n="function"==typeof e.error?e.error:t=>console.error("LP Statistics:",t);lpUtils.lpFetchAPI(a,{headers:{"X-WP-Nonce":o.nonce||""}},{...e,success:t=>{if(t&&"success"===t.status){const s=t.data&&t.data.range;s&&s.label&&document.dispatchEvent(new CustomEvent(LP_STATS_RANGE_RESOLVED,{detail:s})),"function"==typeof e.success&&e.success(t)}else n(new Error(t&&t.message||getStatsI18n("loadError","Request failed.")))},error:n})}; |