import { html, nothing } from 'lit'; import { when } from 'lit/directives/when.js'; import { classMap } from 'lit/directives/class-map.js'; import { BaseView } from './baseView.js'; import { sleep, queryBackgroundColor, setThemeColor } from './helpers.js'; import { getLanguages, t } from './translate.js'; import { initHafasClient, profiles } from './hafasClient.js'; import { clearDataStorage } from './dataStorage.js'; import { settingsViewStyles } from './styles.js'; class SettingsView extends BaseView { static styles = [ super.styles, settingsViewStyles ]; updated (previous) { super.updated(previous, 'SettingsView'); } render = () => [ html`
`, html`
`, when(this.settingsState.profile !== 'db', () => html`
`), when(this.settingsState.profile !== 'db', () => html`
`), when(this.settingsState.profile === 'db', () => html`
`), when(this.settingsState.profile === 'db', () => html`
`), html`
`, html`
${t('options')}:
`, html`
`, ]; changeHandler = async event => { const id = event.target.id; const value = event.target.value; if (id === 'language') this.settingsState.setLanguage(value); if (id === 'walkingSpeed') this.settingsState.setWalkingSpeed(value); if (id === 'accessibility') this.settingsState.setAccessibility(value); if (id === 'transferTime') this.settingsState.setTransferTime(parseInt(value)); if (id === 'ageGroup') this.settingsState.setAgeGroup(value); if (id === 'loyaltyCard') this.settingsState.setLoyaltyCard(value); if (id === 'showDS100') this.settingsState.toggleShowDS100(); if (id === 'showPrices') this.settingsState.toggleShowPrices(); if (id === 'combineDateTime') this.settingsState.toggleCombineDateTime(); if (id === 'profile') { this.settingsState.setProfile(value); await initHafasClient(this.settingsState.profile); } }; clearStorage = () => { if (confirm('Do you really want to delete all local data?')) { clearDataStorage(); localStorage.clear(); caches.keys().then(names => names.forEach(name => caches.delete(name))); location.reload(); } }; } customElements.define('settings-view', SettingsView);