/**
 * Capability helpers for the React admin, reading the localized `rbfb`
 * bootstrap object. Free tier grants everything, mirroring the source
 * design system's behavior.
 */
const bootstrap = () => (typeof window !== 'undefined' ? window.rbfb : undefined) || {};

export function userCan(permission) {
    const data = bootstrap();
    if (!data.isPro) return true;
    if (!data.currentUser?.can) return true;
    return !!data.currentUser.can[permission];
}

export function userCanViewPage(page) {
    const data = bootstrap();
    if (!data.isPro) return true;
    if (!data.currentUser?.can?.view_pages) return true;
    return !!data.currentUser.can.view_pages[page];
}
