import 'package:doctor_app_flutter/core/enum/filter_type.dart';
import 'package:doctor_app_flutter/core/viewModel/prescriptions_view_model.dart';
import 'package:doctor_app_flutter/core/viewModel/project_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/prescription/prescription_items_page.dart';
import 'package:doctor_app_flutter/util/date-utils.dart';
import 'package:doctor_app_flutter/util/translations_delegate_base.dart';
import 'package:doctor_app_flutter/widgets/shared/app_expandable_notifier_new.dart';
import 'package:doctor_app_flutter/widgets/shared/app_scaffold_widget.dart';
import 'package:doctor_app_flutter/widgets/shared/doctor_card.dart';
import 'package:doctor_app_flutter/widgets/transitions/fade_page.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';

class PrescriptionsPage extends StatelessWidget {

  @override
  Widget build(BuildContext context) {
    final routeArgs = ModalRoute.of(context).settings.arguments as Map;
    PatiantInformtion patient = routeArgs['patient'];

    ProjectViewModel projectViewModel = Provider.of(context);
    return BaseView<PrescriptionsViewModel>(
        onModelReady: (model) => model.getPrescriptions(patient),
        builder: (_, model, w) => AppScaffold(
              baseViewModel: model,
              isShowAppBar: true,
              appBarTitle: TranslationBase.of(context).prescriptions,
              body: FractionallySizedBox(
                widthFactor: 1.0,
                child: ListView(
                  physics: BouncingScrollPhysics(),
                  children: <Widget>[
                    Row(
                      children: <Widget>[
                        Expanded(
                          flex: 1,
                          child: InkWell(
                            onTap: () => model
                                .setFilterType(FilterType.Clinic),
                            child: ListTile(
                              title: Text(TranslationBase.of(context).clinic),
                              leading: Radio(
                                value: FilterType.Clinic,
                                groupValue: model.filterType,
                                onChanged: (FilterType value) {
                                  model.setFilterType(value);
                                },
                              ),
                            ),
                          ),
                        ),
                        Expanded(
                          flex: 1,
                          child: InkWell(
                            onTap: () => model
                                .setFilterType(FilterType.Hospital),
                            child: ListTile(
                              title: Text(TranslationBase.of(context).hospital),
                              leading: Radio(
                                value: FilterType.Hospital,
                                groupValue: model.filterType,
                                onChanged: (FilterType value) {
                                  model.setFilterType(value);
                                },
                              ),
                            ),
                          ),
                        )
                      ],
                    ),
                    ...List.generate(
                      model.prescriptionsOrderList.length,
                      (index) => AppExpandableNotifier(
                          title: model
                              .prescriptionsOrderList[index].filterName,
                          bodyWidget: Column(
                            crossAxisAlignment: CrossAxisAlignment.start,
                            mainAxisAlignment: MainAxisAlignment.spaceBetween,
                            children: model
                                .prescriptionsOrderList[index].prescriptionsList
                                .map((prescriptions) {
                              return InkWell(
                                onTap: () => Navigator.push(
                                  context,
                                  FadePage(
                                    page: PrescriptionItemsPage(
                                      prescriptions: prescriptions,
                                      patient: patient,
                                    ),
                                  ),
                                ),
                                child: DoctorCard(
                                  name: prescriptions.doctorName,
                                  profileUrl: prescriptions.doctorImageURL,
                                  rat:
                                      prescriptions.actualDoctorRate.toDouble(),
                                  subName: prescriptions.name,
                                  isInOutPatient: prescriptions.isInOutPatient,
                                  isLiveCareAppointment:
                                      prescriptions.isLiveCareAppointment,
                                  date: projectViewModel.isArabic
                                      ? DateUtils
                                          .getMonthDayYearDateFormattedAr(
                                              DateUtils.convertStringToDate(
                                                  prescriptions
                                                      .appointmentDate))
                                      : DateUtils.getMonthDayYearDateFormatted(
                                          DateUtils.convertStringToDate(
                                              prescriptions.appointmentDate)),
                                ),
                              );
                            }).toList(),
                          )),
                    )
                  ],
                ),
              ),
            ));
  }
}
