import*as e from"@wordpress/interactivity";import*as t from"jetpack-search/store";var r={8638(){},2833(t,r,n){t.exports=(e=>{var t={};return n.d(t,e),t})({getElement:()=>e.getElement,store:()=>e.store})},2653(e,t,r){e.exports=(e=>{var t={};return r.d(t,e),t})({})}},n={};function i(e){var t=n[e];if(void 0!==t)return t.exports;var a=n[e]={exports:{}};return r[e](a,a.exports,i),a.exports}i.d=(e,t)=>{for(var r in t)i.o(t,r)&&!i.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:t[r]})},i.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t);var a=i(2833);i(2653),i(8638);const c="jetpack-search";function l(e){const t=e?.closest?.(".jetpack-search-filter-wc-price");return t?{min:t.querySelector(".jetpack-search-filter-wc-price__slider-input--min"),max:t.querySelector(".jetpack-search-filter-wc-price__slider-input--max")}:{min:null,max:null}}function s(e){if(null==e||""===e)return null;const t=Number(e);return Number.isFinite(t)&&t>=0?t:null}function o(e,t){let r=s(e?.value),n=s(t?.value);if(null!==r&&null!==n&&r>n){const i=(e??t)?.ownerDocument;i&&i.activeElement===t?(n=r,t&&(t.value=String(r))):(r=n,e&&(e.value=String(n)))}return{min:r,max:n}}function u(e,t,r){if(null==e||!Number.isFinite(e))return"";const n=String(Math.round(e));return"right"===r?`${n}${t}`:`${t}${n}`}(0,a.store)(c,{state:{get priceRangeMinInputValue(){const{state:e}=(0,a.store)(c),t=e.priceRange?.min;return null==t?"":String(t)},get priceRangeMaxInputValue(){const{state:e}=(0,a.store)(c),t=e.priceRange?.max;return null==t?"":String(t)}},actions:{*onPriceRangeInputChange(){const e=(0,a.getElement)()?.ref,{min:t,max:r}=function(e){const t=e?.closest?.(".jetpack-search-filter-wc-price");return t?{min:t.querySelector(".jetpack-search-filter-wc-price__input--min"),max:t.querySelector(".jetpack-search-filter-wc-price__input--max")}:{min:null,max:null}}(e);yield(0,a.store)(c).actions.setPriceRange(s(t?.value),s(r?.value))},onPriceRangeInputKeydown(e){"Enter"===e?.key&&(e.preventDefault(),e.target?.blur?.())},onPriceSliderInput(){const e=(0,a.getElement)()?.ref,{min:t,max:r}=l(e);if(!t||!r)return;const n=o(t,r);if(null===n.min||null===n.max)return;const{state:i}=(0,a.store)(c),s=i.priceRange;s&&s.min===n.min&&s.max===n.max||(i.priceRange={min:n.min,max:n.max})},*onPriceSliderChange(){const e=(0,a.getElement)()?.ref,{min:t,max:r}=l(e);if(!t||!r)return;const n=o(t,r),{state:i}=(0,a.store)(c),s=i.priceRange&&i.priceRange.min===n.min&&i.priceRange.max===n.max;yield(0,a.store)(c).actions.setPriceRange(n.min,n.max),s&&(yield(0,a.store)(c).actions.search())}},callbacks:{updatePriceSliderUi(){const e=(0,a.getElement)()?.ref;if(!e)return;const t=e.querySelector(".jetpack-search-filter-wc-price__slider");if(!t)return;const r=e.querySelector(".jetpack-search-filter-wc-price__slider-input--min"),n=e.querySelector(".jetpack-search-filter-wc-price__slider-input--max"),{state:i}=(0,a.store)(c),{sliderMin:l,sliderMax:s}=function(e){const t=e?.querySelector?.(".jetpack-search-filter-wc-price__slider-input--min"),r=e?.querySelector?.(".jetpack-search-filter-wc-price__slider-input--max");return{sliderMin:Number(t?.min)||0,sliderMax:Number(r?.max)||100}}(e),o=i.priceRange,m=e=>Math.min(s,Math.max(l,Number(e))),p=null!=o?.min?m(o.min):l,f=null!=o?.max?m(o.max):s,x=i.priceCurrencySymbol||"",g=i.priceCurrencySymbolPosition||"left",y=e.ownerDocument?.activeElement;if(r&&r!==y){const e=String(p);r.value!==e&&(r.value=e)}if(n&&n!==y){const e=String(f);n.value!==e&&(n.value=e)}const h=s-l;if(!Number.isFinite(h)||h<=0)t.style.setProperty("--low","0%"),t.style.setProperty("--high","100%");else{const e=Math.max(0,Math.min(100,(p-l)/h*100)),r=Math.max(0,Math.min(100,(f-l)/h*100));t.style.setProperty("--low",`${e}%`),t.style.setProperty("--high",`${r}%`)}r&&r.setAttribute("aria-valuetext",u(p,x,g)),n&&n.setAttribute("aria-valuetext",u(f,x,g))}}});