import 'package:flutter/material.dart';
import 'package:glowwheels/screens/profile_details_screen.dart';

import 'Serviceboy_screen.dart';
import 'account_screen.dart';
import 'order_screen.dart';


class MainScreen extends StatefulWidget {
  @override
  State<MainScreen> createState() => _MainScreenState();
}

class _MainScreenState extends State<MainScreen> {
  int _selectedIndex = 0;

  // ✅ Use nested navigators for each tab
  final List<Widget> _screens = [];

  @override
  void initState() {
    super.initState();
    _screens.addAll([
      _buildTabNavigator(OrdersScreen()),
      _buildTabNavigator(ServiceBoyScreen()),
      _buildTabNavigator(AccountScreen()), // replace with ProfileScreen later
    ]);
  }

  // ✅ Each tab gets its own Navigator
  Widget _buildTabNavigator(Widget child) {
    return Navigator(
      onGenerateRoute: (settings) {
        return MaterialPageRoute(builder: (_) => child);
      },
    );
  }

  void _onItemTapped(int index) {
    setState(() {
      _selectedIndex = index;
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: IndexedStack(
        index: _selectedIndex,
        children: _screens,
      ),
      bottomNavigationBar: BottomNavigationBar(
        currentIndex: _selectedIndex,
        onTap: _onItemTapped,
        selectedItemColor: Color(0xFF1F1762),
        unselectedItemColor: Colors.grey,
        items: const [
          BottomNavigationBarItem(icon:ImageIcon(AssetImage("assets/icon/orders_icon.png")),label: 'Orders'),
          BottomNavigationBarItem(icon:ImageIcon(AssetImage("assets/icon/serviceboy_icon.png")), label: 'Service Boy'),
          BottomNavigationBarItem(icon:ImageIcon(AssetImage("assets/icon/profile_icon.png")), label: 'My Profile'),
        ],
      ),
    );
  }
}

