import 'package:easy_localization/easy_localization.dart';
import 'package:flutter/material.dart';
import 'package:hmg_patient_app_new/core/utils/utils.dart';
import 'package:hmg_patient_app_new/extensions/string_extensions.dart';
import 'package:hmg_patient_app_new/features/lab/lab_view_model.dart';
import 'package:hmg_patient_app_new/features/lab/models/resp_models/lab_result.dart';
import 'package:hmg_patient_app_new/generated/locale_keys.g.dart';
import 'package:hmg_patient_app_new/presentation/lab/lab_result_via_clinic/lab_order_result_item.dart';
import 'package:provider/provider.dart' show Selector, Provider, ReadContext;

import '../../../widgets/date_range_selector/viewmodel/date_range_view_model.dart';

class LabResultList extends StatelessWidget {
  late LabViewModel model;

  @override
  Widget build(BuildContext context) {
    model = Provider.of<LabViewModel>(context);
    return Selector<LabViewModel, List<LabResult>>(
      selector: (_, model) => model.mainLabResultsByHospitals,
      builder: (__, list, ___) {
        if (list.isEmpty && context.read<LabViewModel>().labSpecialResult.isEmpty) {
          // return Utils.getNoDataWidget(context,
          //     noDataText: LocaleKeys.noLabResults.tr(context: context));
          return Container();
        } else {
          return ListView.builder(
              physics: NeverScrollableScrollPhysics(),
              padding: EdgeInsets.zero,
              shrinkWrap: true,itemCount: list.length,itemBuilder: (____, index) {
            var labItem = list[index];
            return LabOrderResultItem(onTap: () {
                      context.read<DateRangeSelectorRangeViewModel>().flush();
                      model.getPatientLabResult(model.currentlySelectedPatientOrder!, labItem.description ?? "", labItem.testShortDescription ?? "", labItem.uOM ?? "");
                    },
                tests: labItem,
                index: index,
                iconColor: model.getColor(labItem.calculatedResultFlag ?? "N"),
                severityText: model.getSeverityText(labItem.calculatedResultFlag ?? "N"));
          });
        }
      },
    );
  }
}