import 'package:flutter/material.dart';
import 'package:get/get.dart';
import '../../home/views/home_view.dart';
import '../../mode/views/mode_view.dart';
import '../../setting/views/setting_view.dart';
import '../controllers/navbar_controller.dart';

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

  @override
  Widget build(BuildContext context) {
    return GetBuilder<NavbarController>(
      init: NavbarController(),
      builder: (controller) {
        return Scaffold(
          extendBody: true, // supaya bottom bar transparan & ga overflow
          body: IndexedStack(
            index: controller.selectedIndex,
            children: const [
              HomeView(),
              SettingView(),
            ],
          ),
          floatingActionButton: SizedBox(
            height: 70,
            width: 70,
            child: FloatingActionButton(
              onPressed: () {
                Get.to(() => const ModeView());
              },
              backgroundColor: Colors.green, // Warna hijau
              child: const Icon(
                Icons.memory,
                color: Colors.white, // Bikin icon putih
                size: 32,
              ),
              elevation: 6,
              shape: const CircleBorder(),
            ),
          ),
          floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked,
          bottomNavigationBar: BottomAppBar(
            shape: const CircularNotchedRectangle(),
            notchMargin: 10.0,
            color: const Color.fromARGB(255, 246, 246, 246),
            elevation: 10,
            child: Padding(
              padding: const EdgeInsets.symmetric(horizontal: 20),
              child: SizedBox(
                height: 65,
                child: Row(
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  children: [
                    _buildNavItem(
                      icon: Icons.home, // ganti jadi home
                      label: 'Beranda',
                      isActive: controller.selectedIndex == 0,
                      onTap: () => controller.changeTabIndex(0),
                    ),
                    const SizedBox(width: 50), // space buat tombol tengah
                    _buildNavItem(
                      icon: Icons.settings, // ganti jadi settings
                      label: 'Pengaturan',
                      isActive: controller.selectedIndex == 1,
                      onTap: () => controller.changeTabIndex(1),
                    ),

                  ],
                ),
              ),
            ),
          ),
        );
      },
    );
  }

  Widget _buildNavItem({
    required IconData icon,
    required String label,
    required bool isActive,
    required VoidCallback onTap,
  }) {
    return GestureDetector(
      onTap: onTap,
      child: Column(
        mainAxisSize: MainAxisSize.min,
        mainAxisAlignment: MainAxisAlignment.center,
        children: [
          Icon(
            icon,
            color: isActive ? Colors.green : Colors.grey,
          ),
          const SizedBox(height: 4),
          Text(
            label,
            style: TextStyle(
              fontSize: 12,
              color: isActive ? Colors.green : Colors.grey,
            ),
          ),
        ],
      ),
    );
  }
}
