import 'package:flutter/material.dart';

import 'package:provider/provider.dart';

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

import 'package:pweb/widgets/drawer/avatar.dart';
import 'package:pweb/widgets/drawer/tiles/dashboard.dart';
import 'package:pweb/widgets/drawer/tiles/logout.dart';
import 'package:pweb/widgets/drawer/tiles/settings/profile.dart';
import 'package:pweb/widgets/drawer/tiles/settings/roles.dart';
import 'package:pweb/widgets/drawer/tiles/settings/users.dart';


class AppDrawer extends StatelessWidget {
  const AppDrawer({super.key});

  @override
  Widget build(BuildContext context) => Drawer(
    child: Consumer<PermissionsProvider>(builder:(context, provider, _) => 
      ListView(
        padding: EdgeInsets.zero,
        children: <Widget>[
          // Shows user avatar / name / email, etc.
          const AccountAvatar(),

          const DashboardTile(),

          // Profile & Settings
          const Divider(),
          if (provider.canAccessResource(ResourceType.accounts))
            const UsersSettingsTile(),
          if (provider.canAccessResource(ResourceType.roles))
            const RolesSettingsTile(),
          const ProfileSettingsTile(), // always available
          
          // Logout
          const Divider(),
          const LogoutTile(),
        ],
      ),
    ),
  );
}
