import 'package:diplomaticquarterapp/core/enum/viewstate.dart';
import 'package:diplomaticquarterapp/core/viewModels/pharmacyModule/lacum-registration-viewModel.dart';
import 'package:diplomaticquarterapp/core/viewModels/project_view_model.dart';
import 'package:diplomaticquarterapp/pages/base/base_view.dart';
import 'package:diplomaticquarterapp/theme/colors.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:flutter/material.dart';
import 'package:provider/provider.dart';

class LakumActivationVidaPage extends StatelessWidget {
  ProjectViewModel projectViewModel;
  TextEditingController _identificationNumberController = new TextEditingController();

  @override
  Widget build(BuildContext context) {
    final mediaQuery = MediaQuery.of(context);
    projectViewModel = Provider.of(context);

    return BaseView<LacumRegistrationViewModel>(
      builder: (_, model, wi) => AppScaffold(
        appBarTitle: TranslationBase.of(context).accountActivation,
        isShowAppBar: true,
        isPharmacy: true,
        isShowDecPage: false,
        showPharmacyCart: false,
        showHomeAppBarIcon: false,
        isBottomBar: false,
        backgroundColor: Colors.white,
        baseViewModel: model,
        body: Container(
          margin: EdgeInsets.symmetric(vertical: 16, horizontal: 12),
          child: Column(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            crossAxisAlignment: CrossAxisAlignment.center,
            children: [
              Column(
                crossAxisAlignment: CrossAxisAlignment.center,
                children: [
                  Texts(
                    TranslationBase.of(context).accountActivationDesc,
                    fontSize: 14,
                  ),
                  Padding(
                    padding: const EdgeInsets.all(8.0),
                    child: TextField(
                      controller: _identificationNumberController,
                      decoration: new InputDecoration(hintText: TranslationBase.of(context).enterIdentificationNumber, focusColor: CustomColors.green),
                      keyboardType: TextInputType.number,
                      style: TextStyle(
                        fontSize: 16,
                        color: Colors.grey.shade700,
                      ),
                    ),
                  ),
                ],
              ),
              Container(
                margin: EdgeInsets.only(top: 4),
                child: BorderedButton(
                  TranslationBase.of(context).accountActivation,
                  // backgroundColor: _identificationNumberController.text != null && _identificationNumberController.text != "" ? CustomColors.green : Color(0xffb0b4b5),
                  textColor: Colors.white,
                  backgroundColor: CustomColors.green,
                  borderColor: CustomColors.green,
                  fontSize: 16,
                  hPadding: 8,
                  vPadding: 12,
                  handler: _identificationNumberController.text != null || _identificationNumberController.text != ""
                      ? () {
                          model.checkLacumAccountActivation(_identificationNumberController.text).then((_) {
                            if (model.state == ViewState.Idle) {
                              if (model.lacumInformation.status != "Hold") {
                                AppToast.showErrorToast(message: TranslationBase.of(context).lakumUnhold);
                                if (model.lacumInformation.status != "Discontinue") {
                                  AppToast.showErrorToast(message: TranslationBase.of(context).lakumDiscontinue);
                                }
                              } else {
                                if (model.lacumInformation.status == "Hold") {
                                  model.makeAccountActivate(projectViewModel.user.patientIdentificationNo).then((value) {
                                    AppToast.showSuccessToast(message: TranslationBase.of(context).lakumSuccess);
                                    Navigator.of(context).pop();
                                  });
                                }
                              }
                              // Navigator.push(context, FadePage(page: LakumRegistrationPage(_identificationNumberController.text))).then((status) => {
                              //       if (status == 200) {model.makeAccountActivate(projectViewModel.user.patientIdentificationNo)}
                              //       // back to previous page
                              //     })
                            }
                          });
                        }
                      : null,
                ),
              ),
            ],
          ),
        ),
      ),
    );
  }
}
