import 'package:aitrainer_app/localization/app_localization.dart';
import 'package:aitrainer_app/service/logging.dart';
import 'package:aitrainer_app/util/common.dart';
import 'package:aitrainer_app/util/trans.dart';
import 'package:flurry/flurry.dart';
import 'package:flutter/material.dart';
import 'package:gradient_bottom_navigation_bar/gradient_bottom_navigation_bar.dart';

// ignore: must_be_immutable
class BottomNavigator extends StatefulWidget {
  int bottomNavIndex = 0;
  BottomNavigator({this.bottomNavIndex}) {
    this.bottomNavIndex = bottomNavIndex;
  }

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

class _NawDrawerWidget extends State<BottomNavigator> with Trans, Logging {
  @override
  void initState() {
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    final Color bgrColor = Color(0xffb4f500);
    final Color bgrColorEnd = Colors.blue;
    final Color active = Colors.black;
    final Color inactive = Colors.black26;
    setContext(context);

    return GradientBottomNavigationBar(
        currentIndex: widget.bottomNavIndex, // this will be set when a new tab is tapped
        backgroundColorStart: bgrColorEnd,
        backgroundColorEnd: bgrColor,
        fixedColor: active,
        items: [
          BottomNavigationBarItem(
            backgroundColor: bgrColor,
            icon: Common.badgedIcon(inactive, Icons.home, "home"),
            activeIcon: Common.badgedIcon(active, Icons.home, "home"),
            title: new Text(t("Home"), style: TextStyle(fontSize: 12)),
          ),
          BottomNavigationBarItem(
            backgroundColor: bgrColor,
            icon: new Icon(Icons.trending_up, color: inactive),
            activeIcon: new Icon(
              Icons.trending_up,
              color: active,
            ),
            title: new Text(
              t("My Development"),
              style: TextStyle(fontSize: 12),
            ),
          ),
          BottomNavigationBarItem(
            backgroundColor: bgrColor,
            icon: new Icon(Icons.featured_play_list, color: inactive),
            activeIcon: new Icon(
              Icons.featured_play_list,
              color: active,
            ),
            title: new Text(
              t("My Training Plan"),
              style: TextStyle(fontSize: 12),
            ),
          ),
          BottomNavigationBarItem(
              backgroundColor: bgrColor,
              icon: Common.badgedIcon(inactive, Icons.person, "account"),
              activeIcon: Common.badgedIcon(active, Icons.person, "account"),
              title: Text(
                AppLocalizations.of(context).translate("Account"),
                style: TextStyle(fontSize: 12),
              )),
          BottomNavigationBarItem(
              backgroundColor: bgrColor,
              icon: Icon(Icons.settings, color: inactive),
              activeIcon: Icon(Icons.settings, color: active),
              title: Text(t("Settings"), style: TextStyle(fontSize: 12)))
        ],
        onTap: (index) {
          setState(() {
            widget.bottomNavIndex = index;
            switch (index) {
              case 0:
                Navigator.of(context).pop();
                Flurry.logEvent("Home");
                Navigator.of(context).pushNamed('home');

                break;
              case 1:
                Navigator.of(context).pop();
                Flurry.logEvent("myDevelopment");
                Navigator.of(context).pushNamed('myDevelopment');
                break;
              case 2:
                Navigator.of(context).pop();
                Flurry.logEvent("myExercisePlan");
                Navigator.of(context).pushNamed('myExercisePlan');

                break;
              case 3:
                Navigator.of(context).pop();
                Flurry.logEvent("Account");
                Navigator.of(context).pushNamed('account');

                break;
              case 4:
                Navigator.of(context).pop();
                Flurry.logEvent("Settings");
                Navigator.of(context).pushNamed('settings');

                break;
            }
          });
        });
  }
}