<?php
if (!function_exists('renderStatTreeLineNodeEdit')) {
    function renderStatTreeLineNodeEdit($line)
    {
        ?>
        <div class="stat-tree-node d-flex align-items-baseline py-1 border-bottom on-hover-aliceblue">
            <span>{{$line->displayLabel()}}</span>
            <span class="ml-2 text-secondary">({{(is_null($line->last_refresh_count) ? '-' : $line->last_refresh_count)}})</span>
            <div moe relative wide class="ml-auto mr-2">
                <a href="#" start show><i class="text-sm fa fa-trash-alt on-hover-opaque text-danger"></i></a>
                <form url="#">Foobar</form>
            </div>
            <div moe relative wide class="mr-2">
                <a href="#" start show class="text-sm">Cols</a>
                <form url="#">Foobar</form>
            </div>
            <div moe relative wide>
                <a href="#" start show class="text-sm">+Child</a>
                <form url="#">Move</form>
            </div>
        </div>
        <?php
        if (count($line->children)) {
            echo '<div class="stat-tree-children">';
            foreach ($line->children as $child) {
                renderStatTreeLineNodeEdit($child);
            }
            echo '</div>';
        }
    }
}
$statTree = \App\Models\StatTree::where('slug', $slug)->first();
?>
@if(@$statTree)
    <div class="d-flex align-items-baseline mb-2">
        <h6 class="font-weight-bold m-0">{{$statTree->name}}</h6>
        <div moe relative wide class="ml-3">
            <a href="#" start show>+ Top Level</a>
            <form url="#">Foobar</form>
        </div>
        <a href="#" class="ml-3">Refresh Counts</a>
    </div>
    <div class="stat-tree-view border mb-3">
        @foreach($statTree->lines as $line)
            @if(!$line->parent_stat_tree_line_id)
                <?php renderStatTreeLineNodeEdit($line); ?>
            @endif
        @endforeach
    </div>
@endif
