<?php

namespace App\View\Components;

use Illuminate\View\Component;
use Illuminate\Support\Facades\Auth;
use App\Models\Settings;
use App\Models\RoleUser;
use App\Models\User;

class Sidebar extends Component
{



    /**
     * Create a new component instance.
     *
     * @return void
     */
    public function __construct()
    {
        //
    }

    /**
     * Get the view / contents that represent the component.
     *
     * @return \Illuminate\Contracts\View\View|\Closure|string
     */
    public function render()
    {
        $options = $this->getOptions();
        return view('components.sidebar', [
            "options" => $options
        ]);
    }

    /**
     * 
     */
    private function getOptionAppointment()
    {
        $primary = '<a href="#submenu1" data-bs-toggle="collapse" class="nav-link px-0 align-middle">
        <span class="ms-1 d-none d-sm-inline">' . __("options.nav.appointments.title") . '</span> 
        &nbsp;&nbsp;&nbsp;<img style="width:30px;display:inline" src="' . asset("img/calendar.png") . '">
        </a>';
        $childOne = '<li class="w-100">
            <a href="/admin/view-appointments" class="nav-link px-0"> 
                <span class="d-none d-sm-inline">
                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' . __("options.nav.appointments.view") . '
                </span> 
            </a>
        </li>';
        $childTwo = '<li class="w-100">
            <a href="/admin/create-appointment" class="nav-link px-0"> 
                <span class="d-none d-sm-inline">
                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' . __("options.nav.appointments.create") . '
                </span> 
            </a>
        </li>';
        $childThree = '<li class="w-100">
            <a href="/admin/appointment-payment-relation" class="nav-link px-0"> 
                <span class="d-none d-sm-inline">
                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Relación de Citas y Pagos
                </span> 
            </a>
        </li>';

        $secondary = '<ul class="collapse nav flex-column ms-1" id="submenu1" data-bs-parent="#menu">';
        if (Auth::user()->isAbleTo('view-appointment')) {
            $secondary .= $childOne;
        }
        if (Auth::user()->isAbleTo('create-appointment')) {
            $secondary .= $childTwo;
        }
        if (Auth::user()->isAbleTo('view-appointment')) {
            $secondary .= $childThree;
        }
        $secondary .= '</ul>';

        if (Auth::user()->isAbleTo('view-appointment') || Auth::user()->isAbleTo('create-appointment')) {
            return  '<li>' . $primary . $secondary . '</li>';
        } else {
            return "";
        }
    }



    /**
     * 
     */
    private function getOptionPatient()
    {
        $accessMode = Settings::getAccessMode();
        $primary = '<a href="#submenu2" data-bs-toggle="collapse" class="nav-link px-0 align-middle">
        <span class="ms-1 d-none d-sm-inline">' . __("options.nav.patients.title") . '</span> 
        &nbsp;&nbsp;&nbsp;<img style="width:30px;display:inline" src="' . asset("img/heart.png") . '">
        </a>';
        $childOne = '<li class="w-100">
        <a href="/admin/view-patients" class="nav-link px-0"> 
            <span class="d-none d-sm-inline">
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' . __("options.nav.patients.view") . '
            </span> 
        </a>
    </li>';
        $childTwo = '<li class="w-100">
        <a href="/admin/create-patient" class="nav-link px-0"> 
            <span class="d-none d-sm-inline">
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' . __("options.nav.patients.create") . '
            </span> 
        </a>
    </li>';
        $childThree = '<li class="w-100">
        <a href="/admin/view-histories" class="nav-link px-0"> 
            <span class="d-none d-sm-inline">
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' . __("options.nav.patients.histories") . '
            </span> 
        </a>
    </li>';
        $secondary = '<ul class="collapse nav flex-column ms-1" id="submenu2" data-bs-parent="#menu">';
        if (Auth::user()->isAbleTo('view-patient')) {
            $secondary .= $childOne;
        }
        if (Auth::user()->isAbleTo('create-patient')) {
            $secondary .= $childTwo;
        }
        if (Auth::user()->isAbleTo('view-history') && (in_array(Settings::HISTORY_ONLY_MODE, $accessMode) || in_array(Settings::FULL_ACCESS_MODE, $accessMode))) {
            $secondary .= $childThree;
        }
        $secondary .= '</ul>';
        if (Auth::user()->isAbleTo('view-patient') || Auth::user()->isAbleTo('create-patient')  || Auth::user()->isAbleTo('view-history')) {
            return  '<li>' . $primary . $secondary . '</li>';
        } else {
            return "";
        }
    }


