import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:syncrow_web/pages/common/bloc/project_manager.dart';
import 'package:syncrow_web/pages/device_managment/shared/navigate_home_grid_view.dart';
import 'package:syncrow_web/pages/roles_and_permission/bloc/roles_permission_bloc.dart';
import 'package:syncrow_web/pages/roles_and_permission/bloc/roles_permission_state.dart';
import 'package:syncrow_web/pages/roles_and_permission/users_page/users_table/bloc/user_table_bloc.dart';
import 'package:syncrow_web/pages/roles_and_permission/users_page/users_table/bloc/user_table_event.dart';
import 'package:syncrow_web/pages/roles_and_permission/users_page/users_table/view/users_page.dart';
import 'package:syncrow_web/utils/color_manager.dart';
import 'package:syncrow_web/utils/extension/build_context_x.dart';
import 'package:syncrow_web/utils/theme/responsive_text_theme.dart';
import 'package:syncrow_web/web_layout/web_scaffold.dart';

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

  @override
  Widget build(BuildContext context) {
    return BlocProvider(
      create: (BuildContext context) => RolesPermissionBloc(),
      child: BlocConsumer<RolesPermissionBloc, RolesPermissionState>(
        listener: (context, state) {},
        builder: (context, state) {
          final _blocRole = BlocProvider.of<RolesPermissionBloc>(context);

          return state is RolesLoadingState
              ? const Center(child: CircularProgressIndicator())
              : WebScaffold(
                  enableMenuSidebar: false,
                  appBarTitle: Text(
                    'Roles & Permissions',
                    style:
                        ResponsiveTextTheme.of(context).deviceManagementTitle,
                  ),
                  rightBody: const NavigateHomeGridView(),
                  centerBody: Row(
                    children: [
                      // TextButton(
                      //   style: TextButton.styleFrom(
                      //     backgroundColor: null,
                      //   ),
                      //   onPressed: () {
                      //     _blocRole.add(const ChangeTapSelected(true));
                      //   },
                      //   child: Text(
                      //     'Roles',
                      //     style: context.textTheme.titleMedium?.copyWith(
                      //       color: (_blocRole.tapSelect == true)
                      //           ? ColorsManager.whiteColors
                      //           : ColorsManager.grayColor,
                      //       fontWeight: (_blocRole.tapSelect == true)
                      //           ? FontWeight.w700
                      //           : FontWeight.w400,
                      //     ),
                      //   ),
                      // ),
                      TextButton(
                        style: TextButton.styleFrom(
                          backgroundColor: null,
                        ),
                        onPressed: () {
                          // _blocRole.add(const ChangeTapSelected(false));
                        },
                        child: Text(
                          'Users',
                          style: context.textTheme.titleMedium?.copyWith(
                            color: (_blocRole.tapSelect == true)
                                ? ColorsManager.whiteColors
                                : ColorsManager.grayColor,
                            fontWeight: (_blocRole.tapSelect == true)
                                ? FontWeight.w700
                                : FontWeight.w400,
                          ),
                        ),
                      ),
                    ],
                  ),
                  scaffoldBody: BlocProvider<UserTableBloc>(
                    create: (context) => UserTableBloc()..add(const GetUsers()),
                    child: UsersPage(),
                  )
                  // _blocRole.tapSelect == false
                  //     ? UsersPage(
                  //         blocRole: _blocRole,
                  //       )
                  //     : RolesPage(
                  //         blocRole: _blocRole,
                  //       )
                  );
        },
      ),
    );
  }
}
