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