<?php 
$function = new Twig_SimpleFunction('botonesSinTexto', function ($texto) {
    Botones::sinTexto($texto);
});
$twig->addFunction($function);


$function = new Twig_SimpleFunction('boton', function ($tipo, $operacion = null, $funcion = null, $texto = null, $icono = null, $clase = null) {
    if(is_null($texto)):
        echo Botones::$tipo($operacion, $funcion);
    else:
        echo Botones::$tipo($operacion, $funcion, $texto, $icono, $clase);
    endif;
});
$twig->addFunction($function);


$function = new Twig_SimpleFunction('imagenTooltip', function ($idElemento, $srcImagen) {
    echo '<div class="titulo-flotante" data-tooltip-content="#'.$idElemento.'" ><i class="fa fa-picture-o" aria-hidden="true"></i>';
    echo '<div class="tooltip_imagen">'.
            '<span id="'.$idElemento.'">'.'<img src="'.$srcImagen.'" />'.'</span>'.
        '</div>';
    echo '</div>';
});
$twig->addFunction($function);


$function = new Twig_SimpleFunction('pdfTooltip', function ($idElemento, $srcPDF) {
    echo '<div class="titulo-flotante" data-tooltip-content="#'.$idElemento.'" ><i class="fa fa-file-pdf-o fa-lg" aria-hidden="true"></i>';
    echo '<div class="tooltip_imagen">'.
            '<span id="'.$idElemento.'">'.
                '<iframe src="'.$srcPDF.'" style="border:0px #ffffff none;" name="myiFrame" scrolling="no" frameborder="1" marginheight="0px" marginwidth="0px" height="400px" width="600px" allowfullscreen></iframe>'.
            '</span>'.
        '</div>';
    echo '</div>';
});
$twig->addFunction($function);


$function = new Twig_SimpleFunction('labelEstado', function ($estadoCODIGO, $estadoTITULO = '') {
    if(empty($estadoTITULO)){ $estadoTITULO = $estadoCODIGO; }
    echo '<span class="label label-default label-'.$estadoCODIGO.'">'.$estadoTITULO.'</span>'; 
});
$twig->addFunction($function);


$function = new Twig_SimpleFunction('enlace', function ( $enlaceURL, $enlaceTITULO = '') {
    if(!empty($enlaceURL))
        echo '<a class="btn-link" href="javascript:void(0)" onclick="popUp(\''.htmlspecialchars($enlaceURL).'\', \''.$enlaceURL.'\');" >'.$enlaceTITULO.'<i class="fa fa-external-link" aria-hidden="true"></i></a>'; 
});
$twig->addFunction($function);

$function = new Twig_SimpleFunction('mostrarVista', function ($componente, $vista, $datos = array()) {
   Vistas::mostrar($componente, $vista, $datos);
});
$twig->addFunction($function);

$function = new Twig_SimpleFunction('tableTooltip', function ($idElemento, $componente, $controlador, $operacion, $datos=null) {
    echo    '<div class="titulo-flotante" id="'.$idElemento.'" ><i class="fa fa-table fa-lg" aria-hidden="true"></i>';
    echo    '<script type="text/javascript" >'.
                '$("#' . $idElemento . '").tooltipster({'.
                    'content: "Cargando...",'.
                    'contentAsHTML: true, '.
                    'functionBefore: function(instance, helper) {'.
                        'var $origin = $(helper.origin);'.
                        'if ($origin.data("loaded") != true) {'.
                            'ejecutarOperacionHTML('.
                            '"'. $componente . '", "'. $controlador . '", "'. $operacion . '", "'. $datos . '",'.
                            'function (html) {'.
                                'instance.content(html);'.
                                '$origin.data("loaded", true);'.
                            '}, false);'.
                        '}'.
                    '}'.
                '});'.
            '</script>';
    echo '</div>';
});
$twig->addFunction($function);
