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