import { usePage } from '@inertiajs/react';
import type { Auth } from '@/types/auth';

export function usePermissions() {
    const { auth } = usePage<{ auth: Auth }>().props;
    const permissions = auth?.permissions ?? [];

    function hasPermission(name: string): boolean {
        return permissions.includes(name);
    }

    function hasAnyPermission(names: string[]): boolean {
        return names.some((name) => permissions.includes(name));
    }

    return { permissions, hasPermission, hasAnyPermission };
}
