:: cheatMenuScript[script]
$(document).on(':passagedisplay', function (ev) {

	// Autocomplete for Goto-Input
	jUIPromise.then(function () {
		var inputId = '#textbox--cheatteleportdestination';
		var tags = Story.lookupWith(function (p) {
			return (p.tags.includes("menu") || p.tags.includes("outdoors") || p.tags.includes("indoors") || p.tags.includes("quest"));
		}).map((passage)=>passage.title);
		$(inputId).autocomplete({
			source: tags
		});

	});

	// Autocomplete for Outfit-Input
	jUIPromise.then(function () {
		var inputId = '#cheatOutfitId';
		var outfitIds = Object.keys(setup.outfits)
		$(inputId).autocomplete({
			source: outfitIds
		});

	});
});

:: cheatMenuWidgets[widget]
<<widget 'cheatMenu'>>
	<div id="cheatMenu" class="collapsed">
		<<link "Cheat Menu">>
			<<toggleclass  '#cheatMenu' 'collapsed'>>
			<<toggleclass  '#cheatMenu' 'expanded'>>
		<</link>>
		<div>
			<<if !_tags.includesAny(['outdoors','indoors'])>>
				<p id="nonSaveState">
					You are currently at a passage that is not save to return to. Using the Cheatmenu here can break various aspects of the game.
				</p>
			<</if>>
			<h2>Finances</h2>
			<p>Cash:
				<<attr "min" 0 "step" 100>>
					<<numberbox "$finances.cash" $finances.cash>>
				<</attr>>
			</p>
			<<confirmButton>>
			
			<h2>Outfits</h2>
			<<set _cheatOutfitId = ''>>
			<<id "cheatOutfitId">>
				<<textbox "_cheatOutfitId" _cheatOutfitId>>
			<</id>>
			<<button 'Wear'>>
				<<run $wardrobe.wear(_cheatOutfitId)>>
				<<regt>>
			<</button>>

			<h2>Teleport</h2>
			<ul class="teleportList">
				<li><<link "Parents Home">><<gt 'korrPar'>><</link>></li>
				<li><<link "Test">><<gt 'test'>><</link>></li>
				<li><<link "Reference Page">><<gt 'Reference'>><</link>></li>
				<li>
					<<textbox "_cheatTeleportDestination" "">>
					<<button 'Go'>>
						<<set _cheatTeleportDestinations = _cheatTeleportDestination.split(",")>>
						<<gt _cheatTeleportDestinations[0] _cheatTeleportDestinations[1]>>
					<</button>>
				</li>
			</ul>

			<h2>Time</h2>
			<<set _cheatTime = {year:$time.year,month:$time.month,day:$time.day,hour:$time.hour,minutes:$time.minutes}>>
			<p>
				<<style "width: 5ch;">><<attr "min" 0 "max" 23>><<numberbox "_cheatTime.hour" _cheatTime.hour>><</attr>><</style>>:
				<<style "width: 5ch;">><<attr "step" 5 "min" 0 "max" 59>><<numberbox "_cheatTime.minutes" _cheatTime.minutes>><</attr>><</style>>
			</p>
			<p>
				<<style "width: 5ch;">><<attr "min" 1 "max" 31>><<numberbox "_cheatTime.day" _cheatTime.day>><</attr>><</style>>.
				<<style "width: 5ch;">><<attr "min" 1 "max" 12>><<numberbox "_cheatTime.month" _cheatTime.month>><</attr>><</style>>.
				<<style "width: 7ch;">><<attr "min" 2016 "max" 2100>><<numberbox "_cheatTime.year" _cheatTime.year>><</attr>><</style>>
			</p>
			<<class 'confirm'>>
				<<button 'Confirm'>>
					<<set $time._now = new Date(Date.UTC(_cheatTime.year, _cheatTime.month - 1, _cheatTime.day, _cheatTime.hour, _cheatTime.minutes));>>
					<<regt>>
				<</button>>
			<</class>>

			<h2>Misc</h2>
			<ul>
				<li><<link 'Remove all mood'>><<run $pc._moodlets = {}>><<regt>><</link>></li>
				<li><<link 'Reset pain'>><<run $pc._pain = _pain = new setup.Pain()>><<regt>><</link>></li>
				<li><<link 'Edit Passage'>><<gt 'editor' $location.passage>><</link>></li>
			</ul>
		</div>
	</div>
<</widget>>

<<widget 'addTimeLink'>>
    <<set _minutes =_args[1]>>
    <<set _label = _args[0]>>
    <<capture _minutes>>
        <<link _label>>
            <<set _cachedTimeFactor = $pc.timeFactor>>
            <<set $pc.timeFactor = 0>>
            <<set $time.minutes += _minutes>>
            <<set $pc.timeFactor = _cachedTimeFactor>>
            <<regt>>
        <</link>>
    <</capture>>
<</widget>>

<<widget 'confirmButton'>>
	<<class 'confirm'>><<button 'Confirm'>><<regt>><</button>><</class>>
<</widget>>