    /**
     * 
     */
    private function getOptionHistory()
    {
        $primary = '<a href="#submenu3" data-bs-toggle="collapse" class="nav-link px-0 align-middle">
        <span class="ms-1 d-none d-sm-inline">' . __("options.nav.patients.histories") . '</span> 
        &nbsp;&nbsp;&nbsp;<img style="width:30px;display:inline" src="' . asset("img/folder.png") . '">
        </a>';
        $childThree = '<li class="w-100">
        <a href="/admin/view-histories" class="nav-link px-0"> 
            <span class="d-none d-sm-inline">
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' . __("options.nav.patients.histories") . '
            </span> 
        </a>
    </li>';
        /* $childTwo = '<li class="w-100">
        <a href="create-history" class="nav-link px-0"> 
            <span class="d-none d-sm-inline">
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'.__("options.optionFour").'
            </span> 
        </a>
    </li>';*/

        $secondary = '<ul class="collapse nav flex-column ms-1" id="submenu3" data-bs-parent="#menu">';
        if (Auth::user()->isAbleTo('view-history')) {
            $secondary .= $childThree;
        }
        /* if(Auth::user()->isAbleTo('create-history')){
            $secondary.= $childTwo;
        }*/
        $secondary .= '</ul>';

        if (Auth::user()->isAbleTo('view-history') || Auth::user()->isAbleTo('create-history')) {
            return  '<li>' . $primary . $secondary . '</li>';
        } else {
            return "";
        }
    }


    /**
     * 
     */
    private function getOptionEmail()
    {
        $primary = '<a href="#submenu9" data-bs-toggle="collapse" class="nav-link px-0 align-middle">
        <span class="ms-1 d-none d-sm-inline">' . __("options.nav.email.title") . '</span> 
        &nbsp;&nbsp;&nbsp;<img style="width:30px;display:inline" src="' . asset("img/email.png") . '">
        </a>';
        $childOne = '<li class="w-100">
        <a href="/admin/view-email" class="nav-link px-0"> 
            <span class="d-none d-sm-inline">
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' . __("options.nav.email.inbox") . '
            </span> 
        </a>
    </li>';
        $childTwo = '<li class="w-100">
        <a href="/admin/view-email-out" class="nav-link px-0"> 
            <span class="d-none d-sm-inline">
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' . __("options.nav.email.sent") . '
            </span> 
        </a>
    </li>';

        $secondary = '<ul class="collapse nav flex-column ms-1" id="submenu9" data-bs-parent="#menu">';
       // if (Auth::user()->isAbleTo('view-user')) {
            $secondary .= $childOne;
       // }
       // if (Auth::user()->isAbleTo('create-user')) {
            $secondary .= $childTwo;
        //}
        $secondary .= '</ul>';

        //if (Auth::user()->isAbleTo('view-user') || Auth::user()->isAbleTo('create-user')) {
            return  '<li>' . $primary . $secondary . '</li>';
       // } else {
         //   return "";
        //}
    }


