import{a as x}from"./context-B0nlviwN.js";import{b as D,G as P,E as U}from"./utils-bGFjD22D.js";var T=Object.defineProperty,_=(t,e,r)=>e in t?T(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,$=(t,e,r)=>_(t,typeof e!="symbol"?e+"":e,r);class p{constructor(e,r){if($(this,"baseUrl"),$(this,"resource"),!e)throw new Error("resource needs to be set");this.resource=e,this.baseUrl=r}buildUrl(e){if(!e)throw new Error("sub-resource needs to be set");return`${this.baseUrl??""}${this.resource}${e}`}async doFetch(e,r="GET",n,a){const s=await fetch(e,{body:JSON.stringify(n),headers:{"Content-Type":"application/json",...a},method:r});return s.ok?{value:await s.json(),headers:s.headers}:Promise.reject(new h(s))}}class h extends Error{constructor(e){super(`Fetch failed with status ${e.status}`),Object.setPrototypeOf(this,h.prototype)}}const S="%[a-f0-9]{2}",E=new RegExp("("+S+")|([^%]+?)","gi"),F=new RegExp("("+S+")+","gi");function g(t,e){try{return[decodeURIComponent(t.join(""))]}catch{}if(t.length===1)return t;e=e||1;const r=t.slice(0,e),n=t.slice(e);return Array.prototype.concat.call([],g(r),g(n))}function H(t){try{return decodeURIComponent(t)}catch{let e=t.match(E)||[];for(let r=1;r<e.length;r++)t=g(e,r).join(""),e=t.match(E)||[];return t}}function L(t){const e={"%FE%FF":"��","%FF%FE":"��"};let r=F.exec(t);for(;r;){try{e[r[0]]=decodeURIComponent(r[0])}catch{const a=H(r[0]);a!==r[0]&&(e[r[0]]=a)}r=F.exec(t)}e["%C2"]="�";const n=Object.keys(e);for(const a of n)t=t.replace(new RegExp(a,"g"),e[a]);return t}function z(t){if(typeof t!="string")throw new TypeError("Expected `encodedURI` to be of type `string`, got `"+typeof t+"`");try{return decodeURIComponent(t)}catch{return L(t)}}function B(t,e){const r={};if(Array.isArray(e))for(const n of e){const a=Object.getOwnPropertyDescriptor(t,n);a!=null&&a.enumerable&&Object.defineProperty(r,n,a)}else for(const n of Reflect.ownKeys(t)){const a=Object.getOwnPropertyDescriptor(t,n);if(a.enumerable){const s=t[n];e(n,s,t)&&Object.defineProperty(r,n,a)}}return r}function O(t,e){if(!(typeof t=="string"&&typeof e=="string"))throw new TypeError("Expected the arguments to be of type `string`");if(t===""||e==="")return[];const r=t.indexOf(e);return r===-1?[]:[t.slice(0,r),t.slice(r+e.length)]}const q=t=>t==null,M=t=>encodeURIComponent(t).replaceAll(/[!'()*]/g,e=>`%${e.charCodeAt(0).toString(16).toUpperCase()}`),b=Symbol("encodeFragmentIdentifier");function G(t){switch(t.arrayFormat){case"index":return e=>(r,n)=>{const a=r.length;return n===void 0||t.skipNull&&n===null||t.skipEmptyString&&n===""?r:n===null?[...r,[l(e,t),"[",a,"]"].join("")]:[...r,[l(e,t),"[",l(a,t),"]=",l(n,t)].join("")]};case"bracket":return e=>(r,n)=>n===void 0||t.skipNull&&n===null||t.skipEmptyString&&n===""?r:n===null?[...r,[l(e,t),"[]"].join("")]:[...r,[l(e,t),"[]=",l(n,t)].join("")];case"colon-list-separator":return e=>(r,n)=>n===void 0||t.skipNull&&n===null||t.skipEmptyString&&n===""?r:n===null?[...r,[l(e,t),":list="].join("")]:[...r,[l(e,t),":list=",l(n,t)].join("")];case"comma":case"separator":case"bracket-separator":{const e=t.arrayFormat==="bracket-separator"?"[]=":"=";return r=>(n,a)=>a===void 0||t.skipNull&&a===null||t.skipEmptyString&&a===""?n:(a=a===null?"":a,n.length===0?[[l(r,t),e,l(a,t)].join("")]:[[n,l(a,t)].join(t.arrayFormatSeparator)])}default:return e=>(r,n)=>n===void 0||t.skipNull&&n===null||t.skipEmptyString&&n===""?r:n===null?[...r,l(e,t)]:[...r,[l(e,t),"=",l(n,t)].join("")]}}function V(t){let e;switch(t.arrayFormat){case"index":return(r,n,a)=>{if(e=/\[(\d*)]$/.exec(r),r=r.replace(/\[\d*]$/,""),!e){a[r]=n;return}a[r]===void 0&&(a[r]={}),a[r][e[1]]=n};case"bracket":return(r,n,a)=>{if(e=/(\[])$/.exec(r),r=r.replace(/\[]$/,""),!e){a[r]=n;return}if(a[r]===void 0){a[r]=[n];return}a[r]=[...a[r],n]};case"colon-list-separator":return(r,n,a)=>{if(e=/(:list)$/.exec(r),r=r.replace(/:list$/,""),!e){a[r]=n;return}if(a[r]===void 0){a[r]=[n];return}a[r]=[...a[r],n]};case"comma":case"separator":return(r,n,a)=>{const s=typeof n=="string"&&n.includes(t.arrayFormatSeparator),i=typeof n=="string"&&!s&&f(n,t).includes(t.arrayFormatSeparator);n=i?f(n,t):n;const o=s||i?n.split(t.arrayFormatSeparator).map(d=>f(d,t)):n===null?n:f(n,t);a[r]=o};case"bracket-separator":return(r,n,a)=>{const s=/(\[])$/.test(r);if(r=r.replace(/\[]$/,""),!s){a[r]=n&&f(n,t);return}const i=n===null?[]:n.split(t.arrayFormatSeparator).map(o=>f(o,t));if(a[r]===void 0){a[r]=i;return}a[r]=[...a[r],...i]};default:return(r,n,a)=>{if(a[r]===void 0){a[r]=n;return}a[r]=[...[a[r]].flat(),n]}}}function w(t){if(typeof t!="string"||t.length!==1)throw new TypeError("arrayFormatSeparator must be single character string")}function l(t,e){return e.encode?e.strict?M(t):encodeURIComponent(t):t}function f(t,e){return e.decode?z(t):t}function C(t){return Array.isArray(t)?t.sort():typeof t=="object"?C(Object.keys(t)).sort((e,r)=>Number(e)-Number(r)).map(e=>t[e]):t}function R(t){const e=t.indexOf("#");return e!==-1&&(t=t.slice(0,e)),t}function K(t){let e="";const r=t.indexOf("#");return r!==-1&&(e=t.slice(r)),e}function j(t,e,r){return r==="string"&&typeof t=="string"?t:typeof r=="function"&&typeof t=="string"?r(t):e.parseBooleans&&t!==null&&(t.toLowerCase()==="true"||t.toLowerCase()==="false")?t.toLowerCase()==="true":r==="number"&&!Number.isNaN(Number(t))&&typeof t=="string"&&t.trim()!==""||e.parseNumbers&&!Number.isNaN(Number(t))&&typeof t=="string"&&t.trim()!==""?Number(t):t}function m(t){t=R(t);const e=t.indexOf("?");return e===-1?"":t.slice(e+1)}function v(t,e){e={decode:!0,sort:!0,arrayFormat:"none",arrayFormatSeparator:",",parseNumbers:!1,parseBooleans:!1,types:Object.create(null),...e},w(e.arrayFormatSeparator);const r=V(e),n=Object.create(null);if(typeof t!="string"||(t=t.trim().replace(/^[?#&]/,""),!t))return n;for(const a of t.split("&")){if(a==="")continue;const s=e.decode?a.replaceAll("+"," "):a;let[i,o]=O(s,"=");i===void 0&&(i=s),o=o===void 0?null:["comma","separator","bracket-separator"].includes(e.arrayFormat)?o:f(o,e),r(f(i,e),o,n)}for(const[a,s]of Object.entries(n))if(typeof s=="object"&&s!==null&&e.types[a]!=="string")for(const[i,o]of Object.entries(s)){const d=e.types[a]?e.types[a].replace("[]",""):void 0;s[i]=j(o,e,d)}else typeof s=="object"&&s!==null&&e.types[a]==="string"?n[a]=Object.values(s).join(e.arrayFormatSeparator):n[a]=j(s,e,e.types[a]);return e.sort===!1?n:(e.sort===!0?Object.keys(n).sort():Object.keys(n).sort(e.sort)).reduce((a,s)=>{const i=n[s];return a[s]=i&&typeof i=="object"&&!Array.isArray(i)?C(i):i,a},Object.create(null))}function A(t,e){if(!t)return"";e={encode:!0,strict:!0,arrayFormat:"none",arrayFormatSeparator:",",...e},w(e.arrayFormatSeparator);const r=i=>e.skipNull&&q(t[i])||e.skipEmptyString&&t[i]==="",n=G(e),a={};for(const[i,o]of Object.entries(t))r(i)||(a[i]=o);const s=Object.keys(a);return e.sort!==!1&&s.sort(e.sort),s.map(i=>{const o=t[i];return o===void 0?"":o===null?l(i,e):Array.isArray(o)?o.length===0&&e.arrayFormat==="bracket-separator"?l(i,e)+"[]":o.reduce(n(i),[]).join("&"):l(i,e)+"="+l(o,e)}).filter(i=>i.length>0).join("&")}function N(t,e){var r;e={decode:!0,...e};let[n,a]=O(t,"#");return n===void 0&&(n=t),{url:((r=n==null?void 0:n.split("?"))==null?void 0:r[0])??"",query:v(m(t),e),...e&&e.parseFragmentIdentifier&&a?{fragmentIdentifier:f(a,e)}:{}}}function I(t,e){e={encode:!0,strict:!0,[b]:!0,...e};const r=R(t.url).split("?")[0]||"",n=m(t.url),a={...v(n,{sort:!1}),...t.query};let s=A(a,e);s&&(s=`?${s}`);let i=K(t.url);if(typeof t.fragmentIdentifier=="string"){const o=new URL(r);o.hash=t.fragmentIdentifier,i=e[b]?o.hash:`#${t.fragmentIdentifier}`}return`${r}${s}${i}`}function k(t,e,r){r={parseFragmentIdentifier:!0,[b]:!1,...r};const{url:n,query:a,fragmentIdentifier:s}=N(t,r);return I({url:n,query:B(a,e),fragmentIdentifier:s},r)}function J(t,e,r){const n=Array.isArray(e)?a=>!e.includes(a):(a,s)=>!e(a,s);return k(t,n,r)}const c=Object.freeze(Object.defineProperty({__proto__:null,exclude:J,extract:m,parse:v,parseUrl:N,pick:k,stringify:A,stringifyUrl:I},Symbol.toStringTag,{value:"Module"}));class re extends p{constructor(e){super("/mainframe/internal/cars/",e)}async searchCar(e,r,n,a,s){const{projection:i,params:o,...d}=s,u={country:e,brand:r,_page:n,_size:a,projection:i,...d,...o},y=this.buildUrl(`?${c.stringify(u)}`);return this.doFetch(y)}async searchCarById(e,r){const n={projection:r},a=this.buildUrl(`${e}?${c.stringify(n)}`);return this.doFetch(a)}async searchCarsByIds(e,r){const n={carId:e,projection:r},a=this.buildUrl(`?${c.stringify(n)}`);return this.doFetch(a).then(s=>s.value)}getCarByIdenticalCarHash(e,r){const n={projection:r},a=this.buildUrl(`identicalCarHash/${e}?${c.stringify(n)}`);return this.doFetch(a)}}class ne extends p{constructor(e){super("/dealer-resolver/internal",e)}async getDealer(e,r,n){const a={brand:n},s=this.buildUrl(`/dealer/${e}/${r}?${c.stringify(a)}`);return this.doFetch(s).then(i=>i.value)}async getInternetDealer(e,r){const n=this.buildUrl(`/dealer/${e}/${r}/leader`);return this.doFetch(n).then(a=>a.value)}async getDealerRatings(e,r,n){const a={brand:n},s=this.buildUrl(`/dealer/${e}/${r}/rating?${c.stringify(a)}`);return this.doFetch(s).then(i=>i.value)}async getOpeningHours(e,r,n){const a={brand:n},s=this.buildUrl(`/dealer/${e}/${r}/openinghours?${c.stringify(a)}`);return this.doFetch(s).then(i=>i.value)}async getEcomLightDealers(e,r){const n=this.buildUrl(`/dealer/${e}/${r}/ecom-light`);return this.doFetch(n).then(a=>a.value)}async searchDealers(e,r,n){const a={country:n.country,brand:n.brand,name:n.name,specificDealerId:n.specificDealerId,group:n.group,tags:n.tags,"place.id":n.placeId,"place.distance":n.placeDistance,_page:e,_size:r},s=this.buildUrl(`/dealer?${c.stringify(a)}`);return this.doFetch(s).then(i=>i.value)}async searchAllDealers(e){return this.searchAllDealersRecursive(0,25,e)}async searchAllDealersRecursive(e,r,n){const a=await this.searchDealers(e,r,n),s=a.nextPageRequest;if(s){const i=await this.searchAllDealersRecursive(s.page,s.size,n);return[...a.dealers,...i]}return a.dealers}async suggest(e){const r=this.buildUrl("/suggestion");return this.doFetch(r,"POST",e).then(n=>n.value)}}class Q extends Error{constructor(e){super(e)}}class ae extends p{constructor(e){super("/mainframe/internal/favourites",e)}async getFavourites(e,r,n,a,s,i){const o={country:e,brand:r,_page:n,_size:a,...i},d=this.buildUrl(`?${c.stringify(o)}`);return fetch(d,{method:"GET",headers:{Authorization:`Bearer ${s}`}}).then(u=>{if(u.status===404)throw new Q(`get favourites failed with status ${u.status}`);if(!u.ok)throw new Error(`get favourites failed with status ${u.status}`);return u.json()})}async isFavourited(e,r,n,a){const s={country:e,brand:r},i=this.buildUrl(`/isFavourited?${c.stringify(s)}`);return this.doFetch(i,"POST",n,{Authorization:`Bearer ${a}`}).then(o=>o.value)}async addFavourite(e,r,n,a){const s={country:e,brand:r,identicalCarHash:n},i=this.buildUrl(`?${c.stringify(s)}`);return this.doFetch(i,"POST",void 0,{Authorization:`Bearer ${a}`}).then(o=>o.value)}async addFavourites(e,r,n,a){const s={country:e,brand:r},i=this.buildUrl(`/bulk?${c.stringify(s)}`);return this.doFetch(i,"POST",n,{Authorization:`Bearer ${a}`}).then(o=>o.value)}async deleteFavourite(e,r,n,a){const s={country:e,brand:r},i=this.buildUrl(`/${n}?${c.stringify(s)}`),o=await fetch(i,{headers:{Authorization:`Bearer ${a}`},method:"DELETE"}).then();if(!o.ok)return Promise.reject(new h(o))}}var Y=(t=>(t.CASH="CASH",t.LEASE="LEASE",t.CREDIT="CREDIT",t.INSURANCE="INSURANCE",t))(Y||{});class se extends p{constructor(e){super("/mainframe/internal/financecalc/",e)}async getProducts(e,r,n,a,s,i){const o={brand:e,country:r,modelCode:n,onlineSales:a,testDrive:s,...i},d=this.buildUrl(`products?${c.stringify(o)}`);return this.doFetch(d).then(u=>u.value)}async getDefaultRate(e,r){const n={type:r},a=this.buildUrl(`car/${e}/defaultRate?${c.stringify(n)}`);return this.doFetch(a).then(s=>s.value)}async getDefaultRateForIdenticalCarHash(e,r){const n={type:r},a=this.buildUrl(`car/identicalCarHash/${e}/defaultRate?${c.stringify(n)}`);return this.doFetch(a).then(s=>s.value)}async getDefaultRates(e,r){const n={type:r,carIds:e},a=this.buildUrl(`bulk/defaultRate?${c.stringify(n)}`);return this.doFetch(a).then(s=>s.value)}async getProductDetail(e,r,n){const a={type:n==null?void 0:n.type},s=this.buildUrl(`car/${e}/detail/${r}?${c.stringify(a)}`);return this.doFetch(s,"POST",n==null?void 0:n.parameters).then(i=>i.value)}async getProductDetailForIdenticalCarHash(e,r,n){const a={type:n==null?void 0:n.type},s=this.buildUrl(`car/identicalCarHash/${e}/detail/${r}?${c.stringify(a)}`);return this.doFetch(s,"POST",n==null?void 0:n.parameters).then(i=>i.value)}}var W=(t=>(t.BOOTSTRAPPED_EVENT_NAME="fc-bootstrapped",t.CONFIGURE_EVENT_NAME="fc-configure",t.SAVE_PRODUCT_EVENT_NAME="fc-save-product",t.DISMISS_EVENT_NAME="fc-close",t.TRACKING="fc-tracking",t))(W||{});function ie({groups:t}){if(!t)return;const e={},r=(n,a)=>{a!==void 0&&(e[n]=a)};for(const n of t)for(const a of n.fields||[]){if(a.type==="Label"||a.id===void 0)continue;const{data:s,type:i,id:o,value:d}=a;let u=s==null?void 0:s.find(y=>(i==="Select"||i==="Radio"||i==="Question"||i==="Slider")&&y.defaultValue==="Yes");!u&&s!=null&&s.length&&i==="Edit"&&(u=s[0]),u?r(o,u.value):i==="Check"?r(o,`${d==="true"}`):i==="Hidden"&&r(o,d)}return e}class oe extends p{constructor(e){super("/mainframe/api/redirect",e)}buildHomePageRedirect(e){return this.buildUrl(`/home-page?${c.stringify(e)}`)}buildCarDetailRedirect(e){return this.buildUrl(`/car-detail?${c.stringify(e)}`)}buildOfferRequesterRedirect(e){return this.buildUrl(`/offer-requester?${c.stringify(e)}`)}buildResultListRedirect(e){return this.buildUrl(`/result-list?${c.stringify(e)}`)}}class ce extends p{constructor(e){super("/mainframe/internal/cars",e)}searchSimilarCars(e,r,n){const a={projection:r,...n},s=this.buildUrl(`/${e}/similar?${c.stringify(a)}`);return this.doFetch(s).then(i=>i.value)}}class X extends U{handle(e){console.groupCollapsed(`Meta: ${e.type}`),console.log("event:",e),console.groupEnd()}}class Z extends U{handle(e){}}function le(){const t=x(),e=D();return r=>{r.additionalPayload=e(r);const n=[t.environment.isDevelop?new X:new Z,new P(t.frontendProperties.googleTagManager.url)];r=Object.freeze(r),n.forEach(a=>a.handle(r))}}export{ne as a,re as c,ie as d,Y as e,oe as g,ae as l,W as n,se as o,Q as r,le as u,ce as y};
