import 'package:flutter/material.dart';
import 'package:project_manager/pages/dashboard.dart';
import 'package:project_manager/pages/delivery_list.dart';
import 'package:project_manager/pages/delivery_list.dart';
import 'package:project_manager/pages/upload_excel.dart';
import 'package:project_manager/pages/upload_photo.dart';
import 'package:project_manager/pages/map_page.dart';
import 'package:project_manager/pages/upload_excel.dart';
import 'package:project_manager/pages/upload_photo.dart';

void main() {
  runApp(const MaterialApp(
    home: MyDeliveryApp(),
  ));
}

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

  @override
  Widget build(BuildContext context) {
    return const MaterialApp(
      title: 'Furniture Delivery App',
      home: Navbar(),
    );
  }
}

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

  @override
  NavbarState createState() => NavbarState();
}

class NavbarState extends State<Navbar> {
  int _currentIndex = 0;

  final List<Widget> _children = const [
    MapPage(),
    ListViewHome()
  ];

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

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Center(child: Text('Delivery Dashboard')),
      ),
      body: _children[_currentIndex],
      bottomNavigationBar: BottomNavigationBar(
        onTap: onTabTapped,
        currentIndex: _currentIndex,
        items: const [
          BottomNavigationBarItem(
            icon: Icon(Icons.map),
            label: 'Map',
          ),
          BottomNavigationBarItem(
            icon: Icon(Icons.view_list),
            label: 'All Deliveries',
          )
        ],
      ),
      floatingActionButton:
      Stack(children: <Widget>[
        _currentIndex == 1 ?  Align(
          alignment: Alignment.bottomRight,
          child: FloatingActionButton(
            onPressed: () {
              Navigator.push(context,
                  MaterialPageRoute(builder: (context) => const UploadExcelScreen()));
            },
            child: const Icon(Icons.document_scanner),
          ),
        ) : const Align(),
        _currentIndex == 2 ?  Align(
          alignment: Alignment.bottomRight,
          child: FloatingActionButton(
            onPressed: () {
              Navigator.push(context, MaterialPageRoute(builder: (context) => const UploadPhotoScreen()));
            },
            child: const Icon(Icons.camera),
          ),
        ) : const Align(),
      ]),
    );
  }
}
