"use strict";var __defProp=Object.defineProperty,__getOwnPropDesc=Object.getOwnPropertyDescriptor,__getOwnPropNames=Object.getOwnPropertyNames,__hasOwnProp=Object.prototype.hasOwnProperty,__export=(e,r)=>{for(var t in r)__defProp(e,t,{get:r[t],enumerable:!0})},__copyProps=(e,r,t,o)=>{if(r&&"object"==typeof r||"function"==typeof r)for(let d of __getOwnPropNames(r))__hasOwnProp.call(e,d)||d===t||__defProp(e,d,{get:()=>r[d],enumerable:!(o=__getOwnPropDesc(r,d))||o.enumerable});return e},__toCommonJS=e=>__copyProps(__defProp({},"__esModule",{value:!0}),e),reducer_exports={};__export(reducer_exports,{getLoadLinkedProductsDispatcher:()=>getLoadLinkedProductsDispatcher,getRemoveLinkedProductDispatcher:()=>getRemoveLinkedProductDispatcher,getSelectSearchedProductDispatcher:()=>getSelectSearchedProductDispatcher,reducer:()=>reducer}),module.exports=__toCommonJS(reducer_exports);var import_data=require("@wordpress/data"),import_data2=require("@woocommerce/data");function reducer(e,r){switch(r.type){case"SELECT_SEARCHED_PRODUCT":case"REMOVE_LINKED_PRODUCT":return r.payload.selectedProduct?{...e,...r.payload}:e;default:return{...e,...r.payload}}}function getLoadLinkedProductsDispatcher(e){return async function(r){return 0===r.length?(e({type:"SET_LINKED_PRODUCTS",payload:{linkedProducts:[]}}),Promise.resolve([])):(e({type:"LOADING_LINKED_PRODUCTS",payload:{isLoading:!0}}),(0,import_data.resolveSelect)(import_data2.productsStore).getProducts({include:r}).then(r=>(e({type:"SET_LINKED_PRODUCTS",payload:{linkedProducts:r}}),r)).finally(()=>{e({type:"LOADING_LINKED_PRODUCTS",payload:{isLoading:!1}})}))}}function getSelectSearchedProductDispatcher(e){return function(r,t){Array.isArray(r)||(r=[r]);const o=[...t,...r];return e({type:"SELECT_SEARCHED_PRODUCT",payload:{selectedProduct:r,linkedProducts:o}}),o.map(e=>e.id)}}function getRemoveLinkedProductDispatcher(e){return function(r,t){const o=t.reduce((e,t)=>t.id===r.id?e:[...e,t],[]);return e({type:"REMOVE_LINKED_PRODUCT",payload:{selectedProduct:r,linkedProducts:o}}),o.map(e=>e.id)}}