<?php


namespace App\Components\Sidebar\SidebarMenu\Controls;


use App\Components\Sidebar\SidebarMenu\TSidebarMenuNode;

class LinkGroup extends BaseControl implements IActiveNode
{
    use TSidebarMenuNode;

    protected $expand = false;

    public function render()
    {
        $this->template->isActive = $this->isActive();
        $this->template->nodes = $this->getComponents();
        $this->renderTemplate('group');
    }

    public function isActive()
    {
        foreach ($this->getComponents() as $component) {
            if ($component instanceof IActiveNode) {
                if ($component->isActive()) {
                    return true;
                }
            }
        }

        return false;
    }

    public function expand($expand = true)
    {
        $this->expand =  $expand;
    }

    protected function renderTemplate($template)
    {
        $this->template->expand = $this->expand;

        parent::renderTemplate($template);
    }


}