    /**
     * 
     */
    private function getOptionUser()
    {
        $primary = '<a href="#submenu4" data-bs-toggle="collapse" class="nav-link px-0 align-middle">
        <span class="ms-1 d-none d-sm-inline">' . __("options.nav.users.title") . '</span> 
        &nbsp;&nbsp;&nbsp;<img style="width:30px;display:inline" src="' . asset("img/patients.png") . '">
        </a>';
        $childOne = '<li class="w-100">
        <a href="/admin/view-users" class="nav-link px-0"> 
            <span class="d-none d-sm-inline">
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' . __("options.nav.users.view") . '
            </span> 
        </a>
    </li><li class="w-100">
        <a href="/admin/view-doctors" class="nav-link px-0"> 
            <span class="d-none d-sm-inline">
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' . __("options.nav.users.view_doctors") . '
            </span> 
        </a>
    </li>';
        $childTwo = '<li class="w-100">
        <a href="/admin/create-users" class="nav-link px-0"> 
            <span class="d-none d-sm-inline">
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' . __("options.nav.users.create") . '
            </span> 
        </a>
    </li><li class="w-100">
        <a href="/admin/create-users?newDoctor=true" class="nav-link px-0"> 
            <span class="d-none d-sm-inline">
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' . __("options.nav.users.create_doctor") . '
            </span> 
        </a>
    </li>';

        $childThree = '<li class="w-100">
        <a href="/admin/schedules" class="nav-link px-0"> 
            <span class="d-none d-sm-inline">
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' . __("options.nav.users.doctor_schedules") . '
            </span> 
        </a>
    </li>';

        $secondary = '<ul class="collapse nav flex-column ms-1" id="submenu4" data-bs-parent="#menu">' . 
            $childOne . $childTwo . $childThree .
        '</ul>';

        if (Auth::user()->isAbleTo('view-user') || Auth::user()->isAbleTo('create-user')) {
            return  '<li>' . $primary . $secondary . '</li>';
        } else {
            return "";
        }
    }


    /**
     * 
     */
    private function getOptionAreas()
    {
        $primary = '<a href="#submenu5" data-bs-toggle="collapse" class="nav-link px-0 align-middle">
        <span class="ms-1 d-none d-sm-inline">' . __("options.nav.areas.title") . '</span> 
        &nbsp;&nbsp;&nbsp;<img style="width:30px;display:inline" src="' . asset("img/areas.png") . '">
        </a>';
        $childOne = '<li class="w-100">
        <a href="/admin/create-areas" class="nav-link px-0"> 
            <span class="d-none d-sm-inline">
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' . __("options.nav.areas.view") . '
            </span> 
        </a>
    </li>';
        /*$childTwo = '<li class="w-100">
        <a href="create-areas" class="nav-link px-0"> 
            <span class="d-none d-sm-inline">
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'.__("options.optionIleven").'
            </span> 
        </a>
    </li>';*/

        $secondary = '<ul class="collapse nav flex-column ms-1" id="submenu5" data-bs-parent="#menu">';
        if (Auth::user()->isAbleTo('view-area')) {
            $secondary .= $childOne;
        }
        /*if(Auth::user()->isAbleTo('create-area')){
            $secondary.= $childTwo;
        }*/
        $secondary .= '</ul>';

        if (Auth::user()->isAbleTo('view-area') || Auth::user()->isAbleTo('create-area')) {
            return  '<li>' . $primary . $secondary . '</li>';
        } else {
            return "";
        }
    }

    /**
     * 
     */
    private function getOptionConfig()
    {
        $primary = '<a href="#submenu6" data-bs-toggle="collapse" class="nav-link px-0 align-middle">
        <span class="ms-1 d-none d-sm-inline">' . __("options.nav.config.title") . '</span> 
        &nbsp;&nbsp;&nbsp;<img style="width:30px;display:inline" src="' . asset("img/settings.png") . '">
        </a>';
        $childOne = '<li class="w-100">
        <a href="/admin/view-config" class="nav-link px-0"> 
            <span class="d-none d-sm-inline">
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' . __("options.nav.config.general") . '
            </span> 
        </a>
        </li>';
        
        $childTwo = '<li class="w-100">
        <a href="/admin/audits" class="nav-link px-0"> 
            <span class="d-none d-sm-inline">
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' . __("options.nav.config.audits") . '
            </span> 
        </a>
        </li>';
        
        $childThree = '<li class="w-100">
        <a href="' . route('clinic-identity.index') . '" class="nav-link px-0"> 
            <span class="d-none d-sm-inline">
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' . __("options.nav.config.clinic_identity") . '
            </span> 
        </a>
        </li>';
        
        $childFour = '<li class="w-100">
        <a href="' . route('routes.index') . '" class="nav-link px-0"> 
            <span class="d-none d-sm-inline">
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' . __("common.route-permissions") . '
            </span> 
        </a>
        </li>';


        $childFive = '<li class="w-100">
            <a href="/admin/patient-custom-fields" class="nav-link px-0"> 
                <span class="d-none d-sm-inline">
                    <i class="bi bi-card-list me-2"></i> ' . __('patient-custom-fields.menu_title') . '
                </span> 
            </a>
        </li>';
        
        $childSix = '<li class="w-100">
            <a href="/admin/appointment-tags" class="nav-link px-0"> 
                <span class="d-none d-sm-inline">
                    <i class="bi bi-tags me-2"></i> ' . __('appointment-tags.menu_title') . '
                </span> 
            </a>
        </li>';
        
        

        $secondary = '<ul class="collapse nav flex-column ms-1" id="submenu6" data-bs-parent="#menu">';
        if (Auth::user()->hasRole('root')) {
            $secondary .= $childOne;
        }
        if (Auth::user()->hasRole(['admin', 'root'])) {
            $secondary .= $childTwo;
        }
       /* if (Auth::user()->isAbleTo('audits')) {
            $secondary .= $childTwo;
        }*/
        // Clinic Identity
        if (Auth::user()->isAbleTo(['view-config'])) {
            $secondary .= $childThree;
        }
        // Route Permissions
        if (Auth::user()->isAbleTo(['manage-routes'])) {
            $secondary .= $childFour;
        }
        // Campos personalizados de pacientes
        if (Auth::user()->isAbleTo(['view-config'])) {
            $secondary .= $childFive;
        }
        // Etiquetas de citas
        if (Auth::user()->isAbleTo(['view-config'])) {
            $secondary .= $childSix;
        }
        $secondary .= '</ul>';

        if (Auth::user()->isAbleTo('view-user') || Auth::user()->isAbleTo('create-user')) {
            return  '<li>' . $primary . $secondary . '</li>';
        } else {
            return "";
        }
    }

