import{a as St,b as q,o as bt}from"./chunk-LHNDRZIN.js";import{c as yt}from"./chunk-OQN66XSO.js";import{e as ft,h as j}from"./chunk-VDGDDK32.js";import{a as T,b as D}from"./chunk-XI2EB733.js";import{b as lt}from"./chunk-2W5T35U6.js";import{a as mt}from"./chunk-Y77T26QU.js";import{a as x,d as E,k as U}from"./chunk-RTZH3MOC.js";import{S as ht}from"./chunk-YFWLORNM.js";import{a as $}from"./chunk-JWAFQ6PQ.js";import{a as gt}from"./chunk-G22GDL5B.js";import{m as dt,o as pt}from"./chunk-DAYGRJHR.js";import{D as nt,s as ct,v as a,w as at}from"./chunk-VYUKN3XQ.js";import{Da as it,Na as ut,P as L,Sa as _,_ as k,t as w}from"./chunk-XNQ3RS5P.js";var Tt=at("recommendation"),l=a(Tt,e=>e.boughtTogetherState),Rt=a(l,e=>e.allProducts),Ct=a(l,e=>e.status),Ot=a(l,e=>e.displayedProducts),$t=a(l,e=>e.displayedCount),wt=a(l,e=>e.isLoaded),F=a(l,e=>e.productsPrice),xt=a(Tt,e=>e.relatedProductsState),At=a(xt,e=>e.products),W=a(xt,e=>e.productsPrice),Lt=a(At,W,(e,i)=>e==null?void 0:e.map(n=>({product:n,price:i==null?void 0:i.find(t=>t.id===n.productId)})).filter(n=>n.price)),vt=a(Rt,F,(e,i)=>e==null?void 0:e.map(n=>({product:n,price:i==null?void 0:i.find(t=>t.id===n.productId)})).filter(n=>n.price)),kt=e=>a(vt,i=>i==null?void 0:i.find(n=>n.product.productId===e)),_t=a(l,e=>{var o,u;if(e.status===nt.loading||e.error||!(e!=null&&e.displayedProducts)||!(e!=null&&e.productsPrice))return;let n=((o=e.displayedProducts)==null?void 0:o.length)>=2,t=((u=e.productsPrice)==null?void 0:u.length)>=2;return n&&t});var Vt=(()=>{let i=class i extends mt{constructor(t,o){super(),this.store=t,this.storeSelector=o,this.activeTabNotFrequentlyBoughtTogether$=new w,this.destroyedProductPage$=new w}convertProductsToSmallProducts(t){return t.map(o=>({id:o.productId,alt:o.brand+" "+o.title,href:o.href?o.href:"",picture:gt.getHrefAndFallbackFromCarousel({carouselPictures:o.carouselPicturesNew,relType:"100x100"})}))}destroyedProductPage(){this.destroyedProductPage$.next(!0),this.destroyedProductPage$.complete()}getProductPrices(t,o){let u=o===q.RelatedProducts?W:F;return this.store.select(u).pipe(k(Boolean),L(d=>{var c;return(c=d==null?void 0:d.find(m=>m.id===t))==null?void 0:c.priceVariants}))}getRelatedProducts(t,o){let u={msisdn:o||"",productId:t,shouldOffer:!1,type:q.RelatedProducts};this.store.dispatch(bt({recommendationsRequest:u}))}isLoggedIn$(){return this.storeSelector.getWithSelector(dt)}isPostPaidUser$(){return this.isLoggedIn$().pipe(k(Boolean),it(()=>this.storeSelector.getWithSelector(ht)),L(lt))}mapRecommendedProductToRecommendedProductTracking(t,o,u,d,c,m){var r,g,P,H,I,M,X,z,G,J,K,Q,Y,Z,V,tt,et,ot,rt,st;let{product:p,price:y}=t,{installmentPrice:R,acquisitionPrice:A,standardPrice:f}=this.processPriceVariants(y.priceVariants),S="".concat((g=p.href)==null?void 0:g.split("/")[((r=p.href)==null?void 0:r.split("/").length)-1].split("-").join(" ")),s=this.getRecommendedProductTrackingInfoBasedOnAvailableSellingOptionsAndUserType(R,A,f,o,u,y),v=(H=(P=s==null?void 0:s.displayedPrice)==null?void 0:P.find(h=>(h==null?void 0:h.currency)===$.EUR))==null?void 0:H.value,N=(M=(I=s==null?void 0:s.basePrice)==null?void 0:I.find(h=>(h==null?void 0:h.currency)===$.EUR))==null?void 0:M.value,B=(z=(X=f==null?void 0:f.referenceAmount)==null?void 0:X.find(h=>(h==null?void 0:h.currency)===$.EUR))==null?void 0:z.value,C=p.stockState===St.OutOfStock?D.outOfStock:D.inStock,O=((G=c==null?void 0:c.item)==null?void 0:G.stockState)===U.InStock||((J=c==null?void 0:c.item)==null?void 0:J.stockState)===U.Preorder?"bottom-instock":"middle-outofstock",b="product-".concat(m,"-").concat(c?"".concat(O,"-"):"").concat(yt());return sessionStorage.setItem((Q=(K=p.productCode)==null?void 0:K.toString())!=null?Q:"0",b),{abonamentAtasat:s==null?void 0:s.attachedSubscription,availability:C,base_price:Number(N),brand:(Z=(Y=p.brand)==null?void 0:Y.toLowerCase())!=null?Z:j.brand,category:((V=p.categoryName)==null?void 0:V.toLowerCase())||j.category,color:p.color.toLowerCase(),file:"related-products.service.ts:167",id:(et=(tt=p.productCode)==null?void 0:tt.toString())!=null?et:"0",img_url:p.imageURL,installments:(ot=s==null?void 0:s.installmentsPeriod)!=null?ot:ft,item_name_full:S,list:b,memory:(st=(rt=p.hardDisk)==null?void 0:rt.toString())!=null?st:"",name:S.toLowerCase(),period:(s==null?void 0:s.transactionType)===T.standard?0:24,position:d,price:Number(v),promotion_name:s==null?void 0:s.promotionName,retail_price:Number(B),transactionSubType:s==null?void 0:s.transactionSubType,transactionType:s==null?void 0:s.transactionType,reviews:null}}processPriceVariants(t){var c;let o,u,d;return(c=t==null?void 0:t.allPriceVariants)==null||c.forEach(m=>{m.discriminator.acquisition===x.Loyalty&&m.discriminator.installment===E.Oro&&(o=this.extractRecommendedPrice(m)),m.discriminator.acquisition===x.Acquisition&&(u=this.extractRecommendedPrice(m))}),d=t==null?void 0:t.standardPrice,{installmentPrice:o,acquisitionPrice:u,standardPrice:d}}extractRecommendedPrice(t){return t.items?t.items[0].price:void 0}getRecommendedProductTrackingInfoBasedOnAvailableSellingOptionsAndUserType(t,o,u,d,c,m){var p,y,R,A,f,S,s,v,N,B,C,O,b;if(t!=null&&t.installmentAmount&&!d||t!=null&&t.installmentAmount&&d&&c){let r=(R=(y=(p=m.priceVariants)==null?void 0:p.allPriceVariants)==null?void 0:y.find(g=>g.discriminator.acquisition===x.Loyalty&&g.discriminator.installment===E.Oro))==null?void 0:R.items[0].salePackage;return{basePrice:t.referenceAmount,displayedPrice:t.amount,installmentsPeriod:(t==null?void 0:t.installmentPeriod)||void 0,promotionName:(A=t.discount)==null?void 0:A.offerName,transactionType:T.installment,attachedSubscription:{base_price:((f=r==null?void 0:r.price)==null?void 0:f.value)||0,id:(r==null?void 0:r.ref)||"",name:(r==null?void 0:r.displayName)||"",period:24,price:((S=r==null?void 0:r.price)==null?void 0:S.value)||0,discounted_subscription:!1}}}if(!(t!=null&&t.installmentAmount)&&!d&&o||!(t!=null&&t.installmentAmount)&&o&&d){let r=(N=(v=(s=m.priceVariants)==null?void 0:s.allPriceVariants)==null?void 0:v.find(g=>g.discriminator.acquisition===x.Acquisition))==null?void 0:N.items[0].salePackage;return{basePrice:o.referenceAmount,displayedPrice:o.amount,promotionName:(B=o.discount)==null?void 0:B.offerName,transactionSubType:"acquisition_new_package",transactionType:T.acquisition,attachedSubscription:{base_price:((C=r==null?void 0:r.price)==null?void 0:C.value)||0,id:(r==null?void 0:r.ref)||"",name:(r==null?void 0:r.displayName)||"",period:24,price:((O=r==null?void 0:r.price)==null?void 0:O.value)||0,discounted_subscription:!1}}}if(u&&!(t!=null&&t.installmentAmount)&&!(o!=null&&o.amount))return{basePrice:u.referenceAmount,displayedPrice:u==null?void 0:u.amount,promotionName:(b=u.discount)==null?void 0:b.offerName,transactionType:T.standard}}};i.\u0275fac=function(o){return new(o||i)(_(ct),_(pt))},i.\u0275prov=ut({token:i,factory:i.\u0275fac,providedIn:"root"});let e=i;return e})();export{l as a,Rt as b,Ct as c,Ot as d,$t as e,wt as f,F as g,xt as h,At as i,W as j,Lt as k,vt as l,kt as m,_t as n,Vt as o};