import 'package:diplomaticquarterapp/core/service/AuthenticatedUserObject.dart';
import 'package:diplomaticquarterapp/core/viewModels/project_view_model.dart';
import 'package:diplomaticquarterapp/locator.dart';
import 'package:diplomaticquarterapp/models/Appointments/toDoCountProviderModel.dart';
import 'package:diplomaticquarterapp/pages/BookAppointment/BookingOptions.dart';
import 'package:diplomaticquarterapp/pages/ToDoList/ToDo.dart';
import 'package:diplomaticquarterapp/uitl/app_toast.dart';
import 'package:diplomaticquarterapp/uitl/translations_delegate_base.dart';
import 'package:diplomaticquarterapp/widgets/transitions/fade_page.dart';
import 'package:eva_icons_flutter/eva_icons_flutter.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:diplomaticquarterapp/services/robo_search/event_provider.dart';
import 'package:provider/provider.dart';

import '../../d_q_icons_icons.dart';
import 'bottom_navigation_item.dart';

class BottomNavBar extends StatefulWidget {
  final ValueChanged<int> changeIndex;
  final int index;
  final bool showHomeIcon;
  BottomNavBar(
      {Key key, this.changeIndex, this.index, this.showHomeIcon = false})
      : super(key: key);

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

class _BottomNavBarState extends State<BottomNavBar> {
  int _index = 0;
  ToDoCountProviderModel model;
  var event = RobotProvider();
  _changeIndex(int index) async {
    widget.changeIndex(index);
    if (index == 0) {
      event.setValue({'isRobotVisible': 'true'});
    }
  }

  @override
  Widget build(BuildContext context) {
    model = Provider.of<ToDoCountProviderModel>(context);
    ProjectViewModel projectViewModel = Provider.of(context);
    return BottomAppBar(
      elevation: 4,
      shape: CircularNotchedRectangle(),
      color: Colors.white,
      child: Padding(
        padding: EdgeInsets.symmetric(horizontal: 18),
        child: Directionality(
            textDirection: TextDirection.ltr,
            child: Row(
              mainAxisSize: MainAxisSize.max,
              mainAxisAlignment: MainAxisAlignment.spaceAround,
              children: [
                BottomNavigationItem(
                  icon: DQIcons.my_medical_file,
                  activeIcon: DQIcons.my_medical_file,
                  changeIndex: _changeIndex,
                  index: widget.index,
                  currentIndex: 1,
                  name: TranslationBase.of(context).medicalProfile,
                ),
                BottomNavigationItem(
                  icon: DQIcons.family,
                  activeIcon: DQIcons.family,
                  changeIndex: _changeIndex,
                  index: widget.index,
                  currentIndex: 3,
                  name: TranslationBase.of(context).myFamily,
                ),
                if (widget.index == 0)
                  Expanded(
                    child: (widget.showHomeIcon)
                        ? SizedBox(
                            child: BottomNavigationItem(
                              icon: Icons.home_outlined,
                              activeIcon: Icons.home_outlined,
                              changeIndex: _changeIndex,
                              index: widget.index,
                              currentIndex: 2,
                              name: TranslationBase.of(context).home,
                            ),
                          )
                        : SizedBox(
                            height: 50,
                            child: Column(
                              mainAxisSize: MainAxisSize.min,
                              mainAxisAlignment: MainAxisAlignment.center,
                              children: <Widget>[
                                SizedBox(height: 22),
                              ],
                            ),
                          ),
                  ),
                if (widget.index != 0 && projectViewModel.havePrivilege(34))
                  BottomNavigationItem(
                    icon: Icons.home_outlined,
                    activeIcon: Icons.home_outlined,
                    changeIndex: _changeIndex,
                    index: widget.index,
                    currentIndex: 0,
                    name: TranslationBase.of(context).home,
                  ),
                // BottomNavigationItem(
                //   icon: EvaIcons.calendar,
                //   activeIcon: EvaIcons.calendar,
                //   changeIndex: _changeIndex,
                //   index: _index,
                //   currentIndex: 2,
                //   name: TranslationBase.of(context).bookAppo,
                // ),
                if (/*widget.index == 0 && */ projectViewModel
                    .havePrivilege(34))
                  BottomNavigationItem(
                    icon: EvaIcons.calendar,
                    activeIcon: EvaIcons.calendar,
                    changeIndex: _changeIndex,
                    index: widget.index,
                    currentIndex: 4,
                    name: TranslationBase.of(context).todoList,
                  ),
                if (projectViewModel.havePrivilege(77))
                  BottomNavigationItem(
                    icon: DQIcons.roboticon,
                    activeIcon: DQIcons.roboticon,
                    changeIndex: _changeIndex,
                    index: widget.index,
                    currentIndex: 0,
                    name: TranslationBase.of(context).help,
                  )
              ],
            )),
      ),
    );
  }

  Future navigateToBookingOptions(context) async {
    Navigator.push(context, FadePage(page: BookingOptions()));
  }

  Future navigateToToDoList(context) async {
    Navigator.push(context, FadePage(page: ToDo(isShowAppBar: false)));
  }
}
