import{w as t}from"./main-qHBKdA_h.js";function r(r){const e={};r.query&&r.query.query&&r.query.query.length&&r.query.query.forEach((a=>{if("variable"===a.type){const o=a.id;t&&t[r.dataQueryID]&&t[r.dataQueryID][o]||(a.variation_defaults?e[o]={...a.variation_defaults}:e[o]={})}})),e&&t.update((t=>{const a=JSON.parse(JSON.stringify(t));return a[r.dataQueryID]=e,a}))}function e(r){r.query&&r.query.query&&r.query.query.length&&r.query.query.forEach((e=>{if("variable"===e.type){const o=e.id;if(r.wooProducts&&r.wooProducts[r.dataQueryID]&&r.wooProducts[r.dataQueryID][o]&&e.variation&&e.variation.length===Object.keys(r.wooProducts[r.dataQueryID][o]).length&&Object.values(r.wooProducts[r.dataQueryID][o]).every((t=>null!==t&&""!==t))){const u=a(e.variations,r.wooProducts[r.dataQueryID][o]).shift(),s={info:u,attributes:u&&u.attributes&&Object.entries(u.attributes).map((([t,e])=>{const a={};return Object.entries(r.wooProducts[r.dataQueryID][o]).forEach((([r,e])=>{t.replace("attribute_","").toLowerCase()===r.toLowerCase()&&(a.attribute=r,a.value=e)})),a}))};s&&t.update((t=>{const a=JSON.parse(JSON.stringify(t));return a[`${r.dataQueryID}-${e.id}-cart`]=s,a}))}else r.wooProducts&&r.wooProducts[`${r.dataQueryID}-${e.id}-cart`]&&t.update((t=>{const a=JSON.parse(JSON.stringify(t));return delete a[`${r.dataQueryID}-${e.id}-cart`],a}))}}))}function a(t,r){for(var e=[],a=0;a<t.length;a++){var u=t[a];o(u.attributes,r)&&e.push(u)}return e}function o(t,r){var e=!0;for(var a in t){const s=a.replace("attribute_","");if(t.hasOwnProperty(a)){var o=t[a];const i={};Object.keys(r).forEach((t=>{i[t.toLowerCase()]=r[t]}));var u=i[s];void 0!==o&&void 0!==u&&0!==o.length&&0!==u.length&&o!==u&&(e=!1)}}return e}export{a,e as f,r as p};
