import 'package:diplomaticquarterapp/core/enum/filter_type.dart';
import 'package:diplomaticquarterapp/core/viewModels/medical/prescriptions_view_model.dart';
import 'package:diplomaticquarterapp/pages/medical/prescriptions/prescription_items_page.dart';
import 'package:diplomaticquarterapp/uitl/date_uitl.dart';
import 'package:diplomaticquarterapp/uitl/translations_delegate_base.dart';
import 'package:diplomaticquarterapp/widgets/data_display/medical/doctor_card.dart';
import 'package:diplomaticquarterapp/widgets/others/app_expandable_notifier.dart';
import 'package:diplomaticquarterapp/widgets/others/app_scaffold_widget.dart';
import 'package:diplomaticquarterapp/widgets/transitions/fade_page.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

class PrescriptionsPage extends StatelessWidget {
  final PrescriptionsViewModel prescriptionsViewModel;

  const PrescriptionsPage({Key key, this.prescriptionsViewModel})
      : super(key: key);

  @override
  Widget build(BuildContext context) {
    return AppScaffold(
      baseViewModel: prescriptionsViewModel,
      body: FractionallySizedBox(
        widthFactor: 1.0,
        child: ListView(
          physics: BouncingScrollPhysics(),
          children: <Widget>[
            Row(
              children: <Widget>[
                Expanded(
                  flex: 1,
                  child: InkWell(
                    onTap: () =>
                        prescriptionsViewModel.setFilterType(FilterType.Clinic),
                    child: ListTile(
                      title:  Text(TranslationBase.of(context).clinic),
                      leading: Radio(
                        value: FilterType.Clinic,
                        groupValue: prescriptionsViewModel.filterType,
                        activeColor: Colors.red[800],
                        onChanged: (FilterType value) {
                          prescriptionsViewModel.setFilterType(value);
                        },
                      ),
                    ),
                  ),
                ),
                Expanded(
                  flex: 1,
                  child: InkWell(
                    onTap: () => prescriptionsViewModel
                        .setFilterType(FilterType.Hospital),
                    child: ListTile(
                      title: Text(TranslationBase.of(context).hospital),
                      leading: Radio(
                        value: FilterType.Hospital,
                        groupValue: prescriptionsViewModel.filterType,
                        activeColor: Colors.red[800],
                        onChanged: (FilterType value) {
                          prescriptionsViewModel.setFilterType(value);
                        },
                      ),
                    ),
                  ),
                )
              ],
            ),
            ...List.generate(
              prescriptionsViewModel.prescriptionsOrderList.length,
              (index) => AppExpandableNotifier(
                  title: prescriptionsViewModel
                      .prescriptionsOrderList[index].filterName,
                  bodyWidget: Column(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: prescriptionsViewModel
                        .prescriptionsOrderList[index].prescriptionsList
                        .map((prescriptions) {
                      return InkWell(
                        onTap: () => Navigator.push(
                          context,
                          FadePage(
                            page: PrescriptionItemsPage(prescriptions: prescriptions,),
                          ),
                        ),
                        child: DoctorCard(
                          name: prescriptions.doctorName,
                          profileUrl: prescriptions.doctorImageURL,
                          rat: prescriptions.doctorRate.toDouble(),
                          subName: prescriptions.name,
                          date: DateUtil.getMonthDayYearDateFormatted(
                              prescriptions.dischargeDate),
                        ),
                      );
                    }).toList(),
                  )),
            )
          ],
        ),
      ),
    );
  }
}
