import 'dart:collection';

import 'package:aitrainer_app/bloc/customer_change/customer_change_bloc.dart';
import 'package:aitrainer_app/util/app_localization.dart';
import 'package:aitrainer_app/repository/customer_repository.dart';
import 'package:aitrainer_app/util/trans.dart';
import 'package:aitrainer_app/widgets/app_bar_min.dart';
import 'package:aitrainer_app/widgets/app_bar_progress.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_form_bloc/flutter_form_bloc.dart';

class GoalsItem {
  static String muscle = "gain_muscle";
  static String weight = "weight_loss";
}

// ignore: must_be_immutable
class CustomerGoalPage extends StatefulWidget {
  @override
  State<StatefulWidget> createState() => _CustomerGoalPage();
}

class _CustomerGoalPage extends State<CustomerGoalPage> with Trans {
  String selected;
  bool fulldata = false;

  @override
  Widget build(BuildContext context) {
    setContext(context);

    CustomerRepository customerRepository;
    dynamic args = ModalRoute.of(context).settings.arguments;
    if (args is HashMap && args['personal_data'] != null) {
      fulldata = args['personal_data'];
      customerRepository = args['bloc'];
    } else {
      customerRepository = ModalRoute.of(context).settings.arguments;
    }

    return Scaffold(
        appBar: fulldata
            ? AppBarMin(
                back: true,
              )
            : AppBarProgress(max: 50, min: 26),
        body: Container(
          decoration: BoxDecoration(
            image: DecorationImage(
              image: AssetImage('asset/image/WT_light_background.jpg'),
              fit: BoxFit.cover,
              alignment: Alignment.center,
            ),
          ),
          height: double.infinity,
          width: double.infinity,
          child: BlocProvider(
            create: (context) => CustomerChangeBloc(customerRepository: customerRepository),
            child: Builder(builder: (context) {
              CustomerChangeBloc changeBloc = BlocProvider.of<CustomerChangeBloc>(context);

              return SingleChildScrollView(
                  child: Center(
                child: Column(
                  children: [
                    Divider(),
                    InkWell(
                      child: Text(
                        AppLocalizations.of(context).translate("Set Your Goals"),
                        style: TextStyle(color: Colors.orange, fontSize: 50, fontFamily: 'Arial', fontWeight: FontWeight.w900),
                      ),
                      highlightColor: Colors.white,
                    ),
                    Stack(alignment: Alignment.bottomLeft, overflow: Overflow.visible, children: [
                      FlatButton(
                          child: Image.asset(
                            "asset/image/Gain_muscle.jpg",
                            height: 180,
                          ),
                          padding: EdgeInsets.all(0.0),
                          shape: getShape(changeBloc, GoalsItem.muscle),
                          onPressed: () => {
                                setState(() {
                                  selected = GoalsItem.muscle;
                                  changeBloc.add(CustomerGoalChange(goal: GoalsItem.muscle));
                                }),
                              }),
                      InkWell(
                        child: Text(
                          AppLocalizations.of(context).translate("Gain Muscle"),
                          style: TextStyle(color: Colors.white, fontSize: 32, fontFamily: 'Arial', fontWeight: FontWeight.w900),
                        ),
                        highlightColor: Colors.white,
                      )
                    ]),
                    Divider(),
                    Stack(alignment: Alignment.bottomLeft, overflow: Overflow.visible, children: [
                      FlatButton(
                          child: Image.asset(
                            "asset/image/WT_weight_loss.jpg",
                            height: 180,
                          ),
                          padding: EdgeInsets.all(0.0),
                          shape: getShape(changeBloc, GoalsItem.weight),
                          onPressed: () => {
                                setState(() {
                                  selected = GoalsItem.muscle;
                                  changeBloc.add(CustomerGoalChange(goal: GoalsItem.weight));
                                }),
                              }),
                      InkWell(
                        child: Text(
                          AppLocalizations.of(context).translate("Loose Weight"),
                          style: TextStyle(color: Colors.white, fontSize: 32, fontFamily: 'Arial', fontWeight: FontWeight.w900),
                        ),
                        highlightColor: Colors.white,
                      )
                    ]),
                    Divider(),
                    RaisedButton(
                      color: Colors.orange,
                      textColor: Colors.white,
                      child: Text(fulldata ? t("Save") : t("Next")),
                      onPressed: () => {
                        //changingViewModel.saveCustomer(),
                        changeBloc.add(CustomerSave()),
                        Navigator.of(context).pop(),
                        if (!fulldata) {Navigator.of(context).pushNamed("customerFitnessPage", arguments: changeBloc.customerRepository)}
                      },
                    )
                  ],
                ),
              ));
            }),
          ),
        ));
  }

  dynamic getShape(CustomerChangeBloc customerBloc, String goal) {
    String selectedGoal = customerBloc.customerRepository.goal;
    dynamic returnCode = (selectedGoal == goal)
        ? RoundedRectangleBorder(
            side: BorderSide(width: 4, color: Colors.red),
          )
        : null;
    //return
    return returnCode;
  }
}