import 'package:diplomaticquarterapp/core/enum/filter_type.dart';
import 'package:diplomaticquarterapp/core/viewModels/medical/labs_view_model.dart';
import 'package:diplomaticquarterapp/pages/base/base_view.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';

import 'laboratory_result_page.dart';

class LabsHomePage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return BaseView<LabsViewModel>(
      onModelReady: (model) => model.getLabs(),
      builder: (context, LabsViewModel model, widget) => AppScaffold(
        baseViewModel: model,
        isShowAppBar: true,
        appBarTitle: TranslationBase.of(context).labOrders,
        body: SingleChildScrollView(
          physics: BouncingScrollPhysics(),
          child: FractionallySizedBox(
            widthFactor: 1.0,
            child: Center(
              child: Column(
                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,
                              activeColor: Colors.red[800],
                              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,
                              activeColor: Colors.red[800],
                              onChanged: (FilterType value) =>
                                  model.setFilterType(value),
                            ),
                          ),
                        ),
                      )
                    ],
                  ),
                  ...List.generate(
                    model.patientLabOrdersList.length,
                    (index) => AppExpandableNotifier(
                      title: model.patientLabOrdersList[index].filterName,
                      bodyWidget: Column(
                        crossAxisAlignment: CrossAxisAlignment.start,
                        mainAxisAlignment: MainAxisAlignment.spaceBetween,
                        children: model
                            .patientLabOrdersList[index].patientLabOrdersList
                            .map((labOrder) {
                          return DoctorCard(
                            onTap: () => Navigator.push(
                              context,
                              FadePage(
                                page: LaboratoryResultPage(
                                  patientLabOrders: labOrder,
                                ),
                              ),
                            ),
                            name: labOrder.doctorName,
                            profileUrl: labOrder.doctorImageURL,
                            subName: TranslationBase.of(context).billNo+' ${labOrder.invoiceNo}',
                            date: DateUtil.getMonthDayYearDateFormatted(
                                labOrder.orderDate),
                          );
                        }).toList(),
                      ),
                    ),
                  )
                ],
              ),
            ),
          ),
        ),
      ),
    );
  }
}