    /**
     * 
     */
    public function getOptions(): array
    {
        $accessMode = Settings::getAccessMode();
        $userRoleId = RoleUser::getRolShortname(Auth::user());
        $options = [];

        // 1. Inicio
        array_push($options, $this->getHomeOption());

        // 2. Gestión de Pacientes
        array_push($options, $this->createCategoryHeader(__('options.categories.patients')));
        array_push($options, $this->getOptionPatient());
        if (Auth::user()->isAbleTo('view-appointment') || Auth::user()->isAbleTo('create-appointment')) {
            array_push($options, $this->getOptionAppointment());
        }
        array_push($options, $this->getOptionHistory());

        // 3. Gestión Financiera
        array_push($options, $this->createCategoryHeader(__('options.categories.financial')));
        
        if (Auth::user()->isAbleTo('view-payments') || Auth::user()->isAbleTo('create-payments')) {
            array_push($options, $this->getOptionPayments());
        }
        
        // Presupuestos (ahora independiente)
        if (Auth::user()->isAbleTo('view-budget') || Auth::user()->isAbleTo('create-budget')) {
            array_push($options, $this->getOptionBudgets());
        }
        
       // if (Auth::user()->isAbleTo('view-medicalServices') || Auth::user()->isAbleTo('create-medicalServices')) {
            array_push($options, $this->getOptionMedicalServices());
        //}

        // 4. Comunicaciones
        array_push($options, $this->createCategoryHeader(__('options.categories.communications')));
        array_push($options, $this->getOptionEmail());

        // 5. Administración
        array_push($options, $this->createCategoryHeader(__('options.categories.administration')));
        array_push($options, $this->getOptionAreas());
        array_push($options, $this->getOptionUser());
        
        // Añadir el menú de inventario en la sección de Administración
        array_push($options, $this->getOptionInventory());
        
        // Horarios de Doctor (solo para doctores)
        if (User::isADoctor(Auth::user())) {
            array_push($options, $this->getOptionDoctorSchedules());
        }

        // 6. Configuración y Utilidades
        array_push($options, $this->createCategoryHeader(__('options.categories.settings')));
        array_push($options, $this->getUtilities());
        if (Auth::user()->isAbleTo('view-config')) {
            array_push($options, $this->getOptionConfig());
        }

        // 7. Cerrar Sesión
        array_push($options, $this->getLogoutOption());

        return $options;
    }

    private function createCategoryHeader(string $title): string
    {
        return '<li class="nav-item">
            <div class="category-header px-3 py-2 text-muted">
                <strong>' . $title . '</strong>
            </div>
        </li>';
    }

