<?php

class VstMenuOpcionHorizontal {
	
	protected $url;
	protected $icono;
	protected $titulo;
	protected $label_htm;
	protected $_elementos = array();
	/*
	 * TODO: subopciones
	 * y label_htm
	 */
	
	public function __construct($titulo, $url){
		
		if (strpos($url, 'http://')===false)
			$this->url = BASEURL.'/'.$url;
		else
			$this->url = $url;
		
		if($url == '#'){
			$this->url = '#';
		}
		
		$this->titulo = $titulo;
		
		
	}
	
	public function render(){
		$atributos_li= '';
		$clase_a = '';
		$extra_a = '';
		if(count($this->_elementos)>0){
			$atributos_li = 'class="dropdown"';
			$clase_a = 'class="dropdown-toggle" data-toggle="dropdown"';
			$this->url = 'javascript:void(0);';
			$extra_a = '<b class="caret"></b>';
			
		}
		
		
		
		
		$html = '<li '. $atributos_li .'><a '.$clase_a.' href="'.$this->url.'">'.$this->titulo.$extra_a.'</a>';
		
		if(count($this->_elementos)>0){
			$html .= '<ul class="dropdown-menu">';
			foreach ($this->_elementos as $elemento){
				$html .= $elemento->render();
			}
			$html .= '</ul>';
		}
		
		$html .='</li>';
		
		return $html;
		
	}
	
	function addOpcion (VstMenuOpcionHorizontal $opcion){
		$this->_elementos[] = $opcion;
	}
	
	public function toArray(){
		
		$res = array('title'	=> $this->titulo,
						'url' 	=> $this->url,
						'icon'	=> $this->icono
						);
		return $res;		
		
	}
	
}