import*as t from"@wordpress/interactivity";var e={d:(t,o)=>{for(var a in o)e.o(o,a)&&!e.o(t,a)&&Object.defineProperty(t,a,{enumerable:!0,get:o[a]})},o:(t,e)=>Object.prototype.hasOwnProperty.call(t,e)};const o=(a={getContext:()=>t.getContext,store:()=>t.store},n={},e.d(n,a),n);var a,n;function i(t,e){if(!t)return null;const o=window.getComputedStyle(t)[e];if("rgba(0, 0, 0, 0)"!==o&&"transparent"!==o){const t=o.match(/\d+/g);if(!t||t.length<3)return null;const[e,a,n]=t.slice(0,3);return`rgb(${e}, ${a}, ${n})`}return i(t.parentElement,e)}!function(){const t=document.querySelector(".wc-block-add-to-cart-with-options-variation-selector-attribute-options__pills");if(!t)return;const e=document.createElement("style"),o=i(t,"backgroundColor")||"#fff",a=i(t,"color")||"#000";e.appendChild(document.createTextNode(`:where(.wc-block-add-to-cart-with-options-variation-selector-attribute-options__pill:has(.wc-block-add-to-cart-with-options-variation-selector-attribute-options__pill-input:checked)) {\n\t\t\t\t--pill-color: ${o};\n\t\t\t\t--pill-background-color: ${a};\n\t\t\t}`)),document.head.appendChild(e)}();const{actions:r}=(0,o.store)("woocommerce/add-to-cart-with-options",{},{lock:"I acknowledge that using a private store means my plugin will inevitably break on the next store release."});function l(t,e){e?r.setAttribute(t,e):r.removeAttribute(t)}function s(){const t=(0,o.getContext)();t.selectedValue&&l(t.name,t.selectedValue)}const c=({attributeName:t,attributeValue:e,selectedAttributes:o,availableVariations:a})=>{const n=o.some((e=>e.attribute===t))?o.length-1:o.length;return a.some((a=>(a.attributes[t]===e||""===a.attributes[t])&&o.filter((o=>{const n=a.attributes[o.attribute];return n===o.value||""===n&&(o.attribute!==t||e===o.value)})).length>=n))},{state:u}=(0,o.store)("woocommerce/add-to-cart-with-options-variation-selector-attribute-options__pills",{state:{get isPillSelected(){const{selectedValue:t,option:e}=(0,o.getContext)();return t===e.value},get isPillDisabled(){const{name:t,option:e}=(0,o.getContext)(),{selectedAttributes:a,availableVariations:n}=(0,o.getContext)("woocommerce/add-to-cart-with-options");return!c({attributeName:t,attributeValue:e.value,selectedAttributes:a,availableVariations:n})},get index(){const t=(0,o.getContext)();return t.options.findIndex((e=>e.value===t.option.value))}},actions:{toggleSelected(){if(u.isPillDisabled)return;const t=(0,o.getContext)();t.selectedValue===t.option.value?t.selectedValue="":t.selectedValue=t.option.value,l(t.name,t.selectedValue)}},callbacks:{setDefaultSelectedAttribute:s}},{lock:!0});(0,o.store)("woocommerce/add-to-cart-with-options-variation-selector-attribute-options__dropdown",{state:{get isOptionDisabled(){const{name:t,option:e}=(0,o.getContext)();if(""===e.value)return!1;const{selectedAttributes:a,availableVariations:n}=(0,o.getContext)("woocommerce/add-to-cart-with-options");return!c({attributeName:t,attributeValue:e.value,selectedAttributes:a,availableVariations:n})}},actions:{handleChange(t){const e=(0,o.getContext)();e.selectedValue=t.currentTarget.value,l(e.name,e.selectedValue)}},callbacks:{setDefaultSelectedAttribute:s}},{lock:!0});