import 'dart:math' as math;

import 'package:diplomaticquarterapp/core/model/AlHabibMedicalService/insert_user_activity_request_model.dart';
import 'package:diplomaticquarterapp/core/viewModels/AlHabibMedicalService/H2O_view_model.dart';
import 'package:diplomaticquarterapp/pages/AlHabibMedicalService/h2o/Dialog/confirm_add_amount_dialog.dart';
import 'package:diplomaticquarterapp/pages/base/base_view.dart';
import 'package:diplomaticquarterapp/uitl/translations_delegate_base.dart';
import 'package:diplomaticquarterapp/widgets/data_display/text.dart';
import 'package:diplomaticquarterapp/widgets/transitions/fade_page.dart';
import 'package:flutter/material.dart';

import '../add_custom_amount.dart';

class H20FloatingActionButton extends StatelessWidget {
  const H20FloatingActionButton({
    Key key,
    @required AnimationController controller,
    @required this.model

  })  : _controller = controller,
        super(key: key);

  final AnimationController _controller;
  final H2OViewModel model;
  @override
  Widget build(BuildContext context) {
    // _showMaterialDialog(String count, H2OViewModel model) {
    //   return SimpleDialog(
    //     contentPadding: EdgeInsets.fromLTRB(28.0, 24.0, 28.0, 0.0),
    //     title: Center(
    //       child: Texts(
    //         "Confirm",
    //         color: Colors.black,
    //       ),
    //     ),
    //     children: [
    //       Column(
    //         children: [
    //           Divider(),
    //           Center(
    //             child: Texts(
    //               "Are you sure you want to Add $count ?",
    //               color: Colors.grey,
    //             ),
    //           ),
    //           SizedBox(
    //             height: 5.0,
    //           ),
    //           Row(
    //             // mainAxisAlignment: MainAxisAlignment.spaceBetween,
    //             children: <Widget>[
    //               Expanded(
    //                 flex: 1,
    //                 child: InkWell(
    //                   onTap: () {
    //                     Navigator.pop(context);
    //                   },
    //                   child: Padding(
    //                     padding: const EdgeInsets.all(8.0),
    //                     child: Container(
    //                       child: Center(
    //                         child: Texts(
    //                           TranslationBase.of(context).cancel.toUpperCase(),
    //                           color: Colors.red,
    //                         ),
    //                       ),
    //                     ),
    //                   ),
    //                 ),
    //               ),
    //               Container(
    //                 width: 1,
    //                 height: 30,
    //                 color: Colors.grey[500],
    //               ),
    //               Expanded(
    //                 flex: 1,
    //                 child: InkWell(
    //                   onTap: () async{
    //                     // insertUserActivity
    //                     int addedValue;
    //
    //                     switch(count) {
    //                       case "600ml": {
    //                         addedValue = 600;
    //                       }
    //                       break;
    //
    //                       case "330ml": {
    //                         addedValue = 330;
    //
    //                       }
    //                       break;
    //                       case "200ml": {
    //                         addedValue = 200;
    //                       }
    //                       break;
    //
    //                     }
    //
    //                     InsertUserActivityRequestModel insertUserActivityRequestModel= InsertUserActivityRequestModel(quantityIntake:addedValue );
    //                     await model.insertUserActivity(insertUserActivityRequestModel);
    //                     Navigator.pop(context);
    //                   },
    //                   child: Padding(
    //                     padding: const EdgeInsets.all(8.0),
    //                     child: Center(
    //                         child: Texts(
    //                           TranslationBase.of(context).ok,
    //                           fontWeight: FontWeight.w400,
    //                         )),
    //                   ),
    //                 ),
    //               ),
    //             ],
    //           )
    //         ],
    //       )
    //     ],
    //   );
    // }

    void showConfirmMessage(int amount, H2OViewModel model) {
      showDialog(context: context, child: ConfirmAddAmountDialog(model: model,amount:amount,));
    }

    return Container(
      margin: EdgeInsets.only(left: 20),
      child: new Column(mainAxisSize: MainAxisSize.min, children: [
        Row(
          mainAxisAlignment: MainAxisAlignment.start,
          children: [
            Column(
              crossAxisAlignment: CrossAxisAlignment.end,
              children: [
                ActionButton(
                  controller: _controller,
                  text: "600ml",
                  onTap: () {
                    showConfirmMessage(600, model);
                  },
                ),
                ActionButton(
                  controller: _controller,
                  text: "330ml",
                  onTap: () {
                    showConfirmMessage(330, model);
                  },
                ),
                ActionButton(
                  controller: _controller,
                  text: "200ml",
                  onTap: () {
                    showConfirmMessage(200, model);
                  },
                ),
              ],
            ),
          ],
        ),
        Row(
          mainAxisAlignment: MainAxisAlignment.start,
          children: [
            FloatingActionButton(
              heroTag: null,
              child: new AnimatedBuilder(
                animation: _controller,
                builder: (BuildContext context, Widget child) {
                  return new Transform(
                    transform: new Matrix4.rotationZ(
                        _controller.value * 0.5 * math.pi),
                    alignment: FractionalOffset.center,
                    child: new Icon(
                        _controller.isDismissed ? Icons.add : Icons.close),
                  );
                },
              ),
              onPressed: () {
                if (_controller.isDismissed) {
                  _controller.forward();
                } else {
                  _controller.reverse();
                }
              },
            ),
            new Container(
              alignment: FractionalOffset.topCenter,
              child: new ScaleTransition(
                scale: new CurvedAnimation(
                  parent: _controller,
                  curve: new Interval(0.0, 1.0 - 0 / 6 / 2.0,
                      curve: Curves.easeOut),
                ),
                child: new FloatingActionButton(
                  backgroundColor: Colors.white,
                  heroTag: null,
                  mini: true,
                  child: Text(
                    "Custom",
                    textAlign: TextAlign.center,
                    style: TextStyle(fontSize: 14.0, color: Colors.grey),
                  ),
                  onPressed: () {
                    Navigator.push(
                      context,
                      FadePage(
                        page: AddCustomAmount(
                          model: model,
                        ),
                      ),
                    );
                  },
                ),
              ),
            ),
            new Container(
              alignment: FractionalOffset.topCenter,
              child: new ScaleTransition(
                scale: new CurvedAnimation(
                  parent: _controller,
                  curve: new Interval(0.0, 1.0 - 0 / 6 / 2.0,
                      curve: Curves.easeOut),
                ),
                child: new FloatingActionButton(
                  backgroundColor: Colors.white,
                  heroTag: null,
                  mini: true,
                  child: Text(
                    "Undo",
                    textAlign: TextAlign.center,
                    style: TextStyle(fontSize: 14.0, color: Colors.grey),
                  ),
                  onPressed: () {},
                ),
              ),
            ),
          ],
        ),
      ]),
    );
  }
}

class ActionButton extends StatelessWidget {
  const ActionButton(
      {Key key,
      @required AnimationController controller,
      @required this.text,
      this.onTap})
      : _controller = controller,
        super(key: key);

  final AnimationController _controller;
  final String text;
  final Function onTap;

  @override
  Widget build(BuildContext context) {
    return Container(
      alignment: FractionalOffset.topCenter,
      child: new ScaleTransition(
        scale: new CurvedAnimation(
          parent: _controller,
          curve: new Interval(0.0, 1.0 - 0 / 6 / 2.0, curve: Curves.easeOut),
        ),
        child: new FloatingActionButton(
          heroTag: null,
          backgroundColor: Colors.white,
          mini: true,
          child: Text(
            text,
            textAlign: TextAlign.center,
            style: TextStyle(fontSize: 14.0, color: Colors.grey),
          ),
          onPressed: onTap
        ),
      ),
    );
  }
}
