<?php
namespace JetStudioModule\DataModel;

use Jet\Http_Request;
use Jet\Tr;
use Jet\UI;
use Jet\UI_badge;

$current = DataModels::getCurrentModel();

if(
	!$current ||
	!$current->getExternalRelations()
) {
	return;
}

$current_relation_name = DataModels::getCurrentRelationName();

?>
<table style="width: 100%">
	<tr>
		<td><b><?= Tr::_( 'External relations' ) ?></b></td>
	</tr>

	<?php foreach( $current->getExternalRelations() as $relation ): ?>
		<tr>
			<td>
				<?php if( $current_relation_name == $relation->getName() ):
					echo UI::badge(UI_badge::INFO, $relation->getName());
				else: ?>
					<a href="<?= Http_Request::currentURI( ['relation' => $relation->getName()], [
						'property',
						'key'
					] ) ?>"><?= $relation->getName() ?></a>
				<?php endif; ?>
			</td>
		</tr>
	<?php endforeach; ?>
</table>
