import 'package:doctor_app_flutter/core/model/pharmacy-intervention-model/intervention_history.dart';
import 'package:doctor_app_flutter/screens/pharmacy_intervention/PharmacyIntervention.dart';
import 'package:doctor_app_flutter/screens/pharmacy_intervention/viewmodel/pharmacy_intervention_view_model.dart';
import 'package:doctor_app_flutter/screens/pharmacy_intervention/widgets/intervention_history_item.dart';
import 'package:doctor_app_flutter/utils/translations_delegate_base_utils.dart';
import 'package:doctor_app_flutter/widgets/shared/app_texts_widget.dart';
import 'package:flutter/material.dart';

class InterventionHistoryBottomSheet extends StatelessWidget {
  final List<InterventionHistory> interventionList;

  // final ScrollController controller;
  final PharmacyInterventionViewModel model;

  const InterventionHistoryBottomSheet({super.key, required this.interventionList, required this.model});

  @override
  Widget build(BuildContext context) {
    return SizedBox(
      height: MediaQuery.sizeOf(context).height * (interventionList.length == 1 ? 0.5 : 0.7),
      child: Material(
        color: Color(0xFFF7F7F7),
        shape: RoundedRectangleBorder(borderRadius: BorderRadius.only(topLeft: Radius.circular(20), topRight: Radius.circular(20))),
        child: Padding(
          padding: EdgeInsets.symmetric(horizontal: 20.0, vertical: 32),
          child: SingleChildScrollView(
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                AppText(
                  TranslationBase.of(context).histories,
                  fontWeight: FontWeight.w700,
                  fontSize: 24,
                  color: Color(0xFF2B353E),
                ),
                SizedBox(
                  height: 16,
                ),
                Column(
                  mainAxisSize: MainAxisSize.min,
                  mainAxisAlignment: MainAxisAlignment.center,
                  children: [
                    ListView.separated(
                      shrinkWrap: true,
                      itemCount: interventionList.length,
                      physics: BouncingScrollPhysics(),
                      itemBuilder: (context, index) => Material(
                        shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(10)),
                        color: Colors.white,
                        child: InterventionHistoryItem(
                          remarksController: interventionList[index].remarksController,
                          interventionHistory: interventionList[index],
                          onAcceptClick: (intervention, remarks) {
                            model.updateInterventionDiseaseStatus(
                                remarks: remarks,
                                isAccepted: true,
                                interventionID: interventionList[index].interventionId.toString(),
                                successMessage: TranslationBase.of(context).interventionAcceptedSuccessfully,
                                errorMessage: TranslationBase.of(context).unableToPerformTheAction);
                            Navigator.pop(context);
                          },
                          onRejectClick: (intervention, remarks) {
                            model.updateInterventionDiseaseStatus(
                                remarks: remarks,
                                interventionID: interventionList[index].interventionId.toString(),
                                successMessage: TranslationBase.of(context).interventionRejectedSuccessfully,
                                errorMessage: TranslationBase.of(context).unableToPerformTheAction);
                            Navigator.pop(context);
                          },
                            ),
                          ),
                      separatorBuilder: (_, __) => Divider(),
                    )
                  ],
                )
              ],
            ),
          ),
        ),
      ),
    );
  }
}
