import 'dart:html' show window, querySelector;
final localStorage = window.localStorage;
Future setTheme([String theme]) async {
final currentTheme = theme ?? localStorage['theme'] ??
() {
final devicePrefersDark =
window.matchMedia('(prefers-color-scheme: dark)').matches;
return devicePrefersDark ? 'nord' : 'light';
}();
localStorage['theme'] = currentTheme;
querySelector('body')
..classes.clear()
..classes.add(currentTheme);
}
void enableThemeChanger() {
final themes = ['light', 'dark', 'nord', 'black'];
themes.forEach((theme) =>
querySelector('#${theme}Btn').onClick.listen((_) => setTheme(theme))
);
}