1import{ch as a,b as w,ci as P,cj as u,bl as V,c as S,i as g,S as R,p as T,r as A,C as E}from"./storefrontApp.DHj_rTVq.min.js";import{S as I}from"./chunk-storefront_base_lit_element.BDgKmPq.js";import{t as _,e as d}from"./chunk-vendor-lit.NvY0u02.js";import{d as f,e as $,i as C,s as N,c as O,w as L}from"./chunk-index.esm.nYUWi4A.js";import{m}from"./chunk-vendor-rxjs.Dp7kflo.js";import"./chunk-vendor-di.Bh23gdA.js";import"./chunk-storefront_settings_constants.DIF02Gz.js";import"./chunk-vendor-lodash.CWHFt7Z.js";import"./chunk-vendor-phoenix.cdKS79L.js";const h="slider__content_with-arrows",y={mobile:`${h}-mobile`,tablet:`${h}-tablet`,laptop:`${h}-laptop`,desktop:`${h}-desktop`};var k=Object.defineProperty,c=(n,e,t,i)=>{for(var s=void 0,r=n.length-1,p;r>=0;r--)(p=n[r])&&(s=p(e,t,s)||s);return s&&k(e,t,s),s};class o extends I{constructor(){super(),this._recentlyViewedProductsTemplate=void 0,this._productsVisible=0,this._$sliderParent=null,this.currentProductId="",this.containerId="",this.productsToShow=16,this.productsPerPageDesktop=4,this.productsPerPageLaptop=3,this.productsPerPageTablet=3,this.productsPerPageMobile=1,this._updateSliderContentArrows=()=>{const e=this._$sliderParent?.querySelector(".slider__content");if(!this._$sliderParent||!e)return;const t=this._productsVisible>this.productsPerPageDesktop,i=this._productsVisible>this.productsPerPageLaptop,s=this._productsVisible>this.productsPerPageTablet,r=this._productsVisible>this.productsPerPageMobile;this._$sliderParent.sliderSettings={...this._$sliderParent.sliderSettings,arrows:t,type:this._productsVisible>this.productsPerPageDesktop?"loop":"slide",breakpoints:{...this._$sliderParent.sliderSettings.breakpoints,1440:{...this._$sliderParent.sliderSettings.breakpoints?.[1440]??{},arrows:i,type:this._productsVisible>this.productsPerPageLaptop?"loop":"slide"},1e3:{...this._$sliderParent.sliderSettings.breakpoints?.[1e3]??{},arrows:s,type:this._productsVisible>this.productsPerPageTablet?"loop":"slide"},576:{...this._$sliderParent.sliderSettings.breakpoints?.[576]??{},arrows:r,type:this._productsVisible>this.productsPerPageMobile?"loop":"slide"}}},[{className:y.desktop,active:t},{className:y.laptop,active:i},{className:y.tablet,active:s},{className:y.mobile,active:r}].forEach(({className:l,active:b})=>{e.classList.toggle(l,b)})},this._setupCalculateVisibleProductsSubscription=()=>{this._recentlyViewedApi&&(this._productsVisibleSubscription=this._recentlyViewedApi.selectRecentlyViewedProducts$(this.currentProductId).subscribe(e=>{const t=e.length;this._productsVisible=this.productsToShow>t?t:this.productsToShow}))},this._recentlyViewedApi=this.getApiSync(a.api)}static{this.moduleName=a.component}connectedCallback(){super.connectedCallback(),this._$sliderParent=this.closest("h-slider"),this._createTemplate(),this._setupCalculateVisibleProductsSubscription(),this._updateRecentlyViewedVisibility()}updated(e){super.updated(e),e.has("_productsVisible")&&this._updateSliderContentArrows()}disconnectedCallback(){super.disconnectedCallback(),this._recentlyViewedProductSubscription?.unsubscribe(),this._productsVisibleSubscription?.unsubscribe()}_updateRecentlyViewedVisibility(){const e=document.getElementById(this.containerId);if(!e)return;const t=this._recentlyViewedApi.getAllRecentlyViewedItems(),i=t.length===1&&t.some(({id:s})=>s===`product_${this.currentProductId}`);e.hidden=t.length===0||i}_createTemplate(){this._recentlyViewedApi&&(this._recentlyViewedProductSubscription=this._recentlyViewedApi.selectRecentlyViewedProducts$(this.currentProductId).subscribe(e=>{this._recentlyViewedProductsTemplate=e.slice(0,this.productsToShow).reduce((t,i)=>t+i,"")}))}render(){this.parentNode&&(this.outerHTML=this._recentlyViewedProductsTemplate||"",this._handleSliderRefresh())}_handleSliderRefresh(){this._destroyStalePagination(),this._$sliderParent?.getSlider()?.refresh()}_destroyStalePagination(){const e=this._$sliderParent?.getSlider()?.Components?.Pagination;e?.destroy&&e.destroy()}}c([_()],o.prototype,"_recentlyViewedProductsTemplate");c([_()],o.prototype,"_productsVisible");c([d({type:String,attribute:"current-product-id"})],o.prototype,"currentProductId");c([d({type:String,attribute:"container-id"})],o.prototype,"containerId");c([d({type:Number,attribute:"products-to-show"})],o.prototype,"productsToShow");c([d({type:Number,attribute:"products-per-page-desktop"})],o.prototype,"productsPerPageDesktop");c([d({type:Number,attribute:"products-per-page-laptop"})],o.prototype,"productsPerPageLaptop");c([d({type:Number,attribute:"products-per-page-tablet"})],o.prototype,"productsPerPageTablet");c([d({type:Number,attribute:"products-per-page-mobile"})],o.prototype,"productsPerPageMobile");class v{#e;constructor({recentlyViewedStore:e}){this.#e=e}deleteRecentlyViewedItem(e){this.#e.update(f(e))}selectRecentlyViewed$(){return this.#e.pipe(m(e=>e))}addRecentlyViewedItem(e){this.#e.update($([e],{prepend:!0}))}getRecentlyViewedItem(e){return this.#e.query(C(e))}selectAllRecentlyViewedItems$(){return this.#e.pipe(N())}setRecentlyViewedItems(e){this.#e.update(O(e))}getAllRecentlyViewedItems(){return Object.values(this.#e.getValue().entities)}}class M extends w{constructor({recentlyViewedRepository:e,storeFactoryApi:t}){super(),this._addTemplateIfOnProductPage=()=>{const i=document.querySelector(`#${P}`);if(!i)return;const s=i.getAttribute("product-id"),r=i.innerHTML;s&&this.addTemplateToRecentlyViewed(s,r)},this._getRecentlyViewedStore=()=>(this.#t=this.#s.getStore(u),this.#t?this.#t:this.#s.createStore("local",u)),this._initializeProductTemplates=()=>{const s=this._getRecentlyViewedStore().getObject(u);if(!s)return;const r=this._sortEntities(Object.values(s.entities),s.ids);r&&this.#e.setRecentlyViewedItems(r)},this._setupStoreSubscription=()=>{this.#i=this.#e.selectRecentlyViewed$().subscribe(i=>{this._getRecentlyViewedStore().setObject(u,i)})},this._mapEntitiesToTemplates=(i,s)=>i.filter(l=>l.id!==`product_${s}`).map(l=>l.template),this.#e=e,this.#s=t,this._initializeProductTemplates(),this._setupStoreSubscription(),new V(()=>{this._addTemplateIfOnProductPage()})}#e;#i;#t;#s;_sortEntities(e,t){return e.sort((i,s)=>t.indexOf(i.id)-t.indexOf(s.id))}_removeProductIfExists(e){this.#e.getRecentlyViewedItem(e)&&this.#e.deleteRecentlyViewedItem(e)}dispose(){super.dispose(),this.#i?.unsubscribe()}addTemplateToRecentlyViewed(e,t){const i=`product_${e}`;this._removeProductIfExists(i),this.#e.addRecentlyViewedItem({id:i,template:t})}selectProductTemplates$(e){return this.#e.selectAllRecentlyViewedItems$().pipe(m(t=>this._mapEntitiesToTemplates(t,e)))}getAllRecentlyViewedItems(){return this.#e.getAllRecentlyViewedItems()}}const x=()=>S({name:a.store},L({idKey:"id"}));class D extends g{constructor(e){super(),this.moduleName=a.api,this.#e=e}#e;selectRecentlyViewedProducts$(e){return this.#e.selectProductTemplates$(e)}addTemplateToRecentlyViewed(e,t){return this.#e.addTemplateToRecentlyViewed(e,t)}getAllRecentlyViewedItems(){return this.#e.getAllRecentlyViewedItems()}}class G extends R{static{this.featureName=a.feature}init(){const e=x(),t=new v({recentlyViewedStore:e}),i=this.getApiSync(T),s=new M({recentlyViewedRepository:t,storeFactoryApi:i}),r=new D(s);return{cores:[{type:A.api,instance:[r]},{type:E,instance:[o]}]}}}export{G as RecentlyViewedInitializer};
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.