    private function getHomeOption(): string
    {
        return '<li class="nav-item">
            <a href="/admin/dashboard" class="nav-link align-middle px-0">
                <span class="ms-1 d-none d-sm-inline">' . __("options.nav.home") . '</span>
                &nbsp;&nbsp;&nbsp;<img style="width:30px;display:inline" src="' . asset("img/home.png") . '">
            </a>
        </li>';
    }

    
    private function getLogoutOption(): string
    {
        return '<li class="nav-item">
            <a href="#" data-bs-toggle="modal" data-bs-target="#modalLogout" class="nav-link align-middle px-0">
                <span class="ms-1 d-none d-sm-inline">' . __("options.nav.logout") . '</span>
                &nbsp;&nbsp;&nbsp;<img style="width:30px;display:inline" src="' . asset("img/logout.png") . '">
            </a>
        </li>';
    }

    /**
     * 
     */
    public function getOptionPayments(): string
    {
        $primary = '<a href="#submenu8" data-bs-toggle="collapse" class="nav-link px-0 align-middle">
         <span class="ms-1 d-none d-sm-inline">' . __("options.nav.payments.title") . '</span> 
        &nbsp;&nbsp;&nbsp;<img style="width:30px;display:inline" src="' . asset("img/money.png") . '">
        </a>';
        
        $secondary = '<ul class="collapse nav flex-column ms-1" id="submenu8" data-bs-parent="#menu">';
        
        // Ver pagos
       /* if (Auth::user()->isAbleTo('view-payments')) {
            $secondary .= '<li class="w-100">
                <a href="/admin/view-payments" class="nav-link px-0"> 
                    <span class="d-none d-sm-inline">
                    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' . __("options.nav.payments.view") . '
                    </span> 
                </a>
            </li>';
        }

        // Crear pagos
        if (Auth::user()->isAbleTo('create-payments')) {
            $secondary .= '<li class="w-100">
                <a href="/admin/create-payment" class="nav-link px-0"> 
                    <span class="d-none d-sm-inline">
                    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' . __("options.nav.payments.create") . '
                    </span> 
                </a>
            </li>';
        }*/

        // Gestionar monedas
        if (Auth::user()->hasRole(['admin', 'root'])) {
            $secondary .= '<li class="w-100">
                <a href="/admin/create-currency" class="nav-link px-0"> 
                    <span class="d-none d-sm-inline">
                    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' . __("options.nav.payments.currency") . '
                    </span> 
                </a>
            </li>';
        }

        // Métodos de pago
        if (Auth::user()->isAbleTo('view-payment-method')) {
            $secondary .= '<li class="w-100">
                <a href="/admin/create-payments-method" class="nav-link px-0"> 
                    <span class="d-none d-sm-inline">
                    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' . __("options.nav.payments.methods") . '
                    </span> 
                </a>
            </li>';
        }

        $secondary .= '</ul>';

        // Solo mostrar el menú si el usuario tiene al menos uno de los permisos necesarios
        if (Auth::user()->isAbleTo(['view-payment', 'create-payment', 'view-payment-method']) 
            || Auth::user()->hasRole(['admin', 'root'])) {
            return '<li>' . $primary . $secondary . '</li>';
        }
        
        return "";
    }

    /**
     * Opciones de Horarios de Doctor (solo horarios del doctor en sesión)
     * 
     * @return string
     */
    public function getOptionDoctorSchedules(): string
    {
        $primary = '<a href="#submenuSchedules" data-bs-toggle="collapse" class="nav-link px-0 align-middle">
        <span class="ms-1 d-none d-sm-inline">' . __("doctor-schedules.my_schedules") . '</span> 
        &nbsp;&nbsp;&nbsp;<img style="width:30px;display:inline" src="' . asset("img/calendar.png") . '">
        </a>';
        
        $childOne = '<li class="w-100">
            <a href="/admin/doctor/schedules" class="nav-link px-0"> 
                <span class="d-none d-sm-inline">
                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' . __("doctor-schedules.view_my_schedules") . '
                </span> 
            </a>
        </li>';
        
        $childTwo = '<li class="w-100">
            <a href="/admin/doctor/schedules/create" class="nav-link px-0"> 
                <span class="d-none d-sm-inline">
                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' . __("doctor-schedules.create_schedule") . '
                </span> 
            </a>
        </li>';

        $secondary = '<ul class="collapse nav flex-column ms-1" id="submenuSchedules" data-bs-parent="#menu">';
        
        // Solo mostrar al doctor sus propios horarios
        if (User::isADoctor(Auth::user())) {
            $secondary .= $childOne;
            $secondary .= $childTwo;
        }
        
        $secondary .= '</ul>';

        // Solo mostrar esta sección si es un doctor
        if (User::isADoctor(Auth::user())) {
            return '<li>' . $primary . $secondary . '</li>';
        } else {
            return "";
        }
    }

