import 'package:driverapp/pages/delivery/delivery_confirmed_page.dart';
import 'package:driverapp/pages/delivery/information_page.dart';
import 'package:driverapp/uitl/translations_delegate_base.dart';
import 'package:driverapp/widgets/bottom_navigation/bottom_nav_bar.dart';
import 'package:driverapp/widgets/drawer/app_drawer_widget.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

import 'home_page.dart';

class LandingPage extends StatefulWidget {
  @override
  _LandingPageState createState() => _LandingPageState();
}

class _LandingPageState extends State<LandingPage> {
  int currentTab = 0;
  PageController pageController;

  _changeCurrentTab(int tab) {
    setState(() {
      currentTab = tab;
      pageController.jumpToPage(tab);
    });
  }

  @override
  void initState() {
    super.initState();
    pageController = PageController(keepPage: true);
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        elevation: 0,
        textTheme: TextTheme(
          headline6:
              TextStyle(color: Colors.white, fontWeight: FontWeight.bold),
        ),
        title: Text(getText(currentTab).toUpperCase()),
        leading: Builder(
          builder: (BuildContext context) {
            return IconButton(
              icon: Icon(Icons.menu),
              color: Colors.white,
              onPressed: () => Scaffold.of(context).openDrawer(),
            );
          },
        ),
        centerTitle: true,
      ),
      drawer: SafeArea(child: AppDrawer()),
      extendBody: true,
      body: PageView(
        physics: NeverScrollableScrollPhysics(),
        controller: pageController,
        children: [
          HomePage(),
          InformationPage(null),
          DeliveryConfirmedPage(null),
          Container()
        ],
      ),
      bottomNavigationBar: BottomNavBar(changeIndex: _changeCurrentTab),
    );
  }

  getText(currentTab) {
    switch (currentTab) {
      case 0:
        return TranslationBase.of(context).home;
      case 1:
        return 'new One';
      case 2:
        return TranslationBase.of(context).booking;
      case 3:
        return TranslationBase.of(context).mySchedule;
      case 4:
        return TranslationBase.of(context).services;
    }
  }
}
