import 'package:flutter/widgets.dart';

import 'package:provider/provider.dart';

import 'package:pshared/models/resources.dart';
import 'package:pshared/models/permissions/action.dart' as perm;
import 'package:pshared/provider/permissions.dart';


T? protectedWidgetctx<T extends Widget>(BuildContext context, ResourceType resource, T child, {perm.Action? action}) {
  return protectedWidget(Provider.of<PermissionsProvider>(context, listen: false), resource, child, action: action);
}

T? protectedWidget<T extends Widget>(PermissionsProvider provider, ResourceType resource, T child, {perm.Action? action}) {
  return provider.canAccessResource(resource, action: action) ? child : null;
}