    /**
     * 
     */
    public function getUtilities(): string
    {
        $primary = '<a href="#submenu7" data-bs-toggle="collapse" class="nav-link px-0 align-middle">
        <span class="ms-1 d-none d-sm-inline">' . __("options.nav.utilities.title") . '</span> 
        &nbsp;&nbsp;&nbsp;<img style="width:30px;display:inline" src="' . asset("img/settings.png") . '">
        </a>';
        
        $childOne = '<li class="w-100">
        <a href="/admin/xray-edit" class="nav-link px-0"> 
            <span class="d-none d-sm-inline">
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' . __("options.nav.utilities.xray") . '
            </span> 
        </a>
        </li>';

        $childTwo = '<li class="w-100">
        <a href="/admin/utilities/imc" class="nav-link px-0"> 
            <span class="d-none d-sm-inline">
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' . __("options.nav.utilities.imc") . '
            </span> 
        </a>
        </li>';

        $childThree = '<li class="w-100">
        <a href="/admin/utilities/converter" class="nav-link px-0"> 
            <span class="d-none d-sm-inline">
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' . __("options.nav.utilities.converter") . '
            </span> 
        </a>
        </li>';

        $childFour = '<li class="w-100">
        <a href="/admin/utilities/vaccination" class="nav-link px-0"> 
            <span class="d-none d-sm-inline">
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' . __("options.nav.utilities.vaccination") . '
            </span> 
        </a>
        </li>';

        $secondary = '<ul class="collapse nav flex-column ms-1" id="submenu7" data-bs-parent="#menu">';
        
        if(Auth::user()->isAbleTo('xray-edit')){
            $secondary .= $childOne;
        }
        
        // Nuevas utilidades disponibles para todos los roles médicos
        if(Auth::user()->hasRole('doctor|admin|root')){
            $secondary .= $childTwo; // Calculadora IMC
            $secondary .= $childThree; // Convertidor
           // $secondary .= $childFour; // Calendario vacunación
        }

        $secondary .= '</ul>';

        // Mostrar menú si tiene acceso a rayos X o es personal médico
        if(Auth::user()->isAbleTo('xray-edit') || Auth::user()->hasRole('doctor|admin|root')){
            return '<li>'.$primary.$secondary.'</li>';
        }else{
            return "";
        }
    }

    /**
     * Opción de Servicios Médicos para el menú
     */
    private function getOptionMedicalServices(): string
    {
        $primary = '<a href="#submenu10" data-bs-toggle="collapse" class="nav-link px-0 align-middle">
            <span class="ms-1 d-none d-sm-inline">' . __("options.nav.medical_services.title") . '</span> 
            &nbsp;&nbsp;&nbsp;<i class="bi bi-heart-pulse fs-5"></i>
        </a>';
        
        $childOne = '<li class="w-100">
            <a href="' . route('/admin/view-medical-services') . '" class="nav-link px-0"> 
                <span class="d-none d-sm-inline">
                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' . __("options.nav.medical_services.view") . '
                </span> 
            </a>
        </li>';
        
        $childTwo = '<li class="w-100">
            <a href="' . route('/admin/create-medical-services') . '" class="nav-link px-0"> 
                <span class="d-none d-sm-inline">
                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' . __("options.nav.medical_services.create") . '
                </span> 
            </a>
        </li>';

        $secondary = '<ul class="collapse nav flex-column ms-1" id="submenu10" data-bs-parent="#menu">';
        if (Auth::user()->isAbleTo('view-medical-service')) {
            $secondary .= $childOne;
        }
        if (Auth::user()->isAbleTo('create-medical-service')) {
            $secondary .= $childTwo;
        }
        $secondary .= '</ul>';

        if (Auth::user()->isAbleTo('view-medical-service') || Auth::user()->isAbleTo('create-medical-service')) {
            return  '<li>' . $primary . $secondary . '</li>';
        }
        return "";
    }

