import 'package:digiplug/bat_theme/bat_theme.dart';
import 'package:digiplug/features/devices/presentation/views/device_home.dart';
import 'package:digiplug/features/home/presentation/views/home.dart';
import 'package:digiplug/features/profile/presentation/views/profile.dart';
import 'package:digiplug/main.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';

class PlaceholderScreen extends StatelessWidget {
  final String title;
  const PlaceholderScreen({super.key, required this.title});

  @override
  Widget build(BuildContext context) {
    return Center(
      child: Text(
        '$title\n(.)',
        textAlign: TextAlign.center,
        style: BatThemeData.of(context).typography.headline4,
      ),
    );
  }
}

class Dashboard extends StatefulWidget {
  const Dashboard({super.key});

  @override
  State<Dashboard> createState() => _DashboardState();
}

class _DashboardState extends State<Dashboard> {
  int _currentIndex = 0;

  // Daftar halaman yang akan ditampilkan di setiap tab
  final List<Widget> _children = [
    const HomeScreen(),
    const DevicesScreen(),
    const PlaceholderScreen(title: "Schedule"),
    const PlaceholderScreen(title: "Stats"),
    const ProfileScreen(), // Mengganti Voice dengan Profile
  ];

  void onTabTapped(int index) {
    setState(() {
      _currentIndex = index;
    });
  }

  @override
  Widget build(BuildContext context) {
    var themeProvider = context.read<ThemeProvider>();
    var batTheme = BatThemeData.of(context);

    return Scaffold(
      backgroundColor: batTheme.colors.background,
      body: SafeArea(
        top: true, // Beri jarak aman di atas
        child: _children[_currentIndex],
      ),
      bottomNavigationBar: BottomNavigationBar(
        backgroundColor: batTheme.colors.background,
        type: BottomNavigationBarType.fixed,
        onTap: onTabTapped,
        currentIndex: _currentIndex,
        unselectedFontSize: 14,
        elevation: 2.0,
        selectedIconTheme: const IconThemeData(color: BatPalette.primary),
        unselectedIconTheme: IconThemeData(
            color:
                themeProvider.isDark ? BatPalette.white60 : BatPalette.grey60),
        selectedLabelStyle: batTheme.typography.bodyCopyMedium,
        unselectedLabelStyle: batTheme.typography.bodyCopy,
        selectedItemColor: BatPalette.primary,
        unselectedItemColor:
            themeProvider.isDark ? BatPalette.white60 : BatPalette.grey60,
        enableFeedback: true,
        items: const [
          BottomNavigationBarItem(
              icon: Icon(Icons.home_outlined),
              activeIcon: Icon(Icons.home),
              label: "Home"),
          BottomNavigationBarItem(
              icon: Icon(Icons.phone_iphone_rounded),
              activeIcon: Icon(Icons.phone_iphone),
              label: "Device"),
          BottomNavigationBarItem(
              icon: Icon(Icons.timer_outlined),
              activeIcon: Icon(Icons.timer),
              label: "Schedule"),
          BottomNavigationBarItem(
              icon: Icon(Icons.bar_chart_rounded),
              activeIcon: Icon(Icons.bar_chart),
              label: "Stats"),
          BottomNavigationBarItem(
              icon: Icon(Icons.person_outline), // Mengganti ikon Voice
              activeIcon: Icon(Icons.person),
              label: "Profile"), // Mengganti label Voice
        ],
      ),
    );
  }
}
