1import{a as $}from"./BaseElement.T5rcpVrk.min.js";import{b as M}from"./bloomreach-category-context.DChcsJfA.min.js";import{r as U}from"./bloomreach-default-sort-options.bXhQqII0.min.js";import{p as L,a as x}from"./bloomreach-sort-url.BsMNXSWI.min.js";import{g as O}from"./money-helper.CJ2CLSOB.min.js";import{g as R,b as A,n as I}from"./utils.C9euZx3E.min.js";import{L as N}from"./LiveRegionUtility.44lKd9Yx.min.js";import{x as Q,j as q}from"./index.IEUEv3yy.min.js";import{i as T}from"./context-provider.B4rs2v8g.min.js";import{b as V}from"./lit-element.Ck2-kYtD.min.js";import"./create-context.89xeped_.min.js";import"./aria-live-region-context.BZEtRCSs.min.js";import"./context-request-event.GdmzvDV-.min.js";const D=class D extends ${constructor(){super(),this._originalPriceRangesMap={},this._originalFacetRangesMap={},this._allProductsMap={},this._lastBroadcastSignature=null,this._initialAutoLoadFromUrlInProgress=!1,this.categoryId="",this.productsPerPage=20,this.autoLoad=!0,this.navigationType="pagination",this.currencySymbol="",this.defaultSort="",this._$liveRegionUtility=new N(this),this._bloomreachConfig=null,this._categoryData={categoryId:"",products:[],isLoading:!1,totalProducts:0,currentPage:1,hasNextPage:!1,error:null,currentSort:"",collectionDefaultSort:"",searchQuery:"",currentFilters:{},facets:[],productsPerPage:this.productsPerPage,loadProducts:this.loadProducts.bind(this),loadNextPage:this.loadNextPage.bind(this),setFilters:this.setFilters.bind(this),togglePriceFilter:this.togglePriceFilter.bind(this),setSorting:this.setSorting.bind(this),search:this.search.bind(this),clearFilters:this.clearFilters.bind(this),getAllProducts:this.getAllProducts.bind(this)},this._contextProvider=new T(this,{context:M,initialValue:this._categoryData}),this._loadFacetRangeCache(),this.initializeBloomreach()}_formatMoney(e){return`${(this.currencySymbol||"").trim()||O()}${e}`}_loadFacetRangeCache(){try{const e=sessionStorage.getItem(D._FACET_RANGE_CACHE_STORAGE_KEY);if(!e)return;const t=JSON.parse(e);t&&typeof t=="object"&&(this._originalFacetRangesMap=t)}catch(e){console.error(e)}}_persistFacetRangeCache(){try{sessionStorage.setItem(D._FACET_RANGE_CACHE_STORAGE_KEY,JSON.stringify(this._originalFacetRangesMap))}catch(e){console.error(e)}}async initializeBloomreach(){var r,s,a;const e=(r=window.bloomreachConfig)==null?void 0:r.accountId,t=(s=window.bloomreachConfig)==null?void 0:s.domainKey;if(!e||!t){console.warn("Bloomreach configuration missing");return}this._bloomreachConfig={account_id:parseInt(e),domain_key:t,searchEndpoint:((a=window.bloomreachConfig)==null?void 0:a.environment)==="staging"?"https://staging-core.dxpapi.com/api/v1/core/":"https://core.dxpapi.com/api/v1/core/"}}connectedCallback(){super.connectedCallback(),this._syncCollectionDefaultSort(),this._syncSortFromCurrentUrl(),this._autoLoadOnConnect(),this.addEventListener("price-filter-toggle",e=>{const t=e,{value:r}=t.detail;this.togglePriceFilter(r)}),this.addEventListener("range-change",e=>{var a,o;const t=e,{name:r,value:s}=t.detail;(o=(a=window.Shopify)==null?void 0:a.analytics)!=null&&o.publish&&window.Shopify.analytics.publish("bloomreach:filter-state-change",{href:window.location.href}),this.rangeChangeFilter(r,s)})}_syncSortFromCurrentUrl(){this._categoryData.currentSort=L(new URLSearchParams(window.location.search),this._categoryData.collectionDefaultSort)}async _autoLoadOnConnect(){this.autoLoad&&(this._initialAutoLoadFromUrlInProgress=!0);try{if(await this.initializeBloomreach(),!this.autoLoad)return;const e=new URLSearchParams(window.location.search),t=(e.get("q")||"").trim(),r=e.get("page"),s=r?Math.max(1,parseInt(r,10)):1;this._syncSortFromCurrentUrl();const a=this._categoryData.currentSort;if(t.length>0){this.loadProducts(this.categoryId||"",{page:s,searchQuery:t,sort:a});return}this.categoryId&&this.loadProducts(this.categoryId,{page:s,sort:a})}catch{this.categoryId&&(this._syncSortFromCurrentUrl(),this.loadProducts(this.categoryId,{sort:this._categoryData.currentSort}))}finally{this._initialAutoLoadFromUrlInProgress=!1}}updated(e){if(super.updated(e),e.has("productsPerPage")&&this._categoryData&&(this._categoryData.productsPerPage=this.productsPerPage,this._updateContext()),e.has("defaultSort")){this._syncCollectionDefaultSort(),this._syncSortFromCurrentUrl();const t=new URLSearchParams(window.location.search).has("sort");this.autoLoad&&this.categoryId&&!this._initialAutoLoadFromUrlInProgress&&!t&&this._categoryData.collectionDefaultSort&&this.loadProducts(this.categoryId,{sort:this._categoryData.currentSort})}e.has("categoryId")&&this.autoLoad&&this.categoryId&&(this._initialAutoLoadFromUrlInProgress||(this._syncSortFromCurrentUrl(),this.loadProducts(this.categoryId,{sort:this._categoryData.currentSort})))}_syncCollectionDefaultSort(){this._categoryData.collectionDefaultSort=U(this.defaultSort)}_resolveSortForLoad(e={}){return e.sort!==void 0?e.sort:L(new URLSearchParams(window.location.search),this._categoryData.collectionDefaultSort)}async loadProducts(e,t={}){if(this._categoryData.categoryId=e,!this._bloomreachConfig){this._updateError("Bloomreach not configured");return}this._updateLoading(!0),this._syncCollectionDefaultSort(),this._categoryData.searchQuery=typeof t.searchQuery=="string"?t.searchQuery.trim():"";const r=this._resolveSortForLoad(t);this._categoryData.currentSort=r,t.filters||(t.filters=this._parseFiltersFromURL()),this._categoryData.currentFilters=t.filters;try{let s;if(t.searchQuery){const a=t.filters?this._buildFilterParams(t.filters):{},o=[];Array.isArray(a.fq)&&o.push(...a.fq),e&&o.push(`category:"${e}"`);const i={q:t.searchQuery,url:window.location.href,ref_url:window.getPreviousUrl(
1),_br_uid_2:R(),rows:t.rows||this.productsPerPage,start:((t.page||1)-1)*(t.rows||this.productsPerPage),fl:["pid","title","description","brand","price","sale_price","url","thumb_image","inStock","onSale","category_ids","tags"].join(","),"facet.version":"3.0",...r&&{sort:r},...o.length>0&&{fq:o}};try{s=await Q(t.searchQuery,this._bloomreachConfig,i)}catch(l){throw console.error("Product search API error:",l),new Error(`Product search failed: ${l instanceof Error?l.message:"Unknown API error"}`)}}else{const a={q:e,url:window.location.href,ref_url:window.getPreviousUrl(),_br_uid_2:R(),rows:t.rows||this.productsPerPage,start:((t.page||1)-1)*(t.rows||this.productsPerPage),fl:["pid","title","description","brand","price","sale_price","url","thumb_image","inStock","onSale","category_ids","tags"].join(","),"facet.version":"3.0",...r&&{sort:r},...t.filters&&{fq:this._buildFilterParams(t.filters).fq}};try{s=await q(e,this._bloomreachConfig,a)}catch(o){throw console.error("Category search API error:",o),new Error(`Category search failed: ${o instanceof Error?o.message:"Unknown API error"}`)}}this._processCategoryResponse(s,t.page||1,t),this._updateLoading(!1)}catch(s){console.error("Category search error:",s),this._updateError("Failed to load category products"),this._updateLoading(!1)}}async loadNextPage(){if(!(!this._categoryData.hasNextPage||this._categoryData.isLoading)){this._updateLoading(!0);try{await this.loadProducts(this._categoryData.categoryId,{page:this._categoryData.currentPage+1,rows:this.productsPerPage,searchQuery:this._categoryData.searchQuery,sort:this._categoryData.currentSort,filters:this._categoryData.currentFilters,append:!0})}finally{this._updateLoading(!1)}}}setFilters(e){const t=e&&typeof e=="object"?e:{},r={};Object.entries(t).forEach(([s,a])=>{(Array.isArray(a)&&a.length>0||a&&!Array.isArray(a))&&(r[s]=a)}),this._categoryData.currentFilters=r,this._updateURLWithFilters(r),this.loadProducts(this._categoryData.categoryId,{page:1,filters:r,searchQuery:this._categoryData.searchQuery,sort:this._categoryData.currentSort})}togglePriceFilter(e){const t=this._categoryData.currentFilters.price||[];let r;t.includes(e)?r=[]:r=[e],this.setFilters({...this._categoryData.currentFilters,price:r})}rangeChangeFilter(e,t){e&&this.setFilters({...this._categoryData.currentFilters,[e]:t})}setSorting(e){this._categoryData.currentSort=e,this._applySortToUrl(e),this.loadProducts(this._categoryData.categoryId,{page:1,sort:e,searchQuery:this._categoryData.searchQuery})}_applySortToUrl(e){const t=new URL(window.location.href);t.searchParams.delete("page"),x(t.searchParams,e,this._categoryData.collectionDefaultSort),window.history.replaceState({},"",t.toString())}async search(e){const t=e.trim();this._categoryData.searchQuery=t,this._updateURLWithSearchQuery(t),t?this.loadProducts(this._categoryData.categoryId,{page:1,searchQuery:t,sort:this._categoryData.currentSort}):this.loadProducts(this._categoryData.categoryId,{page:1,sort:this._categoryData.currentSort})}clearFilters(){this._categoryData.currentFilters={},this.loadProducts(this._categoryData.categoryId,{page:1,searchQuery:this._categoryData.searchQuery,sort:this._categoryData.currentSort})}getAllProducts(){return this._allProductsMap[this._categoryData.categoryId]||[]}_processCategoryResponse(e,t,r){var n;if(e!=null&&e.keywordRedirect){const c=e==null?void 0:e.keywordRedirect["redirected url"];if(c){window.location.href=c;return}}const s=(e==null?void 0:e.response)||{},a=s.docs||[],o=s.numFound||0,i=((n=e==null?void 0:e.facet_counts)==null?void 0:n.facets)||[],l=(r==null?void 0:r.append)===!0,u=a==null?void 0:a.map((c,y)=>{const p=c.pid||c.url||this._extractHandle(c)||`fallback-${t}-${y}`;return{pid:p,title:c.title||"",handle:this._extractHandle(c)||p,thumb_image:c.thumb_image||"",url:c.url||"",price:c.price||0,sale_price:c.sale_price||c.price||0,tags:c.tags||[]}});if(l?t===1?this._allProductsMap[this._categoryData.categoryId]=u:(this._allProductsMap[this._categoryData.categoryId]||(this._allProductsMap[this._categoryData.categoryId]=[]),this._allProductsMap[this._categoryData.categoryId].push(...u)):this._allProductsMap[this._categoryData.categoryId]=u,(t===1||this._categoryData.facets.length===0)&&(this._categoryData.facets=this._processFacets(i),!this._originalPriceRangesMap[this._categoryData.categoryId]&&u.length>0&&Object.keys(this._categoryData.currentFilters).length===0&&t===1&&u.map(y=>y.price).filter(y=>y>0).length>0&&(this._originalPriceRangesMap[this._categoryData.categoryId]=this._generatePriceRangesFromProducts(u))),l){if(t===1)this._categoryData.products=u,this._allProductsMap[this._categoryData.categoryId]=u;else{const y=[...this._categoryData.products,...u],p=new Set;this._categoryData.products=y.filter(F=>p.has(F.pid)?!1:(p.add(F.pid),!0)),this._allProductsMap[this._categoryData.categoryId]=[...this._allProductsMap[this._categoryData.categoryId],...u]}this._categoryData.currentPage=t,this._categoryData.totalProducts=o;const c=(r==null?void 0:r.rows)||this.productsPerPage;this._categoryData.hasNextPage=t*c<o,this._categoryData.facets.length===0&&i&&(this._categoryData.facets=this._processFacets(i)),this._updateContext();return}else this._categoryData.products=u,this._allProductsMap[this._categoryData.categoryId]=u,this._categoryData.currentPage=t;this._categoryData.totalProducts=o;const g=(r==null?void 0:r.rows)||this.productsPerPage;this._categoryData.hasNextPage=t*g<o,this._categoryData.error=null,this._updateContext()}_extractHandle(e){if(e.pid)return e.pid;if(e.url){const t=e.url.split("/");return t[t.length-1]||""}return""}
1_processFacets(e){const t=[];return e.forEach(r=>{var p,F;const s=r.name||r.field,a=r.type,o=(p=r.value)==null?void 0:p.start,i=(F=r.value)==null?void 0:F.end,l=r.value||r.values||[];if(s.toLowerCase().includes("price")&&a==="text"||a==="number_stats"&&(o==null||i==null)||a!=="number_stats"&&(!l||l.length===0))return;if(a==="number_range"){const h=Array.isArray(l)?l.filter(d=>((d==null?void 0:d.count)||0)>0).map(d=>{const _=d==null?void 0:d.start,m=d==null?void 0:d.end,S=_==="*"?0:Number(_),b=m==="*"?"":Number(m),P=Number.isFinite(S)?S:0,w=b===""?"":Number.isFinite(b)?b:"",E=w===""?`${this._formatMoney(P)}+`:`${this._formatMoney(P)}-${this._formatMoney(w)}`;return{value:`[${_} TO ${m}]`,label:E,count:(d==null?void 0:d.count)||0,min:P,max:w===""?void 0:w}}):[];if(h.length===0)return;const f=this._categoryData.currentFilters[s]||[];t.push({name:s,label:this._getLabelForFacet(s),type:"number_range",options:h,selectedValues:Array.isArray(f)?f:[f]});return}const g=Array.isArray(l)?l.map(h=>{let f=h.cat_id||h.name||h.value,d=h.cat_name||h.name||h.value;if(!f&&(h.start!==void 0||h.end!==void 0)){const _=h.start??0,m=h.end??0;f=`${_},${m}`,d=`${this._formatMoney(_)} - ${this._formatMoney(m)}`}return{value:f,label:d,count:h.count||0,image:h.image||void 0}}):[],n=this._categoryData.currentFilters[s]||[];let c,y;if(a==="number_stats"&&typeof n=="string"&&([c,y]=n.split(",")),a==="number_stats"&&Array.isArray(n)&&typeof n[0]=="string"){const h=n[0];h.includes(" TO ")?[c,y]=h.replace("[","").replace("]","").split(" TO "):h.includes(",")&&([c,y]=h.split(","))}if(a==="number_stats"){const h=`${this._categoryData.categoryId}:${s}`,f=Number(c),d=Number(y),_=this._originalFacetRangesMap[h];if(!_)this._originalFacetRangesMap[h]={min:Number.isFinite(f)?Math.min(o,f):o,max:Number.isFinite(d)?Math.max(i,d):i},this._persistFacetRangeCache();else{let P=!1;_.max<i&&(_.max=i,P=!0),_.min>o&&(_.min=o,P=!0),Number.isFinite(d)&&_.max<d&&(_.max=d,P=!0),Number.isFinite(f)&&_.min>f&&(_.min=f,P=!0),P&&this._persistFacetRangeCache()}const m=this._originalFacetRangesMap[h],S=(m==null?void 0:m.min)??o,b=(m==null?void 0:m.max)??i;t.push({name:s,label:this._getLabelForFacet(s),type:"number_stats",rangeMin:S,rangeMax:b,rangeSelectedMin:Number.isFinite(f)?f:S,rangeSelectedMax:Number.isFinite(d)?d:b});return}t.push({name:s,label:this._getLabelForFacet(s),type:a,options:g,selectedValues:Array.isArray(n)?n:[n]})}),t}_getLabelForFacet(e){return{category:"Category",color:"Color",sizes:"Sizes",price:"Price",brand:"Brand",gender:"Gender"}[e]||this._capitalizeFirst(e)}_capitalizeFirst(e){return e.charAt(0).toUpperCase()+e.slice(1).replace(/_/g," ")}_generatePriceRangesFromProducts(e){if(e.length===0)return[];const t=e.map(g=>g.price).filter(g=>g>0).sort((g,n)=>g-n);if(t.length===0)return[];const r=Math.floor(t[0]),s=Math.ceil(t[t.length-1]),a=s-r,o=Array.from(new Set(t));let i=Math.floor(o.length/10);i=Math.max(3,Math.min(6,i));const l=Math.ceil(a/i),u=[];for(let g=0;g<i;g++){const n=r+g*l,c=g===i-1?s:n+l-1,y=e.filter(F=>{const h=F.price||0;return h>=n&&h<=c}).length;if(y===0)continue;const p=`${this._formatMoney(n)} - ${this._formatMoney(c)}`;u.push({value:`${n},${c}`,label:p,count:y,min:n,max:c})}return u}_parseFiltersFromURL(){const e=new URLSearchParams(window.location.search),t={},r=e.get("fq");return r&&r.split(",").forEach(a=>{if(a.includes(":")){const o=a.indexOf(":"),i=A(a.substring(0,o)),l=A(a.substring(o+1));if(i&&l){const u=i.toLowerCase().includes("price"),g=l.match(/^\[\s*([-0-9.*]+)\s+TO\s+([-0-9.*]+)\s*\]$/);if(g){const[,n,c]=g;u?(t[i]||(t[i]=[]),t[i].push(`[${n} TO ${c}]`)):t[i]=`${n},${c}`;return}if(u){const n=I(l);if(!n)return;t[i]||(t[i]=[]),t[i].push(n)}else t[i]||(t[i]=[]),t[i].push(l)}}}),t}_updateURLWithFilters(e){const t=new URL(window.location.href),r=t.searchParams;r.delete("fq");const s=[];Object.entries(e).forEach(([a,o])=>{Array.isArray(o)&&o.length>0?o.forEach(i=>{s.push(`${a}:${encodeURIComponent(i)}`)}):typeof o=="string"&&s.push(`${a}:${encodeURIComponent(o)}`)}),s.length>0?r.set("fq",s.join(",")):r.delete("fq"),window.history.replaceState({},"",t.toString())}_updateURLWithSearchQuery(e){const t=new URL(window.location.href),r=e.trim();r?t.searchParams.set("q",r):t.searchParams.delete("q"),t.searchParams.delete("page"),window.history.replaceState({},"",t.toString())}_buildFilterParams(e){const t={},r=[];return Object.entries(e).forEach(([s,a])=>{if(s.toLowerCase().includes("price"))(Array.isArray(a)?a:[a]).forEac
1h(l=>{if(!l||typeof l!="string")return;const u=I(l);u&&r.push(`${s}:${u}`)});else{const[i,l]=typeof a=="string"?a.split(","):[];let u=a;if(Array.isArray(a)){const g=a.filter(n=>/^\d+(\.\d+)?,\d+(\.\d+)?$/.test(n));if(g.length>0){g.forEach(c=>{const[y,p]=c.split(",");r.push(`${s}:[${y} TO ${p}]`)});const n=a.filter(c=>!/^\d+(\.\d+)?,\d+(\.\d+)?$/.test(c));n.length>0&&r.push(`${s}:"${n.join('" OR "')}"`);return}u=`"${a.join('" OR "')}"`}else i&&l&&(u=`[${i} TO ${l}]`);r.push(`${s}:${u}`)}}),r.length>0&&(t.fq=r),t}_updateLoading(e){this._categoryData.isLoading=e,this._updateContext(),e&&this._$liveRegionUtility.announce({message:"Loading..."})}_updateError(e){this._categoryData.error=e,this._updateContext(),this._$liveRegionUtility.announce({message:e})}_updateContext(){this._contextProvider.setValue(this._categoryData,!0),this.requestUpdate();try{const e={totalProducts:this._categoryData.totalProducts,searchQuery:this._categoryData.searchQuery,currentPage:this._categoryData.currentPage,productsPerPage:this._categoryData.productsPerPage,isLoading:this._categoryData.isLoading},t=JSON.stringify(e);if(this._lastBroadcastSignature===t)return;this._lastBroadcastSignature=t,window.__BLOOMREACH_CATEGORY__=e,window.dispatchEvent(new CustomEvent("bloomreach:category:update",{detail:e}))}catch{}}render(){return V`<slot></slot>`}};D._FACET_RANGE_CACHE_STORAGE_KEY="bloomreach:facetRangeCache:v1",D.properties={categoryId:{type:String,attribute:"category-id"},productsPerPage:{type:Number,attribute:"products-per-page"},autoLoad:{type:Boolean,attribute:"auto-load"},navigationType:{type:String,attribute:"navigation-type"},currencySymbol:{type:String,attribute:"data-currency-symbol"},defaultSort:{type:String,attribute:"default-sort"}};let C=D;window.customElements.define("bloomreach-category-provider",C);
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.