    /**
     * Opción de Presupuestos para el menú
     */
    private function getOptionBudgets(): string
    {
        $primary = '<a href="#submenuBudgets" data-bs-toggle="collapse" class="nav-link px-0 align-middle">
        <span class="ms-1 d-none d-sm-inline">' . __("options.nav.budgets.title") . '</span> 
        &nbsp;&nbsp;&nbsp;<i class="fas fa-file-invoice-dollar fs-5"></i>
        </a>';
        
        $secondary = '<ul class="collapse nav flex-column ms-1" id="submenuBudgets" data-bs-parent="#menu">';
        
        // Ver presupuestos
        if (Auth::user()->isAbleTo('view-budget')) {
            $secondary .= '<li class="w-100">
                <a href="' . route('budgets.index') . '" class="nav-link px-0"> 
                    <span class="d-none d-sm-inline">
                    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' . __("options.nav.budgets.view") . '
                    </span> 
                </a>
            </li>';
        }

        // Crear presupuestos
        if (Auth::user()->isAbleTo('create-budget')) {
            $secondary .= '<li class="w-100">
                <a href="' . route('budgets.create') . '" class="nav-link px-0"> 
                    <span class="d-none d-sm-inline">
                    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' . __("options.nav.budgets.create") . '
                    </span> 
                </a>
            </li>';
        }

        $secondary .= '</ul>';

        // Solo mostrar el menú si el usuario tiene al menos uno de los permisos necesarios
        if (Auth::user()->isAbleTo(['view-budget', 'create-budget'])) {
            return '<li>' . $primary . $secondary . '</li>';
        }
        
        return "";
    }

    /**
     * Opciones del módulo de Inventario
     * 
     * @return string
     */
    private function getOptionInventory(): string
    {
        $primary = '<a href="#submenuInventory" data-bs-toggle="collapse" class="nav-link px-0 align-middle">
        <span class="ms-1 d-none d-sm-inline">Inventario</span> 
        &nbsp;&nbsp;&nbsp;<i class="fas fa-boxes fs-5"></i>
        </a>';
        
        $secondary = '<ul class="collapse nav flex-column ms-1" id="submenuInventory" data-bs-parent="#menu">';
        
        // Ver productos
        $secondary .= '<li class="w-100">
            <a href="' . route('inventory.index') . '" class="nav-link px-0"> 
                <span class="d-none d-sm-inline">
                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Productos
                </span> 
            </a>
        </li>';
        
        // Nuevo producto
        $secondary .= '<li class="w-100">
            <a href="' . route('inventory.create') . '" class="nav-link px-0"> 
                <span class="d-none d-sm-inline">
                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Nuevo Producto
                </span> 
            </a>
        </li>';
        
        // Categorías
        $secondary .= '<li class="w-100">
            <a href="' . route('inventory.categories.index') . '" class="nav-link px-0"> 
                <span class="d-none d-sm-inline">
                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Categorías
                </span> 
            </a>
        </li>';
        
        // Proveedores
        $secondary .= '<li class="w-100">
            <a href="' . route('inventory.suppliers.index') . '" class="nav-link px-0"> 
                <span class="d-none d-sm-inline">
                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Proveedores
                </span> 
            </a>
        </li>';
        
        // Transacciones
        $secondary .= '<li class="w-100">
            <a href="' . route('inventory.transactions.index') . '" class="nav-link px-0"> 
                <span class="d-none d-sm-inline">
                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Transacciones
                </span> 
            </a>
        </li>';
        
        // Stock Bajo
        $secondary .= '<li class="w-100">
            <a href="' . route('inventory.low-stock') . '" class="nav-link px-0"> 
                <span class="d-none d-sm-inline">
                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="text-danger">Stock Bajo</span>
                </span> 
            </a>
        </li>';
        
        $secondary .= '</ul>';
        
        return '<li>' . $primary . $secondary . '</li>';
    }
}
