import 'package:dikantin/app/modules/Demo/views/demo_view.dart';
import 'package:dikantin/app/modules/listDemo/views/list_demo_view.dart';
import 'package:flutter/material.dart';

import 'package:get/get.dart';

import '../../dropdownSearch/views/dropdown_search_view.dart';
import '../controllers/navigation_demo_controller.dart';


class NavigationDemoView extends GetView<NavigationDemoController> {
  NavigationDemoView({Key? key}) : super(key: key);
  final NavigationDemoController nav = Get.put(NavigationDemoController());
  DateTime? currentBackPressTime;
  @override
  Widget build(BuildContext context) {
    Future<bool> onWillPop() async {
      DateTime now = DateTime.now();
      if (currentBackPressTime == null ||
          now.difference(currentBackPressTime!) > Duration(seconds: 1)) {
        currentBackPressTime = now;
        ScaffoldMessenger.of(context).showSnackBar(
          // Perubahan di sini
          SnackBar(
            content: Text('Tekan sekali lagi untuk keluar'),
          ),
        );
        return Future.value(false);
      }
      return Future.value(true);
    }

    final query = MediaQuery.of(context);

    return MediaQuery(
      data: query.copyWith(
          textScaleFactor: query.textScaleFactor.clamp(1.0, 1.15)),
      child: WillPopScope(
        onWillPop: onWillPop,
        child: Scaffold(
          backgroundColor: Colors.black, // Atur warna latar belakang Scaffold

          body: GetBuilder<NavigationDemoController>(
            builder: (controller) {
              return IndexedStack(
                index: controller.tabIndex,
                children: [
                  DemoView(),
                  ListDemoView(),
                  DropdownSearchView(),
                ],
              );
            },
          ),
          bottomNavigationBar: GetBuilder<NavigationDemoController>(
            builder: (controller) {
              return BottomNavigationBar(
                type: BottomNavigationBarType.fixed,
                elevation: 0.0, // to get rid of the shadow
                backgroundColor: Colors
                    .white, // transparent, you could use 0x44aaaaff to make it slightly less transparent with a blue hue.
                currentIndex: controller.tabIndex,
                selectedItemColor: Colors.blue,
                unselectedItemColor: Color(0xFFD0E0FE),
                onTap: (index) {
                  // if (index == 0) {
                  //   homeController.refreshData();
                  //   nav.checkToken();
                  // } else if (index == 1) {
                  //   pesananController.refreshPesanan();
                  //   nav.checkToken();
                  // } else if (index == 2) {
                  //   riwayatController.searchAll();
                  //   nav.checkToken();
                  // } else if (index == 3) {
                  //   nav.checkToken();
                  // }
                  controller.updateCurrentScreen(index);
                },
                items: [
                  BottomNavigationBarItem(
                    icon: Icon(Icons.home_rounded, size: 30),
                    label: 'Old View',
                  ),
                  BottomNavigationBarItem(
                    icon: Icon(Icons.my_library_books, size: 30),
                    label: 'list Search',
                  ),
                  BottomNavigationBarItem(
                    icon: Icon(Icons.history_rounded, size: 30),
                    label: 'Dropdown Search',
                  ),
             
                ],
              );
            },
          ),
        ),
      ),
    );
  }
}
