namespace _dali
{


	/**
	 */
	export function view_mode_encode(
		mode : _dali.type.enum_view_mode
	) : string
	{
		switch (mode)
		{
			case _dali.type.enum_view_mode.week: {return "week"; break;}
			case _dali.type.enum_view_mode.list: {return "list"; break;}
			default: {throw (new Error("invalid mode"));}
		}
	}
	
	
	/**
	 */
	export function view_mode_decode(
		view_mode_encoded : string
	) : _dali.type.enum_view_mode
	{
		const map : Record<string, _dali.type.enum_view_mode> = {
			"week": _dali.type.enum_view_mode.week,
			"list": _dali.type.enum_view_mode.list,
		};
		if (! (view_mode_encoded in map))
		{
			throw (new Error("invalid mode: " + view_mode_encoded));
		}
		else
		{
			return map[view_mode_encoded];
		}
	}
	
	
	/**
	 */
	export function view_mode_determine(
		mode_descriptor : string
	) : _dali.type.enum_view_mode
	{
		if (mode_descriptor === "auto")
		{
			return (
				(window.innerWidth >= 800)
				?
				_dali.type.enum_view_mode.week
				:
				_dali.type.enum_view_mode.list
			);
		}
		else
		{
			return view_mode_decode(mode_descriptor);
		}
	}	

}
