import{a as G,b as v,o as H}from"./chunk-ZFWLWLFX.js";import{c as V}from"./chunk-ILFGL2WN.js";import{e as j,h as x}from"./chunk-G3CUAKBR.js";import{a as p,b as T}from"./chunk-XI2EB733.js";import{b as W}from"./chunk-7EAEXLPB.js";import{a as E}from"./chunk-6NIC2JUZ.js";import{a as g,d as k,k as R}from"./chunk-OT4WOJPO.js";import{S as U}from"./chunk-C2EV7IAO.js";import{a as P}from"./chunk-JWAFQ6PQ.js";import{a as F}from"./chunk-XVDG6BQR.js";import{m as q,o as D}from"./chunk-JJTPXY4D.js";import{D as _,s as w,v as i,w as L}from"./chunk-ALDBR463.js";import{Ia as $,K as y,Na as b,V as S,o as h,ya as O}from"./chunk-V6BPA3D7.js";var M=L("recommendation"),u=i(M,t=>t.boughtTogetherState),te=i(u,t=>t.allProducts),se=i(u,t=>t.status),ne=i(u,t=>t.displayedProducts),ae=i(u,t=>t.displayedCount),de=i(u,t=>t.isLoaded),A=i(u,t=>t.productsPrice),X=i(M,t=>t.relatedProductsState),re=i(X,t=>t.products),N=i(X,t=>t.productsPrice),ue=i(re,N,(t,m)=>t?.map(e=>({product:e,price:m?.find(r=>r.id===e.productId)})).filter(e=>e.price)),oe=i(te,A,(t,m)=>t?.map(e=>({product:e,price:m?.find(r=>r.id===e.productId)})).filter(e=>e.price)),me=t=>i(oe,m=>m?.find(e=>e.product.productId===t)),le=i(u,t=>{if(t.status===_.loading||t.error||!t?.displayedProducts||!t?.productsPrice)return;let e=t.displayedProducts?.length>=2,r=t.productsPrice?.length>=2;return e&&r});var $e=(()=>{class t extends E{constructor(e,r){super(),this.store=e,this.storeSelector=r,this.activeTabNotFrequentlyBoughtTogether$=new h,this.destroyedProductPage$=new h}convertProductsToSmallProducts(e){return e.map(r=>({id:r.productId,alt:r.brand+" "+r.title,href:r.href?r.href:"",picture:F.getHrefAndFallbackFromCarousel({carouselPictures:r.carouselPicturesNew,relType:"100x100"})}))}destroyedProductPage(){this.destroyedProductPage$.next(!0),this.destroyedProductPage$.complete()}getProductPrices(e,r){let c=r===v.RelatedProducts?N:A;return this.store.select(c).pipe(S(Boolean),y(n=>n?.find(s=>s.id===e)?.priceVariants))}getRelatedProducts(e,r){let c={msisdn:r||"",productId:e,shouldOffer:!1,type:v.RelatedProducts};this.store.dispatch(H({recommendationsRequest:c}))}isLoggedIn$(){return this.storeSelector.getWithSelector(q)}isPostPaidUser$(){return this.isLoggedIn$().pipe(S(Boolean),O(()=>this.storeSelector.getWithSelector(U)),y(W))}mapRecommendedProductToRecommendedProductTracking(e,r,c,n,s,f){let{product:o,price:d}=e,{installmentPrice:z,acquisitionPrice:J,standardPrice:I}=this.processPriceVariants(d.priceVariants),B=`${o.href?.split("/")[o.href?.split("/").length-1].split("-").join(" ")}`,a=this.getRecommendedProductTrackingInfoBasedOnAvailableSellingOptionsAndUserType(z,J,I,r,c,d),K=a?.displayedPrice?.find(l=>l?.currency===P.EUR)?.value,Q=a?.basePrice?.find(l=>l?.currency===P.EUR)?.value,Y=I?.referenceAmount?.find(l=>l?.currency===P.EUR)?.value,Z=o.stockState===G.OutOfStock?T.outOfStock:T.inStock,ee=s?.item?.stockState===R.InStock||s?.item?.stockState===R.Preorder?"bottom-instock":"middle-outofstock",C=`product-${f}-${s?`${ee}-`:""}${V()}`;return sessionStorage.setItem(o.productCode?.toString()??"0",C),{abonamentAtasat:a?.attachedSubscription,availability:Z,base_price:Number(Q),brand:o.brand?.toLowerCase()??x.brand,category:o.categoryName?.toLowerCase()||x.category,color:o.color.toLowerCase(),file:"related-products.service.ts:167",id:o.productCode?.toString()??"0",img_url:o.imageURL,installments:a?.installmentsPeriod??j,item_name_full:B,list:C,memory:o.hardDisk?.toString()??"",name:B.toLowerCase(),period:a?.transactionType===p.standard?0:24,position:n,price:Number(K),promotion_name:a?.promotionName,retail_price:Number(Y),transactionSubType:a?.transactionSubType,transactionType:a?.transactionType,reviews:null,energy_class:o.energyConsumptionGrade||null}}processPriceVariants(e){let r,c,n;return e?.allPriceVariants?.forEach(s=>{s.discriminator.acquisition===g.Loyalty&&s.discriminator.installment===k.Oro&&(r=this.extractRecommendedPrice(s)),s.discriminator.acquisition===g.Acquisition&&(c=this.extractRecommendedPrice(s))}),n=e?.standardPrice,{installmentPrice:r,acquisitionPrice:c,standardPrice:n}}extractRecommendedPrice(e){return e.items?e.items[0].price:void 0}getRecommendedProductTrackingInfoBasedOnAvailableSellingOptionsAndUserType(e,r,c,n,s,f){if(e?.installmentAmount&&!n||e?.installmentAmount&&n&&s){let o=f.priceVariants?.allPriceVariants?.find(d=>d.discriminator.acquisition===g.Loyalty&&d.discriminator.installment===k.Oro)?.items[0].salePackage;return{basePrice:e.referenceAmount,displayedPrice:e.amount,installmentsPeriod:e?.installmentPeriod||void 0,promotionName:e.discount?.offerName,transactionType:p.installment,attachedSubscription:{base_price:o?.price?.value||0,id:o?.ref||"",name:o?.displayName||"",period:24,price:o?.price?.value||0,discounted_subscription:!1}}}if(!e?.installmentAmount&&!n&&r||!e?.installmentAmount&&r&&n){let o=f.priceVariants?.allPriceVariants?.find(d=>d.discriminator.acquisition===g.Acquisition)?.items[0].salePackage;return{basePrice:r.referenceAmount,displayedPrice:r.amount,promotionName:r.discount?.offerName,transactionSubType:"acquisition_new_package",transactionType:p.acquisition,attachedSubscription:{base_price:o?.price?.value||0,id:o?.ref||"",name:o?.displayName||"",period:24,price:o?.price?.value||0,discounted_subscription:!1}}}if(c&&!e?.installmentAmount&&!r?.amount)return{basePrice:c.referenceAmount,displayedPrice:c?.amount,promotionName:c.discount?.offerName,transactionType:p.standard}}static{this.\u0275fac=function(r){return new(r||t)(b(w),b(D))}}static{this.\u0275prov=$({token:t,factory:t.\u0275fac,providedIn:"root"})}}return t})();export{u as a,te as b,se as c,ne as d,ae as e,de as f,A as g,X as h,re as i,N as j,ue as k,oe as l,me as m,le as n,$e as o};