{"version":3,"names":["ResultCache","constructor","loadValue","this","cache","Map","get","forceReload","params","cacheKey","toString","has","set","value","key","clear","async","fetchJson","path","response","fetch","error","FetchError","ok","status","json","Error","method","super","toUpperCase","compareCountries","a","b","compareMultiLangString","name","compareConnections","_a","_b","_c","_d","_e","from","stationFrom","to","stationTo","trainNumber","localeCompare","valueA","getLocalizedString","valueB","formatPrice","price","currency","toFixed","replace","matchesStation","stop","station","country","carTransport","car","eva","evaMeta","matchesMultiLangString","query","_f","_g","trim","toLowerCase","int","includes","de","en","it","fr","nl","getTicketshopEva","length","startsWith","getMetaEva","TrainService","njBaseUrl","pvAppsBaseUrl","maxBookableDate","addDaysToDate","countryCache","url","loadCountries","connectionListCache","loadConnections","connectionDetailsCache","loadConnectionDetails","offersCache","loadOffers","instance","_instance","setNjBaseUrl","setPvAppsBaseUrl","setMaxBookableDate","dateString","date","Date","isNaN","valueOf","loadConfig","config","getMaxBookableDate","getGeolocation","result","countryCode","e","console","log","findCountriesForDestinationCountry","destinationCountry","direction","filter","findCountriesForDestinationStation","destinationStation","sort","findConnectionsForDestinationCountry","originCountry","travelDate","findConnectionsForDestinationStation","findConnectionsForType","type","getConnectionDetails","connection","getOffers","departure","forward"],"sources":["node_modules/@oebb-web-team/oebb-web-components/dist/collection/utils/cache.js","node_modules/@oebb-web-team/oebb-web-components/dist/collection/utils/fetch.js","node_modules/@oebb-web-team/oebb-web-components/dist/collection/utils/nightjet.js","node_modules/@oebb-web-team/oebb-web-components/dist/collection/service/train.service.js"],"sourcesContent":["export class ResultCache {\n constructor(loadValue) {\n this.cache = new Map();\n this.loadValue = loadValue;\n }\n get(forceReload = false, params, cacheKey = params === null || params === void 0 ? void 0 : params.toString()) {\n if (forceReload || !this.cache.has(cacheKey)) {\n this.cache.set(cacheKey, this.loadValue(params, forceReload));\n }\n return this.cache.get(cacheKey);\n }\n set(value, key) {\n this.cache.set(key, value);\n }\n clear() {\n this.cache.clear();\n }\n}\n//# sourceMappingURL=cache.js.map\n","export async function fetchJson(path) {\n let response;\n try {\n response = await fetch(path);\n }\n catch (error) {\n throw new FetchError(error, 'get', path);\n }\n if (!response || !response.ok) {\n throw new FetchError(response, 'get', path);\n }\n if (response.status === 204) {\n // No content\n return null;\n }\n return await response.json();\n}\nexport class FetchError extends Error {\n constructor(response, method, path) {\n super(`JSON request failed (${method.toUpperCase()} ${path}) with HTTP status ${response === null || response === void 0 ? void 0 : response.status}`);\n this.response = response;\n this.method = method;\n this.path = path;\n }\n}\n//# sourceMappingURL=fetch.js.map\n","import { getLocalizedString } from \"./I18n\";\nexport function compareCountries(a, b) {\n return compareMultiLangString(a === null || a === void 0 ? void 0 : a.name, b === null || b === void 0 ? void 0 : b.name);\n}\nexport function compareConnections(a, b) {\n var _a, _b, _c, _d, _e;\n const from = compareMultiLangString((_a = a === null || a === void 0 ? void 0 : a.stationFrom) === null || _a === void 0 ? void 0 : _a.name, (_b = b === null || b === void 0 ? void 0 : b.stationFrom) === null || _b === void 0 ? void 0 : _b.name);\n if (from) {\n return from;\n }\n const to = compareMultiLangString((_c = a === null || a === void 0 ? void 0 : a.stationTo) === null || _c === void 0 ? void 0 : _c.name, (_d = b === null || b === void 0 ? void 0 : b.stationTo) === null || _d === void 0 ? void 0 : _d.name);\n if (to) {\n return to;\n }\n return (_e = a === null || a === void 0 ? void 0 : a.trainNumber) === null || _e === void 0 ? void 0 : _e.localeCompare(b === null || b === void 0 ? void 0 : b.trainNumber);\n}\nexport function compareMultiLangString(a, b) {\n const valueA = getLocalizedString(a);\n const valueB = getLocalizedString(b);\n if (!valueA && !valueB) {\n return 0;\n }\n else if (!valueA) {\n return -1;\n }\n else if (!valueB) {\n return 1;\n }\n else {\n return valueA.localeCompare(valueB);\n }\n}\nexport function formatPrice(price, currency = '€') {\n return currency + ' ' + price.toFixed(2).replace('.', ',');\n}\nexport function matchesStation(stop, station, country, carTransport) {\n return (!carTransport || stop.car)\n && (!station || station === stop.station.eva || station === stop.station.evaMeta)\n && (!country || country === stop.station.country);\n}\nexport function matchesMultiLangString(value, query) {\n var _a, _b, _c, _d, _e, _f, _g;\n query = (_a = query === null || query === void 0 ? void 0 : query.trim()) === null || _a === void 0 ? void 0 : _a.toLowerCase();\n return !query\n || ((_b = value === null || value === void 0 ? void 0 : value.int) === null || _b === void 0 ? void 0 : _b.toLowerCase().includes(query))\n || ((_c = value === null || value === void 0 ? void 0 : value.de) === null || _c === void 0 ? void 0 : _c.toLowerCase().includes(query))\n || ((_d = value === null || value === void 0 ? void 0 : value.en) === null || _d === void 0 ? void 0 : _d.toLowerCase().includes(query))\n || ((_e = value === null || value === void 0 ? void 0 : value.it) === null || _e === void 0 ? void 0 : _e.toLowerCase().includes(query))\n || ((_f = value === null || value === void 0 ? void 0 : value.fr) === null || _f === void 0 ? void 0 : _f.toLowerCase().includes(query))\n || ((_g = value === null || value === void 0 ? void 0 : value.nl) === null || _g === void 0 ? void 0 : _g.toLowerCase().includes(query));\n}\nexport function getTicketshopEva(station) {\n return (station === null || station === void 0 ? void 0 : station.evaMeta) && station.evaMeta.length === 7 && !station.evaMeta.startsWith(\"00\")\n ? station.evaMeta\n : station.eva;\n}\nexport function getMetaEva(station) {\n return (station === null || station === void 0 ? void 0 : station.evaMeta) || (station === null || station === void 0 ? void 0 : station.eva);\n}\n//# sourceMappingURL=nightjet.js.map\n","import { addDaysToDate, compareConnections, compareCountries, fetchJson, matchesMultiLangString, ResultCache } from \"../utils\";\nexport class TrainService {\n constructor() {\n this.njBaseUrl = '/nj-booking';\n this.pvAppsBaseUrl = 'https://pv-apps.web.oebb.at';\n this.maxBookableDate = addDaysToDate(180);\n this.countryCache = new ResultCache((url) => this.loadCountries(url));\n this.connectionListCache = new ResultCache((url) => this.loadConnections(url));\n this.connectionDetailsCache = new ResultCache((url) => this.loadConnectionDetails(url));\n this.offersCache = new ResultCache((url) => this.loadOffers(url));\n }\n static get instance() {\n if (!this._instance) {\n this._instance = new TrainService();\n }\n return this._instance;\n }\n setNjBaseUrl(url) {\n this.njBaseUrl = url;\n }\n setPvAppsBaseUrl(url) {\n this.pvAppsBaseUrl = url;\n }\n setMaxBookableDate(dateString) {\n if (!dateString) {\n return;\n }\n const date = new Date(dateString);\n if (!isNaN(date.valueOf())) {\n this.maxBookableDate = date;\n }\n }\n async loadConfig() {\n const config = await fetchJson(this.njBaseUrl + '/config');\n this.setMaxBookableDate(config.maxBookableDate);\n }\n getMaxBookableDate() {\n return this.maxBookableDate;\n }\n async getGeolocation() {\n var _a;\n try {\n const result = await fetchJson(this.pvAppsBaseUrl + '/geolocation');\n return (_a = result === null || result === void 0 ? void 0 : result.countryCode) === null || _a === void 0 ? void 0 : _a.toLowerCase();\n }\n catch (e) {\n console.log('Error loading geolocation', e);\n return null;\n }\n }\n async findCountriesForDestinationCountry(destinationCountry, carTransport, direction, query = '') {\n let url = direction === 'return'\n ? `/countries/from/country/${destinationCountry}`\n : `/countries/to/country/${destinationCountry}`;\n if (carTransport) {\n url += '?carTransport=true';\n }\n const result = await this.countryCache.get(false, url);\n return query\n ? result === null || result === void 0 ? void 0 : result.filter(country => matchesMultiLangString(country === null || country === void 0 ? void 0 : country.name, query))\n : result;\n }\n async findCountriesForDestinationStation(destinationStation, carTransport, direction, query = '') {\n let url = direction === 'return'\n ? `/countries/from/station/${destinationStation}`\n : `/countries/to/station/${destinationStation}`;\n if (carTransport) {\n url += '?carTransport=true';\n }\n const result = await this.countryCache.get(false, url);\n return query\n ? result === null || result === void 0 ? void 0 : result.filter(country => matchesMultiLangString(country === null || country === void 0 ? void 0 : country.name, query))\n : result;\n }\n async loadCountries(url) {\n const result = await fetchJson(this.njBaseUrl + url);\n return result.sort(compareCountries);\n }\n async findConnectionsForDestinationCountry(originCountry, destinationCountry, travelDate, carTransport, direction) {\n let url = direction === 'return'\n ? `/destinations/country/${destinationCountry}/country/${originCountry}/${travelDate}`\n : `/destinations/country/${originCountry}/country/${destinationCountry}/${travelDate}`;\n if (carTransport) {\n url += '?carTransport=true';\n }\n return this.connectionListCache.get(false, url);\n }\n async findConnectionsForDestinationStation(originCountry, destinationStation, travelDate, carTransport, direction) {\n let url = direction === 'return'\n ? `/destinations/station/${destinationStation}/country/${originCountry}/${travelDate}`\n : `/destinations/country/${originCountry}/station/${destinationStation}/${travelDate}`;\n if (carTransport) {\n url += '?carTransport=true';\n }\n return this.connectionListCache.get(false, url);\n }\n async findConnectionsForType(type, travelDate, carTransport) {\n let url = `/destinations/${type}/${travelDate}`;\n if (carTransport) {\n url += '?carTransport=true';\n }\n return this.connectionListCache.get(false, url);\n }\n async loadConnections(url) {\n const result = await fetchJson(this.njBaseUrl + url);\n return result.sort(compareConnections);\n }\n async getConnectionDetails(connection) {\n return this.connectionDetailsCache.get(false, `/destinations/train/${connection.trainNumber}/${connection.date}`);\n }\n async loadConnectionDetails(url) {\n return fetchJson(this.njBaseUrl + url);\n }\n async getOffers(trainNumber, stationFrom, stationTo, departure, forward) {\n const url = `/destinations/offers/${trainNumber}/${stationFrom}/${stationTo}/${+departure}?forward=${forward}`;\n return this.offersCache.get(false, url);\n }\n async loadOffers(url) {\n return fetchJson(this.njBaseUrl + url);\n }\n}\n//# sourceMappingURL=train.service.js.map\n"],"mappings":"wEAAO,MAAMA,EACX,WAAAC,CAAYC,GACVC,KAAKC,MAAQ,IAAIC,IACjBF,KAAKD,UAAYA,CACrB,CACE,GAAAI,CAAIC,EAAc,MAAOC,EAAQC,GAAWD,IAAW,MAAQA,SAAgB,OAAS,EAAIA,EAAOE,aACjG,GAAIH,IAAgBJ,KAAKC,MAAMO,IAAIF,GAAW,CAC5CN,KAAKC,MAAMQ,IAAIH,EAAUN,KAAKD,UAAUM,EAAQD,GACtD,CACI,OAAOJ,KAAKC,MAAME,IAAIG,EAC1B,CACE,GAAAG,CAAIC,EAAOC,GACTX,KAAKC,MAAMQ,IAAIE,EAAKD,EACxB,CACE,KAAAE,GACEZ,KAAKC,MAAMW,OACf,EChBOC,eAAeC,EAAUC,GAC9B,IAAIC,EACJ,IACEA,QAAiBC,MAAMF,EAC3B,CAC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