import { LitElement, html, nothing } from 'lit'; import { classMap } from 'lit/directives/class-map.js'; import { when } from 'lit/directives/when.js'; import { BaseView } from './baseView.js'; import { db } from './dataStorage.js'; import { t } from './translate.js'; import { client } from './hafasClient.js'; import { getIBNRbyDS100 } from './ds100.js'; import { formatPoint } from './formatters.js'; import { newJourneys } from './app_functions.js'; import { CustomDate, sleep, queryBackgroundColor, setThemeColor } from './helpers.js'; import { searchViewStyles } from './styles.js'; class SearchView extends BaseView { static properties = { date: { state: true }, numEnter: { state: true }, noTransfers: { state: true }, isArrival: { state: true }, showHistory: { state: true }, history: { state: true }, location: { state: true }, }; static styles = [ super.styles, searchViewStyles ]; constructor () { super(); this.date = new CustomDate(); this.numEnter = 0; this.noTransfers = false, this.isArrival = false, this.showHistory = false; this.history = []; this.location = { from: { value: '', suggestionsVisible: false, suggestionSelected: null, suggestion: null, suggestions: [], }, to: { value: '', suggestionsVisible: false, suggestionSelected: null, suggestion: null, suggestions: [], }, via: { value: '', suggestionsVisible: false, suggestionSelected: null, suggestion: null, suggestions: [], }, }; } async connectedCallback () { super.connectedCallback(); this.history = (await db.getHistory(this.settingsState.profile)).slice().reverse(); await sleep(200); setThemeColor(queryBackgroundColor(document, 'body')); await sleep(200); this.renderRoot.querySelector('input[name=from]').focus(); } async willUpdate (previous) { if ( previous.has('settingsState') && previous.get('settingsState') !== undefined && previous.get('settingsState').profile !== this.settingsState.profile ) await this.profileChangeHandler(); } updated (previous) { super.updated(previous, 'SearchView'); } renderView = () => { return html`