(()=>{"use strict";var e={n:t=>{var r=t&&t.__esModule?()=>t.default:()=>t;return e.d(r,{a:r}),r},d:(t,r)=>{for(var s in r)e.o(r,s)&&!e.o(t,s)&&Object.defineProperty(t,s,{enumerable:!0,get:r[s]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r:e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}},t={};e.r(t),e.d(t,{STORE_NAME:()=>s,default:()=>b,store:()=>S});const r=window.wp.data,s="wc-affiliate/dashboard",a="SET_DASHBOARD_STATS",o="SET_DASHBOARD_CHARTS",i="SET_TOP_PERFORMERS",n="SET_IS_RESOLVING",c="SET_ERROR",d={setIsResolving:(e,t)=>({type:n,key:e,isResolving:t}),setError:(e,t)=>({type:c,key:e,error:t}),setDashboardStats:(e,t)=>({type:a,key:e,stats:t}),setDashboardCharts:(e,t,r)=>({type:o,chartType:e,data:t,affiliateId:r}),setTopPerformers:(e,t)=>({type:i,key:e,data:t})},l={stats:{},charts:{},topPerformers:{},affiliateDashboard:{},isResolving:{},errors:{}},f=(e=l,t)=>{switch(t.type){case a:return{...e,stats:{...e.stats,[t.key]:t.stats}};case o:const r=t.affiliateId?`${t.chartType}_${t.affiliateId}`:t.chartType;return{...e,charts:{...e.charts,[r]:t.data}};case i:return{...e,topPerformers:{...e.topPerformers,[t.key]:t.data}};case n:return{...e,isResolving:{...e.isResolving,[t.key]:t.isResolving}};case c:return{...e,errors:{...e.errors,[t.key]:t.error}};default:return e}};(Object.getOwnPropertyDescriptor(f,"name")||{}).writable||Object.defineProperty(f,"name",{value:"default",configurable:!0});const y=window.wp.apiFetch;var p=e.n(y);const h=window.wp.url,g={getDashboardStats:(e={})=>async({dispatch:t})=>{const r=JSON.stringify(e);t(d.setIsResolving(r,!0));try{const s=(0,h.addQueryArgs)("/wc-affiliate/v1/dashboard/stats",e),a=await p()({path:s});t(d.setDashboardStats(r,a))}catch(e){const s=e.message||"Failed to fetch dashboard stats";t(d.setError(r,s))}finally{t(d.setIsResolving(r,!1))}},getDashboardCharts:(e,t={})=>async({dispatch:r})=>{const s=JSON.stringify({chartType:e,...t});r(d.setIsResolving(s,!0));try{const s=(0,h.addQueryArgs)("/wc-affiliate/v1/dashboard/charts",{chart_type:e,...t}),a=await p()({path:s});r(d.setDashboardCharts(e,a,t.affiliate_id))}catch(t){const a=t.message||`Failed to fetch dashboard chart ${e}`;r(d.setError(s,a))}finally{r(d.setIsResolving(s,!1))}},getTopPerformers:(e,t={})=>async({dispatch:r})=>{const s=JSON.stringify({performerType:e,...t});r(d.setIsResolving(s,!0));try{const a=(0,h.addQueryArgs)("/wc-affiliate/v1/dashboard/top-performers",{type:e,...t}),o=await p()({path:a});r(d.setTopPerformers(s,o))}catch(t){const a=t.message||`Failed to fetch top performers ${e}`;r(d.setError(s,a))}finally{r(d.setIsResolving(s,!1))}}},u={getDashboardStats(e,t={}){if(!e)return null;const r=JSON.stringify(t);return e.stats?.[r]||null},getDashboardCharts(e,t,r){if(!e)return;const s=r?`${t}_${r}`:t;return e.charts[s]},getTopPerformers(e,t,r={}){if(!e)return;const s=JSON.stringify({performerType:t,...r});return e.topPerformers[s]},isResolving:(e,t)=>e?.isResolving[t]||!1,getError:(e,t)=>e?.errors[t]||null},S=(0,r.createReduxStore)(s,{reducer:f,actions:d,selectors:u,resolvers:g});(0,r.register)(S);const b=S;(window.wcAffiliate=window.wcAffiliate||{}).dashboardStore=t})();