import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:sigap/src/features/panic/presentation/pages/panic_button_page.dart';
import 'package:sigap/src/features/personalization/presentasion/pages/settings/setting_screen.dart';
import 'package:sigap/src/shared/widgets/navigation/custom_bottom_navigation_bar.dart';

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

  @override
  Widget build(BuildContext context) {
    // Ensure NavigationController is registered in a binding first, then use find
    final controller = Get.find<NavigationController>();
    final theme = Theme.of(context);

    return Scaffold(
      backgroundColor: theme.scaffoldBackgroundColor,
      body: Obx(
        () => IndexedStack(
          index: controller.selectedIndex.value,
          children: const [
            // HomePage(),
            // SearchPage(),
            PanicButtonPage(),
            // HistoryPage(),
            SettingsScreen(),
          ],
        ),
      ),
      bottomNavigationBar: const CustomBottomNavigationBar(),
    );
  }
}

class NavigationController extends GetxController {
  static NavigationController get instance => Get.find();

  // Observable variable to track the current selected index
  final Rx<int> selectedIndex = 2.obs; // Start with PanicButtonPage (index 2)

  // Method to change selected index
  void changeIndex(int index) {
    selectedIndex.value = index;
  }
}
