:: locationScripts[script]
setup.connections ??= {};

setup.getConnection = function(from, to){
	let passages = [from,to].sort();
	let connectionId = passages.join('_');
	return setup.connections[connectionId] ?? {time: 9};
}

:: LocationMacros[widget]
<!-- USAGE EXAMPLE: <<ConnectedLocation 'Exit the room' 'korrPar' '' 'locations/pavlovsk/resident/apartment/home/korrPar.webp' 1 >> -->
<<widget 'Connection'>>
	<<set _from to _args[0]>>
	<<set _to to _args[1]>>

	<<set _connection = setup.getConnection(_from,_to)>>
	<<set _destinationData = setup.getLocation(_to)>>
	<<ConnectedLocation _destinationData.label _to '' _destinationData.image _connection.time>>
<</widget>>



<!-- For internal use. Provides nothing but the dom. Should be attached to the right postion by another script (currently PassageDone) -->
<<widget 'ConnectedLocationDom'>>
	<!-- settings is of type ConnectedLocation -->
    <<set _settings to _args[0]>>
	<<if $pc.vehicleCanEnterPassage(_settings.targetPassage ?? '')>>
		<div @class=_settings.class>
			<<if _settings.indecencyBlocked && $pc.isIndecent>>
				<div class="indecentBlock">
					Blocked
				</div>
			<</if>>
			<<capture _settings>>
				<<link "">>
					<<= setup.connectionExecute(_settings)>>
				<</link>>
			<</capture>>
			<<image _settings.image>>
			<div class="label">_settings.label</div>
			<<if _settings.duration>>
				<div class="duration_label"><<duration `Math.abs(_settings.duration)`>></div>
			<</if>>
		</div>
	<</if>>
<</widget>>
