from odoo import models, api

class IrUiMenu(models.Model):
    _inherit = 'ir.ui.menu'

    @api.model
    def load_menus(self, debug):
        """
        Override standard menu loading to hide unwanted root menus.
        """
        menus = super(IrUiMenu, self).load_menus(debug)
        
        user = self.env.user
        is_admin = user.has_group('base.group_system')
        
        allowed_menus = ['Online Orders', 'Website', 'Table Reservations', 'Uber Integration', 'Apps', 'Settings']
        
        if 'root' in menus and 'children' in menus['root']:
            new_children = []
            for child_id in menus['root']['children']:
                child_menu = menus.get(child_id)
                if not child_menu:
                    continue
                name = child_menu.get('name')
                
                # Allow matching menus (with fallback for Table Reservation naming variations)
                if name in allowed_menus or name == 'Table Reservation':
                    # Hide Apps and Settings for non-admins
                    if name in ['Apps', 'Settings'] and not is_admin:
                        continue
                    new_children.append(child_id)
            menus['root']['children'] = new_children

        return menus
