import 'dart:ffi';

import 'package:diplomaticquarterapp/config/size_config.dart';
import 'package:diplomaticquarterapp/pages/AlHabibMedicalService/health_calculator/bmi_calculator/bariatrics-screen.dart';
import 'package:diplomaticquarterapp/uitl/translations_delegate_base.dart';
import 'package:diplomaticquarterapp/widgets/buttons/borderedButton.dart';
import 'package:diplomaticquarterapp/widgets/buttons/button.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:percent_indicator/percent_indicator.dart';

class ResultPage extends StatelessWidget {
  final double finalResult;
  final String textResult;
  final String msg;

  ResultPage({this.finalResult, this.textResult, this.msg});

  Color inductorColor;
  double percent;

  Color colorInductor() {
    if (finalResult >= 30) {
      inductorColor = Color(0xffC70D00);
    } else if (finalResult < 30 && finalResult >= 25) {
      inductorColor = Color(0xffC25400);
    } else if (finalResult < 25 && finalResult >= 18.5) {
      inductorColor = Color(0xff36D600);
    } else if (finalResult < 18.5) {
      inductorColor = Color(0xff1BE0EE);
    }
    return inductorColor;
  }

  double percentInductor() {
    if (finalResult >= 30) {
      percent = 1.0;
    } else if (finalResult < 30 && finalResult >= 25) {
      percent = 0.73;
    } else if (finalResult < 25 && finalResult >= 18.5) {
      percent = 0.5;
    } else if (finalResult < 18.5) {
      percent = 0.25;
    }
    return percent;
  }

  @override
  Widget build(BuildContext context) {
    return AppScaffold(
      isShowDecPage: false,
      isShowAppBar: true,
      appBarTitle: "${TranslationBase.of(context).bmi} ${TranslationBase.of(context).calcHealth}",
      body: Column(
        children: [
          Expanded(
            child: SingleChildScrollView(
              child: Column(
                children: [
                  Container(
                    margin: EdgeInsets.only(top: 50),
                    child: Center(
                      child: CircularPercentIndicator(
                        radius: 220.0,
                        lineWidth: 20.0,
                        percent: percentInductor(),
                        center: Column(
                          mainAxisAlignment: MainAxisAlignment.center,
                          children: [
                            Text(
                              finalResult.toStringAsFixed(1),
                              style: TextStyle(
                                fontSize: 18.0,
                                fontWeight: FontWeight.bold,
                              ),
                            ),
                            SizedBox(
                              height: 5.0,
                            ),
                            Text(
                              textResult,
                              style: TextStyle(
                                fontSize: 16.0,
                                fontWeight: FontWeight.w600,
                              ),
                            ),
                          ],
                        ),
                        progressColor: colorInductor(),
                        backgroundColor: Colors.white,
                      ),
                    ),
                  ),
                  Container(
                    margin: EdgeInsets.symmetric(horizontal: 16, vertical: 16),
                    child: Texts(msg),
                  ),
                ],
              ),
            ),
          ),
          Container(
            margin: EdgeInsets.symmetric(horizontal: 16, vertical: 16),
            child: BorderedButton(
              TranslationBase.of(context).seeListOfDoctor,
              fontSize: SizeConfig.textMultiplier * 2.1,
              textColor: Colors.white,
              vPadding: 8,
              hPadding: 8,
              backgroundColor: Theme.of(context).primaryColor,
              radius: 8,
              fontWeight: FontWeight.bold,
              handler: () {
                Navigator.push(
                  context,
                  FadePage(page: BariatricsPage(1, 1, finalResult)),
                );
              },
            ),
          ),
        ],
      ),
    );
  }
}
