import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:unit2/bloc/offline/offline_bloc/offline_bloc.dart';
import 'package:unit2/model/offline/offlane_modules.dart';
import 'package:unit2/screens/offline/homepage/drawer.dart';
import 'package:unit2/screens/offline/homepage/menu_screen.dart';
import 'package:unit2/screens/unit2/homepage.dart/components/drawer-screen.dart';
import 'package:unit2/screens/unit2/homepage.dart/components/menu_tile.dart';
import 'package:unit2/theme-data.dart/colors.dart';
import 'package:fluttericon/web_symbols_icons.dart';
import 'package:fluttericon/font_awesome5_icons.dart';
import 'package:unit2/utils/global_context.dart';
import '../../../../model/login_data/user_info/user_data.dart';
import '../../../../utils/global.dart';

class MenuScreen extends StatefulWidget {
  final UserData? userData;
  const MenuScreen({Key? key, required this.userData}) : super(key: key);

  @override
  State<MenuScreen> createState() => _MenuScreenState();
}

class _MenuScreenState extends State<MenuScreen> {
  @override
  Widget build(BuildContext context) {
    return Drawer(
      child: SizedBox(
        height: screenHeight,
        child: Column(
          mainAxisSize: MainAxisSize.max,
          children: [
            Column(
              children: <Widget>[
                UserAccountsDrawerHeader(
                  currentAccountPictureSize: const Size.square(90),
                  decoration: const BoxDecoration(
                      color: primary,
                      image: DecorationImage(
                          image: AssetImage('assets/pngs/bg.png'),
                          fit: BoxFit.cover)),
                  accountName: null,
                  accountEmail: null,
                  currentAccountPicture: CircleAvatar(
                    radius: 100,
                    backgroundColor: fifth,
                    child: CircleAvatar(
                        radius: 100,
                        backgroundColor: third,
                        child: Image.asset(
                          'assets/pngs/capitol.png',
                        )),
                  ),
                ),
                getTile(FontAwesome5.user, "Basic Info", '/basic-info', context,
                    widget.userData!),
                const Divider(),
                getTile(FontAwesome5.user_circle, "Profile", '/profile',
                    context, widget.userData!),
                const Divider(),
                getTile(FontAwesome5.life_ring, "Request SOS", '/sos', context,
                    widget.userData!),
                const Divider(),
                SizedBox(
                    child: globalOfflineAvailable == true
                        ? ListTile(
                            dense: true,
                            leading: const Icon(
                              Icons.exit_to_app,
                              color: primary,
                            ),
                            title: const Text(
                              "Offline Mode",
                              style: TextStyle(color: Colors.black),
                            ),
                            onTap: () async {
                              Navigator.pushReplacement(
                                  NavigationService
                                      .navigatorKey.currentState!.context,
                                  MaterialPageRoute(builder: ((context) {
                                return BlocProvider(
                                  create: (context) =>
                                      OfflineBloc()..add(SwitchOffline()),
                                  child: const OfflineDrawerScreen(),
                                );
                              })));
                              ;
                            },
                          )
                        : Container())
              ],
            ),
            const Expanded(child: SizedBox()),
            const Divider(),
            Align(
              alignment: FractionalOffset.bottomLeft,
              child: getTile(
                  WebSymbols.logout, "Logout", '/', context, widget.userData!),
            ),
            const SizedBox(
              height: 10,
            ),
          ],
        ),
      ),
    );
  }
}
