import 'package:fancy_bottom_navigation_2/fancy_bottom_navigation.dart';
import 'package:flutter/material.dart';
import 'package:flutter/src/widgets/framework.dart';
import 'package:flutter/src/widgets/placeholder.dart';
import 'package:flutter_hooks/flutter_hooks.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
import '/screen/history_screen/history_screen.dart';
import '/screen/profile_screen/profile_screen.dart';
import '/screen/work_list_screen/work_list_screen.dart';
import 'package:loader_overlay/loader_overlay.dart';
import 'package:loading_animation_widget/loading_animation_widget.dart';

import '../../app/constant.dart';
import '../../provider/current_user_provider.dart';
import '../home_screen/home_screen.dart';
import '../home_screen/pending_work_provider.dart';
import '../home_screen/total_work_provider.dart';
import '../work_list_screen/work_status_provider.dart';
import '../work_list_screen/work_supervisor_moder.dart';
import '../work_list_screen/work_type_provider.dart';

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

  @override
  Widget build(BuildContext context, WidgetRef ref) {
    final current_page = useState(0);
    final mUsername =
        ref.watch(currentUserProvider)?.model.user?.mStaffName ?? "0";

    final mCourirID =
        ref.watch(currentUserProvider)?.model.user?.mCourierID ?? "0";

    changeMenu() {
      switch (current_page.value) {
        case 0:
          return HomeScreen();
          break;
        case 1:
          return WorkListScreen();
          break;
        case 2:
          return HistoryScreen();
          break;
        case 3:
          return ProfilScreen();
          break;
        default:
          return HomeScreen();
      }
    }

    return LoaderOverlay(
      useDefaultLoading: false,
      overlayColor: Colors.black,
      overlayWidget: Center(
        child: LoadingAnimationWidget.inkDrop(
            color: Constant.primaryBlue, size: 50),
      ),
      child: Scaffold(
        resizeToAvoidBottomInset: false,
        backgroundColor:
            current_page.value == 1 ? const Color(0XFFF4F6F8) : Colors.white,
        bottomNavigationBar: Container(
          height: Constant.getActualY(context: context, y: 67),
          child: SizedBox(
            height: Constant.getActualY(context: context, y: 67),
            child: FancyBottomNavigation(
              tabs: [
                TabData(iconData: Icons.home_outlined, title: "Beranda"),
                TabData(
                    iconData: Icons.work_history_outlined,
                    title: "List Pekerjaan"),
                TabData(iconData: Icons.map_outlined, title: "Riwayat"),
                TabData(iconData: Icons.person_outlined, title: "Profil")
              ],
              onTabChangedListener: (position) {
                current_page.value = position;

                // if (position == 0) {
                //   ref.read(TotalWorkProvider.notifier).getData(id: mCourirID);
                //   ref.read(PendingWorkProvider.notifier).getData(id: mCourirID);
                //   ref.read(WorkTypeProvider.notifier).getData();
                //   ref.read(WorkStatusProvider.notifier).getData();
                //   ref.read(WorkSupervisorProvider.notifier).getData();
                // }
              },
            ),
          ),
        ),
        body: changeMenu(),
      ),
    );
  }
}
