<?php
/**
 * Plugin NICC Menu Gestion: Menu de accesos a modulos de gestion
 *
 * @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
 * @author  SIE Asesorias
 */

if (!defined('DOKU_INC')) die();

class syntax_plugin_nicclateral extends DokuWiki_Syntax_Plugin {

    public function getType() {
        return 'substition';
    }

    public function getSort() {
        return 155;
    }

    public function connectTo($mode) {
        $this->Lexer->addSpecialPattern('~~lateral~~', $mode, 'plugin_nicclateral');
        $this->Lexer->addSpecialPattern('~~LATERAL~~', $mode, 'plugin_nicclateral');
        $this->Lexer->addSpecialPattern('\{\{lateral\}\}', $mode, 'plugin_nicclateral');
    }

    public function handle($match, $state, $pos, Doku_Handler $handler) {
        return array();
    }

    public function render($mode, Doku_Renderer $renderer, $data) {
        if ($mode !== 'xhtml') return false;

        // Ruta base de imagenes
        $imgBase = DOKU_BASE . 'lib/plugins/nicclateral/images/';
        $imgPath = DOKU_INC . 'lib/plugins/nicclateral/images/';

        // Definir los items del menu con iconos PNG y emojis fallback
        $items = array(
            array(
                'icon' => 'calidad.png',
                'emoji' => '🏆',
                'text' => 'Gestion de Calidad',
                'link' => 'varios:cal'
            ),
            array(
                'icon' => 'rrhh.png',
                'emoji' => '👥',
                'text' => 'Gestion de Recursos Humanos',
                'link' => 'varios:administrativo'
            ),
            array(
                'icon' => 'administrativa.png',
                'emoji' => '📊',
                'text' => 'Gestion Administrativa',
                'link' => 'varios:gad'
            ),
            array(
                'icon' => 'comercial.png',
                'emoji' => '🤝',
                'text' => 'Gestion Comercial',
                'link' => 'varios:com'
            ),
            array(
                'icon' => 'operaciones.png',
                'emoji' => '⚙️',
                'text' => 'Gestion de Operaciones',
                'link' => 'varios:con'
            ),
            array(
                'icon' => 'funciones.png',
                'emoji' => '📋',
                'text' => 'Competencias, Perfiles y Manual de Funciones',
                'link' => 'varios:funciones'
            )
        );

        // Generar HTML
        $html = '<div class="nicc-menu-gestion">';

        foreach ($items as $item) {
            $url = wl($item['link']);
            $iconFile = $imgPath . $item['icon'];
            $useImage = file_exists($iconFile);

            $html .= '<a href="' . $url . '" class="menu-item">';
            $html .= '<div class="item-icon">';

            if ($useImage) {
                $imgUrl = $imgBase . $item['icon'];
                $html .= '<img src="' . $imgUrl . '" alt="' . hsc($item['text']) . '">';
            } else {
                $html .= '<span class="emoji-icon">' . $item['emoji'] . '</span>';
            }

            $html .= '</div>';
            $html .= '<span class="item-text">' . hsc($item['text']) . '</span>';
            $html .= '<span class="item-arrow">&#8594;</span>';
            $html .= '</a>';
        }

        $html .= '</div>';

        $renderer->doc .= $html;
        return true;
    }
}
