<?php

Yii::import('zii.widgets.CMenu');

class SBMenu extends CMenu
{
    // centering menu items
    public $centerItems = false;
    public $menuCssClass = 'sidebarMenu';
    public $activeCssClass = 'active';

    public function init()
    {
        parent::init();
    }

    /**
     * Recursively renders the menu items.
     * @param array $items the menu items to be rendered recursively
     */
    protected function renderMenu($items)
    {
        $menuClasses = array($this->menuCssClass);

        echo "\n" . CHtml::openTag('ul', array('class' => implode(' ', $menuClasses))) . "\n";

        foreach ($items as $item) {
            $translationTarget = 'MODULE_NAME_' . $item['label'];

            $options = array('data-translation-target' => 'MODULE_NAME_' . $item['label']);
            if ($item['active']) {
                $options['class'] = $this->activeCssClass;
            }
            echo "\t" . CHtml::openTag('li', $options);
            $image = ModuleManager::getIconForModule($item['name']);
            // Description
            $description = CHtml::tag('div', array(), __($item['description']));

            // Image and title as link
            echo CHtml::link($image . __($item['label']) . $description, $item['url']);

            // FIXME: toggle translate mode on/off here
            if (Yii::app()->user->translateMode) {
                echo '<i data-translation-target="' . $translationTarget . '" data-translation-id="' . $item['label'] . '"></i>';
                echo '<i data-translation-target="' . $translationTarget . '" data-translation-id="' . $item['description'] . '"></i>';
            }
            echo CHtml::closeTag('li') . "\n";
        }
        echo CHtml::closeTag('ul') . "\n";
    }
}
