import 'package:hmg_patient_app/core/viewModels/pharmacyModule/lacum-registration-viewModel.dart';
import 'package:hmg_patient_app/core/viewModels/project_view_model.dart';
import 'package:hmg_patient_app/pages/base/base_view.dart';
import 'package:hmg_patient_app/uitl/app_toast.dart';
import 'package:hmg_patient_app/uitl/translations_delegate_base.dart';
import 'package:hmg_patient_app/widgets/buttons/borderedButton.dart';
import 'package:hmg_patient_app/widgets/others/app_scaffold_widget.dart';
import 'package:flutter/material.dart';
import 'package:flutter_html/flutter_html.dart';
import 'package:provider/provider.dart';

class LakumTermsConditions extends StatelessWidget {
  final String firstName, lastName, mobileNo, identificationNo;
  final int languageId;

  LakumTermsConditions(this.identificationNo, this.firstName, this.lastName, this.mobileNo, this.languageId);

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

    return BaseView<LacumRegistrationViewModel>(
        onModelReady: (model) => model.getUserTermsAndConditionsForEPharmcy(),
        builder: (_, model, wi) => AppScaffold(
              appBarTitle: "${TranslationBase.of(context).register} ${TranslationBase.of(context).lakum}",
              isShowAppBar: true,
              isShowDecPage: false,
              backgroundColor: Colors.white,
              baseViewModel: model,
              body: Container(
                margin: EdgeInsets.all(8),
                width: double.infinity,
                child: Stack(
                  children: [
                    SingleChildScrollView(
                      child: Column(
                        mainAxisAlignment: MainAxisAlignment.start,
                        crossAxisAlignment: CrossAxisAlignment.start,
                        children: [
                          if (model.listUserAgreement != null && model.listUserAgreement.userAgreementLAKUM != null)
                            Html(
                              data: projectProvider.isArabic ? model.listUserAgreement.userAgreementLAKUMn : model.listUserAgreement.userAgreementLAKUM,
                            ),
                        ],
                      ),
                    ),
                    Align(
                      alignment: Alignment.bottomCenter,
                      child: Container(
                        height: 50,
                        margin: EdgeInsets.all(8),
                        child: BorderedButton(
                          TranslationBase.of(context).acceptLbl,
                          backgroundColor: Color(0xff60686b),
                          textColor: Colors.white,
                          fontSize: 16,
                          hPadding: 8,
                          vPadding: 12,
                          handler: () {
                            model.createNewLakumAccount("$firstName $lastName", mobileNo, identificationNo, languageId).then((status) => {
                                  if (status == 200) {Navigator.pop(context, "")} else {
                                    Navigator.pop(context, ""),
                                    AppToast.showErrorToast(message: model.error)
                                  }
                                  // back to previous page
                                });
                          },
                        ),
                      ),
                    ),
                  ],
                ),
              ),
            ));
  }
}
