import 'dart:ui';

import 'package:hmg_patient_app/config/config.dart';
import 'package:hmg_patient_app/core/model/ImagesInfo.dart';
import 'package:hmg_patient_app/core/viewModels/AlHabibMedicalService/H2O_view_model.dart';
import 'package:hmg_patient_app/core/viewModels/project_view_model.dart';
import 'package:hmg_patient_app/extensions/string_extensions.dart';
import 'package:hmg_patient_app/pages/AlHabibMedicalService/h2o/h20_setting.dart';
import 'package:hmg_patient_app/pages/AlHabibMedicalService/h2o/month_page.dart';
import 'package:hmg_patient_app/pages/AlHabibMedicalService/h2o/today_page.dart';
import 'package:hmg_patient_app/pages/AlHabibMedicalService/h2o/week_page.dart';
import 'package:hmg_patient_app/pages/ToDoList/ToDo.dart';
import 'package:hmg_patient_app/pages/base/base_view.dart';
import 'package:hmg_patient_app/pages/medical/medical_profile_page_new.dart';
import 'package:hmg_patient_app/routes.dart';
import 'package:hmg_patient_app/uitl/translations_delegate_base.dart';
import 'package:hmg_patient_app/widgets/bottom_navigation/bottom_nav_bar.dart';
import 'package:hmg_patient_app/widgets/others/app_scaffold_widget.dart';
import 'package:hmg_patient_app/widgets/transitions/fade_page.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';

class H2OPage extends StatefulWidget {
  @override
  _H2OPageState createState() => _H2OPageState();
}

class _H2OPageState extends State<H2OPage> with SingleTickerProviderStateMixin {
  late TabController _tabController;

  @override
  void initState() {
    super.initState();
    _tabController = TabController(
      length: 3,
      vsync: this,
    );
  }

  @override
  void dispose() {
    super.dispose();
    _tabController.dispose();
  }

  @override
  Widget build(BuildContext context) {
    ProjectViewModel projectViewModel = Provider.of(context);
    return BaseView<H2OViewModel>(
      onModelReady: (model) => model.getUserDetail(),
      builder: (_, model, widget) => AppScaffold(
        isShowAppBar: true,
        appBarTitle: TranslationBase.of(context).waterTracker,
        description: TranslationBase.of(context).h2oInfo,
        showNewAppBar: true,
        showNewAppBarTitle: true,
        backgroundColor: Color(0xffF7F7F7),
        imagesInfo: [
          ImagesInfo(imageEn: 'https://hmgwebservices.com/Images/MobileApp/images-info-home/h2o/en/0.png', imageAr: 'https://hmgwebservices.com/Images/MobileApp/images-info-home/h2o/ar/0.png')
        ],
        showHomeAppBarIcon: false,
        baseViewModel: model,
        isHelp: true,
        appBarIcons: [
          if (model.isLogin)
            IconButton(
              icon: Icon(Icons.settings),
              color: Color(0xff2B353E),
              onPressed: () {
                Navigator.push(
                  context,
                  FadePage(
                    page: H2oSetting(userDetailModel: model.userDetail, viewModel: model),
                  ),
                );
              },
            ),
        ],
        body: Column(
          children: <Widget>[
            TabBar(
              controller: _tabController,
              indicatorWeight: 3.0,
              indicatorSize: TabBarIndicatorSize.tab,
              labelColor: Color(0xff2B353E),
              unselectedLabelColor: Color(0xff575757),
              labelPadding: EdgeInsets.only(top: 15, bottom: 13, left: 20, right: 20),
              labelStyle: TextStyle(
                fontFamily: projectViewModel.isArabic ? 'Cairo' : 'Poppins',
                fontSize: 16,
                fontWeight: FontWeight.w600,
                letterSpacing: -0.48,
              ),
              unselectedLabelStyle: TextStyle(
                fontFamily: projectViewModel.isArabic ? 'Cairo' : 'Poppins',
                fontSize: 16,
                fontWeight: FontWeight.w600,
                letterSpacing: -0.48,
              ),
              tabs: [Text(TranslationBase.of(context).today), Text(TranslationBase.of(context).week), Text(TranslationBase.of(context).month.toLowerCase().capitalizeFirstofEach)],
            ),
            Expanded(
              child: TabBarView(
                physics: BouncingScrollPhysics(),
                controller: _tabController,
                children: <Widget>[TodayPage(), WeekPage(), MonthPage()],
              ),
            )
          ],
        ),
        bottomNavigationBar: BottomNavBar(
          changeIndex: (index) {
            if (index == 0) {
              IS_VOICE_COMMAND_CLOSED = false;
            } else if (index == 1) {
              Navigator.push(
                  context,
                  FadePage(
                      page: AppScaffold(
                          appBarTitle: TranslationBase.of(context).medicalProfile,
                          isShowAppBar: true,
                          showHomeAppBarIcon: false,
                          appBarIcons: [
                            IconButton(
                              icon: Image.asset("assets/images/new-design/setting_gear_icon.png"),
                              color: Colors.white,
                              onPressed: () => Navigator.of(context).pushNamed(
                                SETTINGS,
                              ),
                            ),
                          ],
                          body: MedicalProfilePageNew())));
            } else if (index == 2) {
              Navigator.of(context).pushNamedAndRemoveUntil(HOME, (Route<dynamic> route) => false);
            } else if (index == 3) {
              Navigator.of(context).pushNamed(MY_FAMILIY);
            } else if (index == 4) {
              Navigator.push(context, FadePage(page: ToDo(isShowAppBar: false)));
            }
          },
          showHomeIcon: true,
          index: 0,
        ),
      ),
    );
  }
}
