import 'package:diplomaticquarterapp/config/size_config.dart';
import 'package:diplomaticquarterapp/core/enum/viewstate.dart';
import 'package:diplomaticquarterapp/core/model/AlHabibMedicalService/HealthCalculator/DiseasesByClinic.dart';
import 'package:diplomaticquarterapp/core/viewModels/AlHabibMedicalService/health-calculator/Bariatrics-viewmodel.dart';
import 'package:diplomaticquarterapp/core/viewModels/project_view_model.dart';
import 'package:diplomaticquarterapp/pages/AlHabibMedicalService/health_calculator/doctor_list.dart';
import 'package:diplomaticquarterapp/pages/base/base_view.dart';
import 'package:diplomaticquarterapp/uitl/app_toast.dart';
import 'package:diplomaticquarterapp/uitl/translations_delegate_base.dart';
import 'package:diplomaticquarterapp/widgets/buttons/borderedButton.dart';
import 'package:diplomaticquarterapp/widgets/data_display/text.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';

// TODO mosa_remark
class BariatricsPage extends StatefulWidget {
  final age;
  final gender;
  final double obeseResult;

  BariatricsPage(this.age, this.gender, this.obeseResult);

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

class _BariatricsPageState extends State<BariatricsPage> {
  DiseasesByClinic _selectedDisease;

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

    return BaseView<BariatricsViewModel>(
      onModelReady: (model) => model.getClinicCategory(),
      builder: (_, model, w) => AppScaffold(
        isShowDecPage: false,
        isShowAppBar: true,
        appBarTitle: "${TranslationBase.of(context).bariatrics}",
        baseViewModel: model,
        body: Column(
          children: [
            Container(
              margin: EdgeInsets.all(8.0),
              child: Center(
                child: Texts(TranslationBase.of(context).bariatricsHeaderMsg),
              ),
            ),
            Expanded(
              child: Container(
                margin: EdgeInsets.symmetric(horizontal: 16.0, vertical: 8.0),
                child: Row(
                  children: [
                    Expanded(
                      child: SingleChildScrollView(
                        child: Column(
                          children: [
                            ...model.diseasesList
                                .map((item) => RadioListTile(
                                      title: Texts("${item.diseases}"),
                                      activeColor: Colors.blue.shade700,
                                      value: item.diseasesID,
                                      groupValue: _selectedDisease != null ? _selectedDisease.diseasesID : -1,
                                      selected: _selectedDisease != null
                                          ? item.diseasesID == _selectedDisease.diseasesID
                                          : false,
                                      onChanged: (val) {
                                        setState(() {
                                          _selectedDisease = item;
                                        });
                                      },
                                    ))
                                .toList()
                          ],
                        ),
                      ),
                    ),
                    Image.asset(
                      _getImageName(widget.gender, widget.obeseResult, projectProvider.isArabic),
                      fit: BoxFit.cover,
                    ),
                  ],
                ),
              ),
            ),
            Container(
              margin: EdgeInsets.symmetric(horizontal: 16, vertical: 16),
              child: BorderedButton(
                TranslationBase.of(context).continues,
                fontSize: SizeConfig.textMultiplier * 2.1,
                textColor: Colors.white,
                vPadding: 8,
                hPadding: 8,
                backgroundColor: Theme.of(context).primaryColor,
                radius: 8,
                fontWeight: FontWeight.bold,
                handler: () async {
                  Navigator.push(
                    context,
                    FadePage(page: DoctorList(diseaseByClinic: _selectedDisease,)),
                  );
                },
              ),
            ),
            Container(
              margin: EdgeInsets.only(bottom: 16.0, left: 16, right: 16),
              child: BorderedButton(
                TranslationBase.of(context).skip,
                fontSize: SizeConfig.textMultiplier * 2.1,
                textColor: Colors.blue,
                vPadding: 8,
                hPadding: 8,
                backgroundColor: Color(0x00000000),
                radius: 8,
                hasBorder: true,
                borderColor: Color(0x00000000),
                fontWeight: FontWeight.bold,
                handler: () async {
                  Navigator.push(
                    context,
                    FadePage(page: DoctorList()),
                  );
                },
              ),
            ),
          ],
        ),
      ),
    );
  }

  _getImageName(int gender, double obeseResult, bool isArabic) {
    String path = "assets/images/BMI/";
    double result = obeseResult;

    if (result < 18.5 && gender == 1) {
      path += "bmi_blue_male";
    } else if (result >= 18.5 && result <= 24.9 && gender == 1) {
      path += "bmi_green_male";
    } else if (result >= 25 && result <= 29.9 && gender == 1) {
      path += "bmi_yellow_male";
    } else if (result >= 30 && result <= 34.9 && gender == 1) {
      path += "bmi_orange_male";
    } else if (result >= 35 && gender == 1) {
      path += "bmi_red_male";
    } else if (result < 18.5 && gender == 2) {
      path += "bmi_blue_female";
    } else if (result >= 18.5 && result <= 24.9 && gender == 2) {
      path += "bmi_green_female";
    } else if (result >= 25 && result <= 29.9 && gender == 2) {
      path += "bmi_yellow_female";
    } else if (result >= 30 && result <= 34.9 && gender == 2) {
      path += "bmi_orange_female";
    } else if (result >= 35 && gender == 2) {
      path += "bmi_red_female";
    } else {
      path += "default.png";
    }

    if (isArabic) {
      path += "_ar.png";
    } else {
      path += "_en.png";
    }
    return path;
  }
}
