import 'package:flutter/material.dart';
import 'package:frontend_eccp_mobile/app/core/widgets/app_bottom_nav.dart';
import 'package:frontend_eccp_mobile/modules/berkas/presentation/screen/berkas_page.dart';
import 'package:frontend_eccp_mobile/modules/home/presentation/screen/home_page.dart';
import 'package:frontend_eccp_mobile/modules/profile/presentation/screen/profile_page.dart';

class MainNavigationPage extends StatefulWidget {
  const MainNavigationPage({
    super.key,
    this.initialIndex = 0,
  });

  final int initialIndex;

  @override
  State<MainNavigationPage> createState() => _MainNavigationPageState();
}

class _MainNavigationPageState extends State<MainNavigationPage> {
  late int _currentIndex;

  final List<Widget> _pages = [
    const HomePage(),
    const BerkasPage(),
    const ProfilePage(),
  ];

  @override
  void initState() {
    super.initState();
    _currentIndex = widget.initialIndex;
  }

  void _onTabChanged(int index) {
    if (_currentIndex == index) return;
    setState(() => _currentIndex = index);
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: IndexedStack(
        index: _currentIndex,
        children: _pages,
      ),
      bottomNavigationBar: AppBottomNav(
        currentIndex: _currentIndex,
        onTap: _onTabChanged,
      ),
    );
  }
}
