'use strict';
import { themes } from '../../menu/themes.js';
import { eventListenerEvents } from '../../../../fd-toolbox/constants/events.js';
import { setLocalStorage } from '../../../../fd-toolbox/local-storage/local-storage.js';
import { jsBasicTypes } from '../../../../base-repo/constants/basic-types.js';

var __defProp=Object['defineProperty'],__name=(_0x4de12d,_0x119022)=>__defProp(_0x4de12d,'name',{'value':_0x119022,'configurable':!![]});function saveTheme(_0x4ce5d5,_0x1dd6c2){_0x1dd6c2(_0x4ce5d5),setLocalStorage(themes['theme'],_0x4ce5d5);}__name(saveTheme,'saveTheme');function onThemeSwitch(_0x3be244,_0x3bd31c){handleThemeChange(_0x3be244,_0x3bd31c);if(typeof window===jsBasicTypes['undefined'])return void(-0x7fb*0x2+-0x2651+-0x5*-0xadb);const _0x1a170c=window['matchMedia'](themes['colorScheme']),_0x390d5a=__name(()=>{handleThemeChange(themes['system'],_0x3bd31c);},'handleSystemThemeChange');return _0x3be244===themes['system']&&_0x1a170c['addEventListener'](eventListenerEvents['change'],_0x390d5a),()=>{_0x1a170c['removeEventListener'](eventListenerEvents['change'],_0x390d5a);};}__name(onThemeSwitch,'onThemeSwitch');function handleThemeChange(_0x5f30af,_0xe09fc3){if(typeof document===jsBasicTypes['undefined'])return;const _0x29952b=resolveTheme(_0x5f30af);_0xe09fc3(_0x29952b);const _0x459c4f=document['documentElement'],_0x345424=_0x459c4f['classList'],_0x327c9=_0x345424['contains'](_0x29952b),_0x217a9d=_0x345424['contains'](_0x29952b===themes['dark']?themes['light']:themes['dark']);(!_0x327c9||_0x217a9d)&&(_0x345424['remove'](themes['light'],themes['dark']),_0x345424['add'](_0x29952b)),_0x459c4f['style']['colorScheme']=_0x29952b;}__name(handleThemeChange,'handleThemeChange');function resolveTheme(_0x288910){return _0x288910===themes['system']?getSystemTheme():_0x288910;}__name(resolveTheme,'resolveTheme');function getSystemTheme(){if(typeof window===jsBasicTypes['undefined'])return themes['light'];return window['matchMedia'](themes['colorScheme'])['matches']?themes['dark']:themes['light'];}__name(getSystemTheme,'getSystemTheme');

export { onThemeSwitch, saveTheme };
