import 'package:eva_icons_flutter/eva_icons_flutter.dart';
import 'package:flutter/material.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:mitra_corporate/app/route.dart';
import 'package:mitra_corporate/model/menu_model.dart';
import 'package:mitra_corporate/provider/auth_provider.dart';
import 'package:mitra_corporate/provider/menu_provider.dart';
import 'package:mitra_corporate/screen/login/logout_provider.dart';
import 'package:mitra_corporate/widgets/side_menu_btn_widget.dart';
import 'package:shared_preferences/shared_preferences.dart';

import '../app/constant.dart';
import 'custom_snackbar_widget.dart';

class SideMenu extends HookConsumerWidget {
  const SideMenu({
    super.key,
  });

  @override
  Widget build(BuildContext context, WidgetRef ref) {
    final currentMenu = ref.watch(currentMenuProvider);
    final isExpand = ref.watch(sideBarExpandProvider);
    final List<MenuModel> menuList = Constant.getMenuModel();

    return Container(
      color: Colors.white,
      child: isExpand
          ? Column(
              children: [
                Expanded(
                  child: SizedBox(
                      width: Constant.getActualX(context: context, x: 280),
                      height: Constant.getActualY(context: context, y: 90),
                      child: Padding(
                        padding: const EdgeInsets.only(
                            left: 24, right: 24, top: 12, bottom: 12),
                        child: Row(
                          children: [
                            Image.asset('images/logo_pramita.png',
                                width: Constant.getActualX(
                                    context: context, x: 147),
                                height: Constant.getActualY(
                                    context: context, y: 46)),
                            Spacer(),
                            IconButton(
                              onPressed: () {
                                ref.read(sideBarExpandProvider.notifier).state =
                                    !isExpand;
                                // ref.read(logoutProvider.notifier).logout(
                                //     M_UserID: currentUser!.mUserID ?? "0",
                                //     M_UserUsername: currentUser.companyName ?? "0");
                              },
                              icon: Icon(EvaIcons.menu2,
                                  color: Constant.primaryRed,
                                  size: Constant.getActualX(
                                      context: context, x: 24)),
                            )
                          ],
                        ),
                      )),
                ),
                SizedBox(
                  width: Constant.getActualX(context: context, x: 280),
                  height: Constant.getActualY(context: context, y: 930),
                  child: Padding(
                    padding: const EdgeInsets.all(24.0),
                    child: ListView(
                      children: menuList
                          .map(
                            (e) => Container(
                              margin: EdgeInsets.only(
                                  bottom: Constant.getActualY(
                                      context: context, y: 24)),
                              decoration: BoxDecoration(
                                  color: e.subValue.contains(currentMenu)
                                      ? Constant.selectedMenuBg
                                      : null,
                                  borderRadius: BorderRadius.circular(8)),
                              child: sideBarMenuBtnWidget(
                                currentMenu: currentMenu,
                                title: e.title,
                                value: e.subValue,
                                iconMenu: e.icon,
                                selectedColor: Constant.selectedMenuBg,
                                selectedColorText: Constant.primaryRed,
                                onTap: () {
                                  ref.read(currentMenuProvider.notifier).state =
                                      e.mainValue;
                                  // Navigator.pushNamed(context, dashboardRoute);
                                },
                              ),
                            ),
                          )
                          .toList(),
                    ),
                  ),
                ),
              ],
            )
          : Column(
              children: [
                Expanded(
                  child: SizedBox(
                      width: Constant.getActualX(context: context, x: 95),
                      height: Constant.getActualY(context: context, y: 90),
                      child: Center(
                        child: IconButton(
                          onPressed: () {
                            ref.read(sideBarExpandProvider.notifier).state =
                                !isExpand;
                          },
                          icon: Icon(EvaIcons.menu2,
                              color: Constant.primaryRed,
                              size:
                                  Constant.getActualX(context: context, x: 24)),
                        ),
                      )),
                ),
                SizedBox(
                  // color: Colors.red,
                  width: Constant.getActualX(context: context, x: 95),
                  height: Constant.getActualY(context: context, y: 930),
                  child: Padding(
                    padding: const EdgeInsets.all(24.0),
                    child: ListView(
                      children: menuList
                          .map(
                            (e) => SideBarBtnSmallWidget(
                              title: e.title,
                              currentMenu: currentMenu,
                              value: e.subValue,
                              iconMenu: e.icon,
                              selectedColor: Constant.selectedMenuBg,
                              selectedColorText: Constant.primaryRed,
                              onTap: () {
                                ref.read(currentMenuProvider.notifier).state =
                                    e.mainValue;
                                // Navigator.pushNamed(context, dashboardRoute);
                              },
                            ),
                          )
                          .toList(),
                    ),
                  ),
                )
              ],
            ),
    );
  }
}
