import 'package:doctor_app_flutter/client/base_app_client.dart';
import 'package:doctor_app_flutter/core/viewModel/procedure_View_model.dart';
import 'package:doctor_app_flutter/models/patient/patiant_info_model.dart';
import 'package:doctor_app_flutter/screens/base/base_view.dart';
import 'package:doctor_app_flutter/screens/procedures/add-procedure-form.dart';
import 'package:doctor_app_flutter/screens/procedures/update-procedure.dart';
import 'package:doctor_app_flutter/util/helpers.dart';
import 'package:doctor_app_flutter/util/translations_delegate_base.dart';
import 'package:doctor_app_flutter/widgets/patients/profile/patient-page-header-widget.dart';
import 'package:doctor_app_flutter/widgets/patients/profile/patient-profile-header-new-design-app-bar.dart';
import 'package:doctor_app_flutter/widgets/patients/profile/patient-profile-header-new-design.dart';
import 'package:doctor_app_flutter/widgets/shared/Text.dart';
import 'package:doctor_app_flutter/widgets/shared/app_scaffold_widget.dart';
import 'package:doctor_app_flutter/widgets/shared/app_texts_widget.dart';
import 'package:doctor_app_flutter/widgets/shared/network_base_view.dart';
import 'package:flutter/material.dart';

import 'ProcedureCard.dart';

class ProcedureScreen extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    final routeArgs = ModalRoute.of(context).settings.arguments as Map;
    PatiantInformtion patient = routeArgs['patient'];
    String patientType = routeArgs['patientType'];
    String arrivalType = routeArgs['arrivalType'];
    return BaseView<ProcedureViewModel>(
      onModelReady: (model) => model.getProcedure(mrn: patient.patientId),
      builder: (BuildContext context, ProcedureViewModel model, Widget child) =>
          AppScaffold(
        isShowAppBar: true,
        appBar: PatientProfileHeaderNewDesignAppBar(
            patient, arrivalType ?? '0', patientType),
        body: NetworkBaseView(
          baseViewModel: model,
          child: SingleChildScrollView(
            child: Container(
              color: Colors.white,
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  SizedBox(
                    height: 12,
                  ),
                  Padding(
                    padding: const EdgeInsets.all(8.0),
                    child: Column(
                      crossAxisAlignment: CrossAxisAlignment.start,
                      children: [
                        Texts(
                          'Order Test or',
                          style: "caption2",
                          color: Colors.black,
                          fontSize: 13,
                        ),
                        Texts(
                          'Procedure',
                          bold: true,
                          fontSize: 22,
                        ),
                      ],
                    ),
                  ),
                  if (patientType != null && patientType == '7' && patient.patientStatusType == 43)
                    InkWell(
                      onTap: () {
                        addSelectedProcedure(context, model, patient);
                      },
                      child: Container(
                        width: double.maxFinite,
                        height: 140,
                        margin: EdgeInsets.all(10),
                        decoration: BoxDecoration(
                          color: Colors.grey[300],
                          borderRadius: BorderRadius.circular(10),
                        ),
                        child: Center(
                          child: Container(
                            height: 90,
                            child: Column(
                              children: [
                                Container(
                                  height: 40,
                                  width: 40,
                                  decoration: BoxDecoration(
                                    color: Colors.grey[600],
                                    borderRadius: BorderRadius.circular(10),
                                  ),
                                  child: Center(
                                    child: Icon(
                                      Icons.add,
                                      color: Colors.white,
                                    ),
                                  ),
                                ),
                                SizedBox(
                                  height: 10,
                                ),
                                Texts(
                                  'Add More Procedure',
                                  color: Colors.grey[600],
                                  fontWeight: FontWeight.w600,
                                )
                              ],
                            ),
                          ),
                        ),
                      ),
                    ),
                  if (model.procedureList.isNotEmpty)
                    ...List.generate(
                      model.procedureList[0].rowcount,
                      (index) => ProcedureCard(
                        categoryID:
                            model.procedureList[0].entityList[index].categoryID,
                        entityList: model.procedureList[0].entityList[index],
                        onTap: () {
                          if (model.procedureList[0].entityList[index].categoryID ==
                                  2 ||
                              model.procedureList[0].entityList[index].categoryID == 4)
                            updateProcedureForm(context,
                                model: model,
                                patient: patient,
                                remarks: model
                                    .procedureList[0].entityList[index].remarks,
                                orderType: model.procedureList[0]
                                    .entityList[index].orderType
                                    .toString(),
                                orderNo: model
                                    .procedureList[0].entityList[index].orderNo,
                                procedureName: model.procedureList[0]
                                    .entityList[index].procedureName,
                                categoreId: model.procedureList[0]
                                    .entityList[index].categoryID
                                    .toString(),
                                procedureId: model.procedureList[0]
                                    .entityList[index].procedureId,
                                limetNo: model.procedureList[0]
                                    .entityList[index].lineItemNo);
                          // } else
                          //   helpers.showErrorToast(
                          //       'You Cant Update This Procedure');
                        },
                      ),
                    ),
                ],
              ),
            ),
          ),
        ),
      ),
    );
  }
}
