(()=>{"use strict";var t={n:e=>{var s=e&&e.__esModule?()=>e.default:()=>e;return t.d(s,{a:s}),s},d:(e,s)=>{for(var o in s)t.o(s,o)&&!t.o(e,o)&&Object.defineProperty(e,o,{enumerable:!0,get:s[o]})},o:(t,e)=>Object.prototype.hasOwnProperty.call(t,e),r:t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})}},e={};t.r(e),t.d(e,{STORE_NAME:()=>o,default:()=>f,store:()=>I});const s=window.wp.data,o="wc-affiliate/import",r="SET_IMPORT_TYPES",a="SET_IMPORT_JOB",i="SET_IMPORT_JOBS",p="SET_IS_RESOLVING",n="SET_ERROR",c={setIsResolving:(t,e)=>({type:p,key:t,isResolving:e}),setError:(t,e)=>({type:n,key:t,error:e}),setImportTypes:t=>({type:r,types:t}),setImportJob:t=>({type:a,job:t}),setImportJobs:t=>({type:i,jobs:t})},l={importTypes:{},importJob:null,importJobs:[],isResolving:{},errors:{}},m=(t=l,e)=>{switch(e.type){case r:return{...t,importTypes:e.types};case a:return{...t,importJob:e.job};case i:return{...t,importJobs:e.jobs};case p:return{...t,isResolving:{...t.isResolving,[e.key]:e.isResolving}};case n:return{...t,errors:{...t.errors,[e.key]:e.error}};case"START_IMPORT":return{...t,importJob:e.importData};case"CANCEL_IMPORT":return{...t,importJobs:t.importJobs.map(t=>t.id===e.importId?{...t,status:"cancelled"}:t)};case"DELETE_IMPORT":return{...t,importJobs:t.importJobs.filter(t=>t.id!==e.importId)};default:return t}};(Object.getOwnPropertyDescriptor(m,"name")||{}).writable||Object.defineProperty(m,"name",{value:"default",configurable:!0});const d=window.wp.apiFetch;var y=t.n(d);const g={getImportTypes:()=>async({dispatch:t})=>{const e="import-types";t(c.setIsResolving(e,!0));try{const e=await y()({path:"/wc-affiliate/v1/import/types"});t(c.setImportTypes(e))}catch(s){const o=s.message||"Failed to fetch import types";t(c.setError(e,o))}finally{t(c.setIsResolving(e,!1))}},validateImport:t=>async({dispatch:e})=>{const s="validate-import";e(c.setIsResolving(s,!0));try{return await y()({path:"/wc-affiliate/v1/import/validate",method:"POST",data:t})}catch(t){const o=t.message||"Failed to validate import";throw e(c.setError(s,o)),t}finally{e(c.setIsResolving(s,!1))}},startImport:t=>async({dispatch:e})=>{const s="start-import";e(c.setIsResolving(s,!0));try{const s=await y()({path:"/wc-affiliate/v1/import/start",method:"POST",data:t});e(c.setImportJob(s))}catch(t){const o=t.message||"Failed to start import";e(c.setError(s,o))}finally{e(c.setIsResolving(s,!1))}},getImportStatus:t=>async({dispatch:e})=>{const s=`import-status-${t}`;e(c.setIsResolving(s,!0));try{const s=await y()({path:`/wc-affiliate/v1/import/${t}/status`});e(c.setImportJob(s))}catch(t){const o=t.message||"Failed to get import status";e(c.setError(s,o))}finally{e(c.setIsResolving(s,!1))}},cancelImport:t=>async({dispatch:e})=>{const s=`cancel-import-${t}`;e(c.setIsResolving(s,!0));try{await y()({path:`/wc-affiliate/v1/import/${t}/cancel`,method:"POST"}),e(c.setImportJob({id:t,status:"cancelled"}))}catch(t){const o=t.message||"Failed to cancel import";e(c.setError(s,o))}finally{e(c.setIsResolving(s,!1))}},deleteImport:t=>async({dispatch:e})=>{const s=`delete-import-${t}`;e(c.setIsResolving(s,!0));try{await y()({path:`/wc-affiliate/v1/import/${t}`,method:"DELETE"}),e(c.setImportJobs([]))}catch(t){const o=t.message||"Failed to delete import";e(c.setError(s,o))}finally{e(c.setIsResolving(s,!1))}},getImportJobs:()=>async({dispatch:t})=>{const e="import-jobs";t(c.setIsResolving(e,!0));try{const e=await y()({path:"/wc-affiliate/v1/import/jobs"});t(c.setImportJobs(e))}catch(s){const o=s.message||"Failed to fetch import jobs";t(c.setError(e,o))}finally{t(c.setIsResolving(e,!1))}}},I=(0,s.createReduxStore)(o,{reducer:m,actions:c,selectors:{getImportTypes:t=>t.importTypes,getImportJob:t=>t.importJob,getImportJobs:t=>t.importJobs,isResolving:(t,e)=>t.isResolving[e]||!1,getError:(t,e)=>t.errors[e]||null},resolvers:g});(0,s.register)(I);const f=I;(window.wcAffiliate=window.wcAffiliate||{}).importStore=e})();