import 'package:doctor_app_flutter/core/viewModel/pednding_orders_view_model.dart';
import 'package:doctor_app_flutter/core/model/patient/patiant_info_model.dart';
import 'package:doctor_app_flutter/screens/base/base_view.dart';
import 'package:doctor_app_flutter/utils/translations_delegate_base_utils.dart';
import 'package:doctor_app_flutter/widgets/patients/profile/app_bar/patient-profile-app-bar.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/card_with_bg_widget.dart';
import 'package:doctor_app_flutter/widgets/shared/errors/error_message.dart';
import 'package:flutter/material.dart';

class PendingOrdersScreen extends StatelessWidget {
  const PendingOrdersScreen({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    final routeArgs = ModalRoute.of(context)!.settings.arguments as Map;
    PatiantInformtion patient = routeArgs['patient'];
    patient = routeArgs['patient'];
    String patientType = routeArgs['patientType'];
    bool isInpatient = routeArgs['isInpatient'];
    var isVidaPlus = routeArgs['isVidaPlusProject'];

    return BaseView<PendingOrdersViewModel>(
      onModelReady: (model) => model.getPendingOrders(patientId: patient.patientMRN!, admissionNo: isVidaPlus? patient.admissionID?? 0 :int.parse(patient.admissionNo!), isVidaPlus: isVidaPlus),
      builder: (BuildContext context, PendingOrdersViewModel model, Widget? child) => AppScaffold(
        appBar: PatientProfileAppBar(
          patient,
          isInpatient: isInpatient,
        ),
        isShowAppBar: true,
        baseViewModel: model,
        appBarTitle: "Pending Orders",
        body: model.pendingOrdersList == null || model.pendingOrdersList.length == 0
            ? Center(
                child: ErrorMessage(
                  error: TranslationBase.of(context).noDataAvailable,
                ),
              )
            : Column(
                children: [
                  Padding(
                    padding: const EdgeInsets.all(8.0),
                    child: Column(
                      children: [
                        Row(
                          children: [
                            AppText(
                              TranslationBase.of(context).pending,
                              fontSize: 15.0,
                              fontWeight: FontWeight.w600,
                              fontFamily: 'Poppins',
                            ),
                          ],
                        ),
                        Row(
                          children: [
                            AppText(
                              TranslationBase.of(context).orders,
                              fontSize: 25.0,
                              fontWeight: FontWeight.w700,
                            ),
                          ],
                        ),
                      ],
                    ),
                  ),
                  Expanded(
                    child: Container(
                      height: MediaQuery.of(context).size.height * .9,
                      child: ListView.builder(
                          itemCount: model.pendingOrdersList.length,
                          itemBuilder: (BuildContext ctxt, int index) {
                            return FractionallySizedBox(
                              widthFactor: 0.95,
                              child: CardWithBgWidget(
                                hasBorder: false,
                                bgColor: Colors.transparent,
                                widget: Column(
                                  children: [
                                    Padding(
                                      padding: EdgeInsets.all(8.0),
                                      child: AppText(model.pendingOrdersList[index].notes!),
                                    ),
                                    SizedBox(
                                      height: 20,
                                    ),
                                  ],
                                ),
                              ),
                            );
                          }),
                    ),
                  ),
                ],
              ),
      ),
    );
  }
}
