
const SYMBOL_LIGHT = "&#x1F31E";
const SYMBOL_DARK = "&#x1F319";

const set_theme_cookie = (value) =>
{
	const d = new Date();
	d.setTime(d.getTime() + (365 * 24 * 60 * 60 * 1000));
	const cookie_str = `theme=${value}; path=/; expires=${d.toUTCString()}; samesite=strict`;
	document.cookie = cookie_str;
};

$(document).ready(() =>
{
	let e_button = $("#theme-button");
	let e_target = $("#theme-target");

	let css_src = e_target.attr("href");
	e_button.html(css_src == "/static/css/light.css" ? SYMBOL_LIGHT : SYMBOL_DARK);

	e_button.on("click", () =>
	{
		let css_src = e_target.attr("href");
		if (css_src == "/static/css/light.css")
		{
			e_target.attr("href", "/static/css/dark.css");
			e_button.html(SYMBOL_DARK);
			set_theme_cookie("dark");
		}
		else
		{
			e_target.attr("href", "/static/css/light.css");
			e_button.html(SYMBOL_LIGHT);
			set_theme_cookie("light");
		}
	});
});

