(()=>{"use strict";var e={n:r=>{var t=r&&r.__esModule?()=>r.default:()=>r;return e.d(t,{a:t}),t},d:(r,t)=>{for(var o in t)e.o(t,o)&&!e.o(r,o)&&Object.defineProperty(r,o,{enumerable:!0,get:t[o]})},o:(e,r)=>Object.prototype.hasOwnProperty.call(e,r),r:e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}},r={};e.r(r),e.d(r,{default:()=>_});const t=window.wp.data,o={vendors:[],loading:!0,error:void 0,queryParams:{page:1,per_page:10,status:void 0,search:"",orderby:"registered",order:"desc"},vendorStats:{},topProducts:{},loadingTopProducts:{},createOrEditVendorLoading:!1,createOrEditVendor:{},createOrEditVendorErrors:[]},d={setVendors:e=>({type:"SET_VENDORS",vendors:e}),setVendor:e=>({type:"SET_VENDOR",vendor:e}),setLoading:e=>({type:"SET_LOADING",loading:e}),setError:e=>({type:"SET_ERROR",error:e}),setQueryParams:e=>({type:"SET_QUERY_PARAMS",queryParams:e}),updateQueryParam:(e,r)=>({type:"UPDATE_QUERY_PARAM",key:e,value:r}),setVendorStats:(e,r)=>({type:"SET_VENDOR_STATS",vendorId:e,stats:r}),setTopProducts:(e,r)=>({type:"SET_TOP_PRODUCTS",vendorId:e,products:r}),setLoadingTopProducts:(e,r)=>({type:"SET_LOADING_TOP_PRODUCTS",vendorId:e,loading:r}),setCreateOrEditVendor:e=>({type:"SET_CREATE_OR_EDIT_VENDOR",vendor:e}),setCreateOrEditVendorLoading:e=>({type:"SET_CREATE_OR_EDIT_VENDOR_LOADING",loading:e}),setCreateOrEditVendorErrors:e=>({type:"SET_CREATE_OR_EDIT_VENDOR_ERRORS",errors:e})},s={getVendors:e=>e.vendors,getVendor(e,r){const{vendors:t}=e;return t.find(e=>e.id===r)},isLoading:e=>e.loading,getError:e=>e.error,getVendorStats:(e,r)=>e.vendorStats?e.vendorStats[r]:{},getTopProducts:(e,r)=>e.topProducts?.[r]||[],isLoadingTopProducts:(e,r)=>e.loadingTopProducts&&e.loadingTopProducts[r]||!1,getCreateOrEditVendor:e=>e.createOrEditVendor,getCreateOrEditVendorLoading:e=>e.createOrEditVendorLoading,getCreateOrEditVendorErrors:e=>e.createOrEditVendorErrors},n=s,a=window.wp.apiFetch;var i=e.n(a);const E={getVendors:()=>async({select:e,dispatch:r})=>{r.setLoading(!0),await i()({path:"/dokan/v1/stores"})},getVendor:e=>async({select:r,dispatch:t})=>{t.setLoading(!0);const o=await i()({path:"/dokan/v1/stores/"+e});return t.setVendor(o),t.setLoading(!1)},getVendorStats:e=>async({dispatch:r})=>{r.setLoading(!0);try{const t=await i()({path:`/dokan/v1/stores/${e}/stats`});r.setVendorStats(e,t)}finally{r.setLoading(!1)}},getTopProducts:e=>async({dispatch:r})=>{r.setLoadingTopProducts(e,!0);try{const t=await i()({path:`/dokan/v1/products/best_selling?per_page=4&seller_id=${e}`});r.setTopProducts(e,t)}catch(t){console.error("Error fetching best selling products:",t),r.setTopProducts(e,[])}finally{r.setLoadingTopProducts(e,!1)}}},c=(0,t.createReduxStore)("dokan/vendors",{reducer:(e=o,r)=>{switch(r.type){case"SET_VENDORS":return{...e,vendors:r.vendors};case"SET_VENDOR":return e.vendors.some(e=>e.id===r.vendor.id)?{...e,vendors:e.vendors.map(e=>e.id===r.vendor.id?r.vendor:e)}:{...e,vendors:[...e.vendors,r.vendor]};case"SET_LOADING":return{...e,loading:r.loading};case"SET_ERROR":return{...e,error:r.error};case"SET_QUERY_PARAMS":return{...e,queryParams:r.queryParams};case"UPDATE_QUERY_PARAM":return{...e,queryParams:{...e.queryParams,[r.key]:r.value}};case"SET_VENDOR_STATS":return{...e,vendorStats:{...e.vendorStats||{},[r.vendorId]:r.stats}};case"SET_TOP_PRODUCTS":return{...e,topProducts:{...e.topProducts,[r.vendorId]:r.products}};case"SET_LOADING_TOP_PRODUCTS":return{...e,loadingTopProducts:{...e.loadingTopProducts,[r.vendorId]:r.loading}};case"SET_CREATE_OR_EDIT_VENDOR":return{...e,createOrEditVendor:r.vendor};case"SET_CREATE_OR_EDIT_VENDOR_LOADING":return{...e,createOrEditVendorLoading:r.loading};case"SET_CREATE_OR_EDIT_VENDOR_ERRORS":return{...e,createOrEditVendorErrors:r.errors};default:return e}},selectors:n,actions:d,resolvers:E});(0,t.register)(c);const _=c;(window.dokan=window.dokan||{}).vendorsStore=r})();