<?php
if (!function_exists('renderStatTreeLineNode')) {
    function renderStatTreeLineNode($line)
    {
        echo '<div class="stat-tree-node">' .
            $line->displayLabel() .
            '&nbsp;&nbsp;<span class="text-secondary">(' . (is_null($line->last_refresh_count) ? '-' : $line->last_refresh_count) . ')</span>' .
            '</div>';
        if (count($line->children)) {
            echo '<div class="pl-4">';
            foreach ($line->children as $child) {
                renderStatTreeLineNode($child);
            }
            echo '</div>';
        }
    }
}
$statTree = \App\Models\StatTree::where('slug', $slug)->first();
?>
@if(@$statTree)
    <div class="stat-tree-view border mb-3">
        @foreach($statTree->lines as $line)
            @if(!$line->parent_stat_tree_line_id)
                <?php renderStatTreeLineNode($line); ?>
            @endif
        @endforeach
    </div>
@endif
