import 'package:diplomaticquarterapp/core/viewModels/project_view_model.dart';
import 'package:diplomaticquarterapp/pages/AlHabibMedicalService/health_calculator/body_fat/body_fat.dart';
import 'package:diplomaticquarterapp/pages/AlHabibMedicalService/health_calculator/calorie_calculator/calorie_calculator.dart';
import 'package:diplomaticquarterapp/pages/AlHabibMedicalService/health_calculator/carbs/carbs.dart';
import 'package:diplomaticquarterapp/pages/AlHabibMedicalService/health_calculator/ovulation_period/ovulation_period.dart';
import 'package:diplomaticquarterapp/uitl/translations_delegate_base.dart';
import 'package:diplomaticquarterapp/widgets/data_display/medical/medical_profile_item.dart';
import 'package:diplomaticquarterapp/widgets/others/app_scaffold_widget.dart';
import 'package:diplomaticquarterapp/widgets/transitions/fade_page.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';

import 'health_calculator/bmi_calculator/bmi_calculator.dart';
import 'health_calculator/bmr_calculator/bmr_calculator.dart';
import 'health_calculator/delivery_due/delivery_due.dart';
import 'health_calculator/ideal_body/ideal_body.dart';

class HealthCalculators extends StatefulWidget {
  @override
  _HealthCalculatorsState createState() => _HealthCalculatorsState();
}

class _HealthCalculatorsState extends State<HealthCalculators> with SingleTickerProviderStateMixin {
  TabController _tabController;

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

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

  @override
  Widget build(BuildContext context) {
    ProjectViewModel projectViewModel = Provider.of(context);

    List<Widget> generalHealthList = getGeneralHealthList(context);
    List<Widget> womenHealthList = getWomenHealthList(context);

    return AppScaffold(
      isShowAppBar: true,
      isShowDecPage: false,
      showNewAppBar: true,
      showNewAppBarTitle: true,
      appBarTitle: TranslationBase.of(context).calculators,
      body: Column(
        children: [
          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: <Widget>[
              Container(
                width: MediaQuery.of(context).size.width * 0.35,
                child: Center(
                  child: Text(TranslationBase.of(context).generalHealth),
                ),
              ),
              Container(
                width: MediaQuery.of(context).size.width * 0.35,
                child: Center(
                  child: Text(TranslationBase.of(context).womanHealth),
                ),
              ),
            ],
          ),
          Expanded(
            child: TabBarView(
              physics: NeverScrollableScrollPhysics(),
              controller: _tabController,
              children: [
                Container(
                  // margin: EdgeInsets.all(20.0),
                  child: Column(
                    children: [
                      Padding(
                        padding: EdgeInsets.only(left: 12, right: 12, top: 20.0),
                        child: GridView.builder(
                          shrinkWrap: true,
                          primary: false,
                          physics: NeverScrollableScrollPhysics(),
                          gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(crossAxisCount: 3, childAspectRatio: 2 / 2, crossAxisSpacing: 12, mainAxisSpacing: 12),
                          padding: EdgeInsets.zero,
                          itemCount: generalHealthList.length,
                          itemBuilder: (BuildContext context, int index) {
                            return generalHealthList[index];
                          },
                        ),
                      ),
                    ],
                  ),
                ),
                Container(
                  // margin: EdgeInsets.all(20.0),
                  child: Column(
                    children: [
                      Padding(
                        padding: EdgeInsets.only(left: 12, right: 12, top: 20.0),
                        child: GridView.builder(
                          shrinkWrap: true,
                          primary: false,
                          physics: NeverScrollableScrollPhysics(),
                          gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(crossAxisCount: 3, childAspectRatio: 2 / 2, crossAxisSpacing: 12, mainAxisSpacing: 12),
                          padding: EdgeInsets.zero,
                          itemCount: womenHealthList.length,
                          itemBuilder: (BuildContext context, int index) {
                            return womenHealthList[index];
                          },
                        ),
                      ),
                    ],
                  ),
                ),
              ],
            ),
          ),
        ],
      ),
    );
  }

  List<Widget> getGeneralHealthList(BuildContext context) {
    List<Widget> medical = List();

    medical.add(InkWell(
      onTap: () => Navigator.push(
        context,
        FadePage(page: BMICalculator()),
      ),
      child: MedicalProfileItem(
        title: TranslationBase.of(context).bmi,
        imagePath: 'bmi.svg',
        subTitle: TranslationBase.of(context).calcHealth,

      ),
    ));

    medical.add(InkWell(
      onTap: () => Navigator.push(
        context,
        FadePage(page: CalorieCalculator()),
      ),
      child: MedicalProfileItem(
        title: TranslationBase.of(context).calories,
        imagePath: 'calories_calc.svg',
        subTitle: TranslationBase.of(context).calcHealth,

      ),
    ));

    medical.add(InkWell(
      onTap: () => Navigator.push(
        context,
        FadePage(page: BmrCalculator()),
      ),
      child: MedicalProfileItem(
        title: TranslationBase.of(context).bmr,
        imagePath: 'bmr_calc.svg',
        subTitle: TranslationBase.of(context).calcHealth,

      ),
    ));

    medical.add(InkWell(
      onTap: () => Navigator.push(
        context,
        FadePage(page: IdealBody()),
      ),
      child: MedicalProfileItem(
        title: TranslationBase.of(context).idealBody,
        imagePath: 'ideal_weight_calc.svg',
        subTitle: TranslationBase.of(context).weight,

      ),
    ));

    medical.add(InkWell(
      onTap: () => Navigator.push(
        context,
        FadePage(page: BodyFat()),
      ),
      child: MedicalProfileItem(
        title: TranslationBase.of(context).bodyWord,
        imagePath: 'bmr_calc.svg',
        subTitle: TranslationBase.of(context).fat,

      ),
    ));

    medical.add(InkWell(
      onTap: () => Navigator.push(
        context,
        FadePage(page: Carbs()),
      ),
      child: MedicalProfileItem(
        title: TranslationBase.of(context).carbohydrate,
        imagePath: 'carbs_proteitn_fat.svg',
        subTitle: TranslationBase.of(context).proteinFat,

      ),
    ));

    return medical;
  }

  List<Widget> getWomenHealthList(BuildContext context) {
    List<Widget> medical = List();

    medical.add(InkWell(
      onTap: () => Navigator.push(
        context,
        FadePage(page: OvulationPeriod()),
      ),
      child: MedicalProfileItem(
        title: TranslationBase.of(context).ovulation,
        imagePath: 'ovulation.svg',
        subTitle: TranslationBase.of(context).period,
      ),
    ));

    medical.add(InkWell(
      onTap: () => Navigator.push(
        context,
        FadePage(page: DeliveryDue()),
      ),
      child: MedicalProfileItem(
        title: TranslationBase.of(context).delivery,
        imagePath: 'delivery.svg',
        subTitle: TranslationBase.of(context).dueDate,
      ),
    ));

    return medical;
  }
}
