import './bootstrap';

const applyAdminTheme = () => {
	const stored = localStorage.getItem('adminDark');
	const prefersDark = window.matchMedia('(prefers-color-scheme: dark)').matches;
	const enabled = stored === null ? prefersDark : stored === 'true';

	document.documentElement.classList.toggle('dark', enabled);
	document.documentElement.style.colorScheme = enabled ? 'dark' : 'light';
};

applyAdminTheme();

window.addEventListener('storage', (event) => {
	if (event.key === 'adminDark') {
		applyAdminTheme();
	}
});

window.quickroApplyAdminTheme = applyAdminTheme;
