"use strict";(globalThis.webpackChunkwoocommerce_product_options=globalThis.webpackChunkwoocommerce_product_options||[]).push([[856],{4513:(e,t,n)=>{n.d(t,{default:()=>r}),n(7723);var o=n(324);const r=function(e){const t=e,n=window.jQuery;let r,i;function a(){let e=!1;r.forEach(t=>{t.inputElements.forEach(n=>{(0,o.Vm)(t.type)||(0,o.rh)(t.type)?n.checked&&(e=!0,c({target:n},t)):"dropdown"===t.type&&n.value&&(e=!0,c({target:n},t))})}),e&&n(t).find(".variations select").trigger("change.wc-variation-form")}function c(e,o){let r;var i,a;if("dropdown"===o.type?(r=null!==(i=e.target.options?.[e.target.selectedIndex]?.dataset?.attributeTerm)&&void 0!==i?i:null,d(o.inputElements[0])):r=null!==(a=e.target.dataset?.attributeTerm)&&void 0!==a?a:null,null===r)return;const c=t.querySelector(`select[name="attribute_${o.variationAttribute}"]`);null!==c&&(c.value=r,n(c).trigger("change"))}function l(){r.forEach(e=>{e.inputElements.forEach(t=>{(0,o.Vm)(e.type)||(0,o.rh)(e.type)?t.checked=!1:"dropdown"===e.type&&t._niceSelect?.clear()})})}function s(){const e=i.map(e=>t.querySelector(`select[name="attribute_${e}"]`)),n=Object.fromEntries(i.map((t,n)=>{const o=e?.[n];return[t,Array.from(o.options).filter(e=>!e.disabled&&e.value).map(e=>e.value)]}));r.forEach(e=>{var t;const r=null!==(t=n[e.variationAttribute])&&void 0!==t?t:[];r.length&&(("dropdown"===e.type?Array.from(e.inputElements[0].options):e.inputElements).forEach(t=>{r.includes(t.dataset.attributeTerm)?function(e,t){if(e.disabled=!1,(0,o.Vm)(t)||(0,o.rh)(t)){const n=e.closest(p(t));n?.classList?.remove("wpo-field-hide")}}(t,e):function(e,t){if((0,o.Vm)(t)||(0,o.rh)(t)){const n=e.closest(p(t));n?.classList?.add("wpo-field-hide"),e.disabled=!0,e.checked=!1}(0,o.D4)(t,"dropdown")&&e.value&&(e.disabled=!0,e.selected=!1)}(t,e)}),"dropdown"===e.type&&d(e.inputElements[0]))})}function u(){const e=t.querySelector(".reset_variations"),n=e?.closest(".variations");if(!n)return;const o=0===n.querySelectorAll("select").length&&0===e?.getBoundingClientRect().width;n.style.display=o?"none":"table"}function d(e){0===e.selectedIndex&&(e.selectedIndex=-1),-1===e.selectedIndex?n(t).trigger("reset_data"):e._niceSelect?.update()}function p(e){return{checkbox:".wpo-checkbox",radio:".wpo-radio",image_buttons:".wpo-image-button",text_labels:".wpo-text-label",color_swatches:".wpo-color-checkbox"}?.[e.type]}return{init:function(){return t instanceof HTMLFormElement&&!!["variations_form","wpt_variations_form"].some(e=>t.classList.contains(e))&&(r=Array.from(t.querySelectorAll(".wpo-field")).map(e=>({element:e,inputElements:e.querySelectorAll((0,o.xL)(e.dataset.type)),type:e.dataset?.type,variationAttribute:e.dataset?.variationAttribute})).filter(e=>e.variationAttribute),i=r.map(e=>e.variationAttribute),0!==r.length&&(r.forEach(e=>{e?.element.addEventListener("change",t=>c(t,e))}),t.querySelector(".reset_variations")?.addEventListener("click",l),n(t).on("woocommerce_update_variation_values",s),n(t).on("check_variations",u),a(),void function(){const e=new URL(window.location.href);i?.forEach(t=>{const n=e.searchParams.get(`attribute_${t}`);if(!n)return;const i=r.find(e=>e.variationAttribute===t);if(i)if((0,o.Vm)(i.type)||(0,o.rh)(i.type))i.inputElements.forEach(e=>{e.checked=e.dataset.attributeTerm===n});else if("dropdown"===i.type){const e=i.inputElements[0],t=Array.from(e.options).find(e=>e.dataset.attributeTerm===n);t&&(e.value=t.value)}}),a()}()))}}}}}]);