import{a as D}from"./chunk-77WMUU2O.js";import{a as R}from"./chunk-35MSDIBO.js";import{X as b}from"./chunk-HMS3LRP2.js";import{s as H}from"./chunk-QYQ7WNYU.js";import{b as l}from"./chunk-W73LR43Y.js";import{i as O,k as I}from"./chunk-GW55Q7ZA.js";import{b as f,c as A,d as T,h as x}from"./chunk-6MZAHXNO.js";import{Ba as P,J as y,K as v,La as E,O as C,Qa as w,Ra as u,a as p,b as g,s as S}from"./chunk-HC2G7LSI.js";var a=class{constructor(s,n,t,e){this.name=n,this.value=s,this.sortValue=t,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 A(()=>!1);function z(o,s){if(o.url.includes(l.getCategoryApiUrl())&&Number(o.params.get("categoryId"))===1){let n=o.params.get("filter"),t=n?.includes("Reconditionate3"),e=n?.includes("Cuabonament1")||n?.includes("Cubuget1")||n?.includes("Rate")||n?.includes("Faraabonament1"),r=n?.includes("Instoc")||n?.includes("Stocepuizat");if(!n||!e||!r){let i=n?.split(",")||[];r||i.push("Instoc"),t?i.push("Reconditionate3"):i.push("Noi"),!e&&o.context.get(m)&&i.push("Cubuget1");let c=o.clone({setParams:{filter:Array.from(new Set(i)).join(",")}});return s(c)}}return s(o)}var F={from:0,size:12,order:d.getOrder(),sort:d.getSortValue()},N=["ONL-SHS0000001","ONL-SHS0000002","ONL-SHS0000003","ONL-SHS0000004"];function _(o){return o.filter(s=>N.indexOf(s.vantiveCode)===-1)}function k(o){if(!o)throw Error("missing searchResult in category page");o.filter||(o.filter=""),o.filterGroups.sort((n,t)=>n.displayOrder-t.displayOrder),o.filterGroups.forEach(n=>{n.filters=n.filters.sort((t,e)=>t.displayOrder-e.displayOrder)}),o.content=_(o.content);let s=j.getFilterActiveValue(R.PRICE,o);return o}var j=(()=>{let s=class s{constructor(t){this.httpClient=t,this.store=u(H),this.router=u(I),this.activatedRoute=u(O),this.updateAutocompletePosition=new S,this.searchRoot=l.getCategoryApiUrl()}static getFilterActiveValue(t,e){if(e.filter){let r=e.filterGroups.find(({type:i})=>i===t);if(r){let i=e.filter.split(",");return r.filters.find(({filterCode:h})=>i.includes(h))?.filterValue}}}buildApiHttpParams(t,e){let r=new f;r=r.append("categoryId",t?.toString());let i=p(p({},F),e);for(let c of Object.keys(i))i[c]!==""&&(r=r.append(c,i[c].toString()));return r}getProductsInformation(t,e){let r=this.isPricesRequest(e)?`${this.searchRoot}/prices`:this.searchRoot;return this.httpClient.get(r,{context:new T().set(m,this.store.selectSignal(b)()),params:this.buildApiHttpParams(t,e),withCredentials:!0})}isPricesRequest(t){return!!t.productsIds}getSearchResult(t,e){return this.getProductsInformation(t,e).pipe(P(r=>{try{return y(k(r))}catch(i){return v(i)}}))}getProductsPricesById(t,e){return this.getProductsInformation(t,e)}getAutocompleteSuggestions(t,e,r){let i=new f;return i=i.append("categoryId",t.toString()),i=i.append("q",e),i=i.append("size",r.toString()),this.httpClient.get(this.searchRoot+"/autocomplete",{params:i,withCredentials:!0}).pipe(C(this.extractAutocompleteData))}extractAutocompleteData(t){let e="https://static.orangeromania.ro/webshop-images";return t.map(r=>{let i="";return r.href&&!r.oldHref?i=`${l.getB2cShopPath()}${r.href}`:!r.href&&r.oldHref?i=r.oldHref:r.href&&r.oldHref&&(i=r.href),{id:r.id,key:r.title,value:l.replaceLinkDomainWithCurrentDomain(i),thumbnail:`${e}${r.thumbnail}`}})}static enrichQueryParamsWithVariantsIds(t,e){return!e||!e.length?t:g(p({},t),{productsIds:e.join(",")})}handleSearchCategoryByTerm(t){this.router.navigate([],{queryParams:{q:t},queryParamsHandling:"merge",relativeTo:this.activatedRoute}).then(()=>{if(t&&this.lastTrackedSearchTerm!==t){this.lastTrackedSearchTerm=t;let e={event:"ltb.search.performed",search_term:t,event_noninteraction:!1,event_name_ga4:"view_search_results",tms_processor:"microanalytics"};D.analyticsPush(e)}})}};s.\u0275fac=function(e){return new(e||s)(w(x))},s.\u0275prov=E({token:s,factory:s.\u0275fac,providedIn:"root"});let o=s;return o})();export{z as a,F as b,j as c};