import { html, render } from 'lit-html';
import { db, clearDataStorage } from './dataStorage.js';
import { modifySettings, settings } from './settings.js';
import { showModal, hideOverlay } from './overlays.js';
import { ElementById, hideElement, showElement } from './helpers.js';
import { t, getLanguages } from './languages.js';
import { searchView } from './searchView.js';
import { initHafasClient } from './hafasClient.js';
export const showSettings = async () => {
showModal(t('settings'), settingsTemplate());
profileChangeHandler(settings.profile);
};
const settingsTemplate = () => html`
`;
const profileChangeHandler = (profile) => {
switch (profile) {
case 'db':
showElement(ElementById('showPricesElement'));
showElement(ElementById('loyaltyCardElement'));
showElement(ElementById('ageGroupElement'));
hideElement(ElementById('walkingSpeedElement'));
break;
default:
showElement(ElementById('walkingSpeedElement'));
hideElement(ElementById('showPricesElement'));
hideElement(ElementById('loyaltyCardElement'));
hideElement(ElementById('ageGroupElement'));
break;
};
};
const clearStorage = async () => {
clearDataStorage();
caches.keys().then(names => {
for (let name of names) caches.delete(name);
});
location.reload();
};
const saveSettings = async () => {
const profile = ElementById('profile').value;
let clearInputs = false;
if (profile !== settings.profile) clearInputs = true;
await modifySettings(settings => {
settings.combineDateTime = ElementById('combineDateTime').checked;
settings.showDS100 = ElementById('showDS100').checked;
settings.showPrices = ElementById('showPrices').checked;
settings.language = ElementById('language').value;
settings.profile = profile;
settings.loyaltyCard = ElementById('loyaltyCard').value;
settings.walkingSpeed = ElementById('walkingSpeed').value;
settings.ageGroup = ElementById('ageGroup').value;
return settings;
});
await initHafasClient(settings.profile);
searchView(clearInputs);
hideOverlay();
};