import 'package:badges/badges.dart';
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/widgets/data_display/text.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'package:provider/provider.dart';

import '../../Constants.dart';

class BottomNavigationItem extends StatelessWidget {
  final String icon;
  final String activeIcon;
  final ValueChanged<int> changeIndex;
  final int index;
  final int currentIndex;
  final String name;
  final bool isDisabled;

  AuthenticatedUserObject authenticatedUserObject = locator<AuthenticatedUserObject>();

  BottomNavigationItem({this.icon, this.activeIcon, this.changeIndex, this.index, this.currentIndex, this.name, this.isDisabled = false});

  @override
  Widget build(BuildContext context) {
    var model = Provider.of<ToDoCountProviderModel>(context);
    ProjectViewModel projectViewModel = Provider.of(context);
    return Expanded(
      child: SizedBox(
        // height: 72.0,
        child: Material(
          type: MaterialType.transparency,
          child: InkWell(
            highlightColor: Colors.transparent,
            splashColor: Colors.transparent,
            onTap: () {
              if (!isDisabled) changeIndex(currentIndex);
            },
            child: currentIndex != 4
                ? Column(
                    mainAxisSize: MainAxisSize.min,
                    mainAxisAlignment: MainAxisAlignment.center,
                    children: <Widget>[
                      SizedBox(
                        height: 15,
                      ),
                      icon == "assets/images/new/bottom_nav/help.svg" ? Container(
                        child: SvgPicture.asset(icon, height: 20, width: 20, fit: BoxFit.cover),
                      ) : Container(
                        child: SvgPicture.asset(icon, height: 20, width: 20, fit: BoxFit.cover, color: currentIndex == index
                                  ? Color(0xff333c45)
                                  : Color(0xff989898)),
                      ),
                      SizedBox(
                        height: 2,
                      ),
                      Texts(
                        name,
                        textAlign: TextAlign.center,
                        color: currentIndex == index
                            ? Color(0xff333c45)
                            : isDisabled
                                ? Colors.grey[300]
                                : Colors.grey,
                        fontSize: 11,
                      ),
                      SizedBox(
                        height: 7,
                      ),
                    ],
                  )
                : (authenticatedUserObject.isLogin && model.isShowBadge)
                    ? Stack(
                        alignment: AlignmentDirectional.center,
                        children: [
                          Column(
                            mainAxisSize: MainAxisSize.min,
                            mainAxisAlignment: MainAxisAlignment.center,
                            children: <Widget>[
                              SizedBox(
                                height: 15,
                              ),
                              Container(
                                child: SvgPicture.asset(icon, height: 20, width: 20, fit: BoxFit.cover, color: currentIndex == index
                                    ? Color(0xff333c45)
                                    : Color(0xff989898)),
                                // Icon(currentIndex == index ? activeIcon : icon, color: currentIndex == index ? secondaryColor : Theme.of(context).dividerColor, size: 22.0),
                              ),
                              SizedBox(
                                height: 2,
                              ),
                              Texts(
                                name,
                                textAlign: TextAlign.center,
                                color: currentIndex == index ? Color(0xff333c45) : Colors.grey,
                                fontSize: 11,
                              ),
                              SizedBox(
                                height: 7,
                              ),
                            ],
                          ),
                          Positioned(
                            right: 18.0,
                            bottom: 28.0,
                            child: Badge(
                              toAnimate: false,
                              position: BadgePosition.topEnd(),
                              shape: BadgeShape.circle,
                              badgeColor: secondaryColor.withOpacity(1.0),
                              borderRadius: BorderRadius.circular(8),
                              badgeContent: Container(
                                padding: EdgeInsets.all(2.0),
                                child: Text(model.count.toString(), style: TextStyle(color: Colors.white, fontSize: 14.0)),
                              ),
                            ),
                          ),
                        ],
                      )
                    : Column(
                        mainAxisSize: MainAxisSize.min,
                        mainAxisAlignment: MainAxisAlignment.center,
                        children: <Widget>[
                          SizedBox(
                            height: 15,
                          ),
                          Container(
                            child: SvgPicture.asset(icon, height: 20, width: 20, fit: BoxFit.cover),
                          ),
                          SizedBox(
                            height: 2,
                          ),
                          Texts(
                            name,
                            textAlign: TextAlign.center,
                            color: currentIndex == index
                                ? Color(0xff333c45)
                                : isDisabled
                                    ? Colors.grey[300]
                                    : Colors.grey,
                            fontSize: 11,
                          ),
                          SizedBox(
                            height: 7,
                          ),
                        ],
                      ),
          ),
        ),
      ),
    );
  }
}
