1import{b as r,m as f,a,e as m,c as h}from"./vite-index-DIVHY0ly.js";import{s as c}from"./vite-index-W7ov81f_.js";import{g as w}from"./vite-getHandle-CQ0RA71c.js";import{d as v}from"./vite-debounce-z3MRm752.js";const n={open:"facets:open",close:"facets:close",opened:"facets:opened",closed:"facets:closed",update:"facets:update",reset:"facets:reset"},$={title:"[data-facets-title]"},S=()=>({searchParamsOld:null,isOpen:!1,isLoading:!1,init(){this.resetFilters=this.resetFilters.bind(this),this.open=this.open.bind(this),this.close=this.close.bind(this),this.debounceonHistoryChange=v(this.onHistoryChange.bind(this),300);const e=this.createSearchParams(this.$el);this.searchParamsOld=e,this.$dispatch(r.mutations.isFiltered,this.isFiltered(e)),this.bindEvents(),this.loadAccordion()},destroy(){window.removeEventListener("popstate",this.debounceonHistoryChange),window.removeEventListener(n.open,this.open),window.removeEventListener(n.close,this.close),window.removeEventListener(n.reset,this.resetFilters)},bindEvents(){window.addEventListener("popstate",this.debounceonHistoryChange),window.addEventListener(n.open,this.open),window.addEventListener(n.close,this.close),window.addEventListener(n.reset,this.resetFilters)},open(){this.isOpen=!0,this.$el.focus(),this.$dispatch(n.opened),this.$dispatch(r.mutations.addUi,{id:"facets"})},close(){this.isOpen=!1,this.$dispatch(n.closed),this.$dispatch(r.mutations.removeUi,{id:"facets"})},onHistoryChange(e){const t=e.state?e.state.searchParams:window.location.search.slice(1);t!==this.searchParamsOld&&this.render(t.toString(),!1)},onInput(){const e=this.createSearchParams(this.$el);this.render(e)},async render(e,t=!0){this.isLoading=!0;const i=this.isFiltered(e);this.$dispatch(h.add,"facets"),this.$dispatch(r.mutations.isFiltered,i),i&&await this.forceRender4x4View(!1),t&&this.updateURLHash(e);const s=`${window.routes.root}?sections=${this.sections.map(o=>o.id).filter(o=>o!==void 0).join(",")}&${e}&view=${this.$store.shop.currentViewCollection}`;try{const o=await this.$store.sections.getSections(s);this.searchParamsOld=e,this.updateSections(o),this.updateActiveClass(e)}catch(o){console.error(`facets: ${o}`)}finally{this.$dispatch(h.done,"facets"),setTimeout(()=>{this.isLoading=!1,window.scrollTo(0,0)},300)}},updateSections(e){for(const t in e){const i=document.querySelector(`#shopify-section-${t}`);f.morph(i,e[t],{adding(s,o){if(s instanceof HTMLElement&&s.hasAttribute(a.Alpine.morph.skip))return o()},updating(s,o,u,p){if(s instanceof HTMLElement){const d=s.getAttribute("key"),l=o.getAttribute("key");if(d===l&&d&&l||s.hasAttribute(a.Alpine.morph.skip))return p();if(s.hasAttribute(a.Alpine.morph.children))return u()}},removing(s,o){if(s instanceof HTMLElement&&s.hasAttribute(a.Alpine.morph.skip))return o()},lookahead:!0}),t===this.sections[0].id&&this.$store.shop.currentViewCollection==="edito"&&this.isFiltered(this.searchParamsOld)&&this.forceRender4x4View(!0),window.dispatchEvent(new CustomEvent(m.newDOM,{detail:{node:i},bubbles:!0}))}},updateURLHash(e){history.pushState({searchParams:e},"",`${window.location.pathname}${e&&`?type=${new Date().valueOf()}&`.concat(e)}`)},updateActiveClass(e){const t=e.split("&").map(s=>s.split("=")[0]),i=this.$el.querySelectorAll($.title);for(const s of i){const{id:o}=s;t.includes(o)?s.classList.add("is-active"):s.classList.remove("is-active")}},createSearchParams(e){const t=new FormData(e);return new URLSearchParams(t).toString()},isFiltered(e){const t=e.split("&").map(i=>{const s=i.split("=");return{key:s[0],value:s[1]}}).filter(i=>i.key!==""&&i.value!==void 0);return t.length>0&&t.some(i=>i.value!==this.defaultSortBy)},resetFilters(e,t=!0){const{currentTarget:i}=e,s=i.href.split("?")[1]??"";t&&(this.render(s),this.close())},loadAccordion(){if(window.innerWidth>=1024)return!1;this.$loadChilds("accordion","/frontend/snippets/accordion/index.ts")},async forceRender4x4View(e){const t=`${w("collections",new URL(window.location.href))}_4x4`;return e&&this.$dispatch(r.mutations.setCartAttributes,{_view_collection:t}),await this.$store.shop.updateAttributes({_view_collection:t},e)},get sections(){var e,t,i;return[{id:(e=document.querySelector(c.collection.grid))==null?void 0:e.id},{id:(t=document.querySelector(c.collection.header))==null?void 0:t.id},{id:(i=document.querySelector(c.collection.facets))==null?void 0:i.id}]},get defaultSortBy(){return this.$root.dataset.sortByDefault}});export{S as data,n as events};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.