import{a as D}from"./chunk-LXG7GT7J.js";import{a as I}from"./chunk-35MSDIBO.js";import{Y as R}from"./chunk-YFWLORNM.js";import{s as b}from"./chunk-VYUKN3XQ.js";import{c as p}from"./chunk-AYHVL37M.js";import{i as O,k as H}from"./chunk-AWMJHCA7.js";import{b as d,c as A,d as T,h as x}from"./chunk-KXVCY5JT.js";import{Da as P,K as v,L as C,Na as E,P as y,Sa as w,Ta as l,a as u,b as S,t as g}from"./chunk-XNQ3RS5P.js";var c=class{constructor(s,e,t,r){this.name=e,this.value=s,this.sortValue=t,this.order=r}getName(){return this.name}getValue(){return this.value}getSortValue(){return this.sortValue}getOrder(){return this.order}},G=new c("priceAscending","Pre\u021B cresc\u0103tor","Price","ASC"),L=new c("priceDescending","Pre\u021B descresc\u0103tor","Price","DESC"),V=new c("newest","Cele mai noi","Newest","DESC"),m=new c("topSales","Cele mai v\xE2ndute","TopSales","ASC"),U=new c("score","Relevan\u021B\u0103","Score","ASC");var h=new A(()=>!1);function z(n,s){if(n.url.includes(p.getCategoryApiUrl())&&Number(n.params.get("categoryId"))===1){let e=n.params.get("filter"),t=e==null?void 0:e.includes("Reconditionate3"),r=(e==null?void 0:e.includes("Cuabonament1"))||(e==null?void 0:e.includes("Cubuget1"))||(e==null?void 0:e.includes("Rate"))||(e==null?void 0:e.includes("Faraabonament1")),o=(e==null?void 0:e.includes("Instoc"))||(e==null?void 0:e.includes("Stocepuizat"));if(!e||!r||!o){let i=(e==null?void 0:e.split(","))||[];o||i.push("Instoc"),t?i.push("Reconditionate3"):i.push("Noi"),!r&&n.context.get(h)&&i.push("Cubuget1");let a=n.clone({setParams:{filter:Array.from(new Set(i)).join(",")}});return s(a)}}return s(n)}var N={from:0,size:12,order:m.getOrder(),sort:m.getSortValue(),page:0},_=["ONL-SHS0000001","ONL-SHS0000002","ONL-SHS0000003","ONL-SHS0000004"];function k(n){return n.filter(s=>_.indexOf(s.vantiveCode)===-1)}function F(n){if(!n)throw Error("missing searchResult in category page");n.filter||(n.filter=""),n.filterGroups.sort((e,t)=>e.displayOrder-t.displayOrder),n.filterGroups.forEach(e=>{e.filters=e.filters.sort((t,r)=>t.displayOrder-r.displayOrder)}),n.content=k(n.content);let s=j.getFilterActiveValue(I.PRICE,n);return n}var j=(()=>{let s=class s{constructor(t){this.httpClient=t,this.store=l(b),this.router=l(H),this.activatedRoute=l(O),this.updateAutocompletePosition=new g,this.searchRoot=p.getCategoryApiUrl()}static getFilterActiveValue(t,r){if(r.filter){let o=r.filterGroups.find(({type:i})=>i===t);if(o){let i=r.filter.split(","),a=o.filters.find(({filterCode:f})=>i.includes(f));return a==null?void 0:a.filterValue}}}buildApiHttpParams(t,r){let o=new d;o=o.append("categoryId",t==null?void 0:t.toString());let i=u(u({},N),r);for(let a of Object.keys(i))i[a]!==""&&(o=o.append(a,i[a].toString()));return o}getProductsInformation(t,r){let o=this.isPricesRequest(r)?"".concat(this.searchRoot,"/prices"):this.searchRoot;return this.httpClient.get(o,{context:new T().set(h,this.store.selectSignal(R)()),params:this.buildApiHttpParams(t,r),withCredentials:!0})}isPricesRequest(t){return!!t.productsIds}getSearchResult(t,r){return this.getProductsInformation(t,r).pipe(P(o=>{try{return v(F(o))}catch(i){return C(i)}}))}getProductsPricesById(t,r){return this.getProductsInformation(t,r)}getAutocompleteSuggestions(t,r,o){let i=new d;return i=i.append("categoryId",t.toString()),i=i.append("q",r),i=i.append("size",o.toString()),this.httpClient.get(this.searchRoot+"/autocomplete",{params:i,withCredentials:!0}).pipe(y(this.extractAutocompleteData))}extractAutocompleteData(t){let r="https://static.orangeromania.ro/webshop-images";return t.map(o=>{let i="";return o.href&&!o.oldHref?i="".concat(p.getB2cShopPath()).concat(o.href):!o.href&&o.oldHref?i=o.oldHref:o.href&&o.oldHref&&(i=o.href),{id:o.id,key:o.title,value:p.replaceLinkDomainWithCurrentDomain(i),thumbnail:"".concat(r).concat(o.thumbnail)}})}static enrichQueryParamsWithVariantsIds(t,r){return!r||!r.length?t:S(u({},t),{productsIds:r.join(",")})}handleSearchCategoryByTerm(t){this.router.navigate([],{queryParams:{q:t},queryParamsHandling:"merge",relativeTo:this.activatedRoute}).then(()=>{if(t&&this.lastTrackedSearchTerm!==t){this.lastTrackedSearchTerm=t;let r={event:"ltb.search.performed",search_term:t,event_noninteraction:!1,event_name_ga4:"view_search_results",tms_processor:"microanalytics"};D.analyticsPush(r)}})}};s.\u0275fac=function(r){return new(r||s)(w(x))},s.\u0275prov=E({token:s,factory:s.\u0275fac,providedIn:"root"});let n=s;return n})();export{z as a,N as b,j as c};