:: MsgMacros[widget]
<<widget 'msg'>>
	<<set _label = _args[0]>>
	<<set _class = 'message '>>
	<<if _args[1]>>
		<<set _class += _args[1]>>
	<</if>>

	<<if !$msg_queue>><<set $msg_queue = {}>><</if>>

	<<if !(_label in $msg_queue)>>
		<<set $msg_queue[_label] = _class>>
	<</if>>
	<<if _messagingExecuted>>
		<<msgPresent _label _class>>
	<</if>>
<</widget>>

<<widget 'msgPredefined'>>
	<<switch _args[0]>>

		<<case "warn_hydra_low">>
			<<msg "Your dehydration has a decremental effect on your health." "warning">>
		<<case "warn_mood_low">>
			<<msg "Your low mood has a decremental effect on your (mental) health." "warning">>
		<<case "warn_sleep_low">>
			<<msg "Forcing yourself to stay awake has a decremental effect on your mood." "warning">>
		<<default>>
			<<msg `"Message Key not found: "+_args[0]` "error">>
	<</switch>>
<</widget>>

<<widget 'msgPresent'>>
	<<set _label = _args[0]>>
	<<set _class = _args[1]>>
	<<if !$messageCounter>>
		<<set $messageCounter = 0>>
	<</if>>
	<<set _messageId = 'message_'+$messageCounter>>
	<<set $messageCounter = ($messageCounter + 1 ) % 1000000>>
	<<capture _label, _class, _messageId>>
		<<done>>
			<<if $('#messagesContainter').length>>
				<<append "#messagesContainter">>
					<div @id='_messageId' @class='_class'>_label</div>
				<</append>>
				<<timed 1s>>
					<<run delete $msg_queue[_label]>>
				<<next 3s>>
					<<addclass  `'#'+_messageId` "hiding">>
				<<next 2s>>
					<<remove  `'#'+_messageId`>>
				<</timed>>
			<</if>>
		<</done>>
	<</capture>>
<</widget>>
