<?php

use Jet\UI_icon;
use Jet\UI_tree;
use Jet\UI;
use Jet\Data_Tree_Node;
use Jet\MVC_View;

/**
 * @var MVC_View $this
 * @var UI_tree $tree
 */
$tree = $this->getRaw( 'element' );

$icon_width = 22;
$icon_size = UI_icon::SIZE_SMALL;
?>
<div class="tree">
	<?php foreach( $tree->getData() as $node ):

		/**
		 * @var Data_Tree_Node $node
		 */

		if( !$node->getIsRoot() && !$tree->nodeFilter( $node ) ) {
			continue;
		}

		$display_callback = $tree->getNodeRenderer( $node );

		$icon = 'file';
		if( $node->getHasChildren() ) {
			if( $tree->nodeOpened( $node ) ) {
				$icon = 'folder-open';
			} else {
				$icon = 'folder';
			}
		}


		$padding = ($node->getDepth()) * $icon_width;
		?>
		<div class="tree-row-container">
			<div class="tree-row<?= $tree->getSelectedId() == $node->getId() ? ' selected' : '' ?>">
				<div class="tree-row-icon-container" style="padding-left: <?= $padding; ?>px;">
					<?= UI::icon( $icon )->setSize( $icon_size )?>
				</div>
				<div class="tree-row-node-container"><?= $display_callback( $node, $node->getData() ); ?></div>
			</div>
		</div>

	<?php endforeach; ?>
</div>


