import { usePage } from '@inertiajs/react';
import type { MenuConfig } from '@rutatiina/ui/types/navigation';

/**
 * The application menus. They are built on the server by the installed packages
 * (Rutatiina\Core\Facades\Navigation) and arrive already filtered against the
 * signed-in user's permissions, so nothing has to be hidden here.
 */
export function useAppMenu() {
  const { navigation } = usePage().props;

  const menu = (name: string): MenuConfig => navigation[name] ?? [];

  return {
    menu,
    sidebar: menu('sidebar'),
    mega: menu('mega'),
    megaMobile: menu('mega-mobile'),
    account: menu('account'),
    accountTabs: menu('account.tabs'),
    user: menu('user'),
  };
}
