import 'package:diplomaticquarterapp/core/enum/filter_type.dart';
import 'package:diplomaticquarterapp/core/viewModels/medical/radiology_view_model.dart';
import 'package:diplomaticquarterapp/pages/base/base_view.dart';
import 'package:diplomaticquarterapp/pages/medical/radiology/radiology_details_page.dart';
import 'package:diplomaticquarterapp/uitl/date_uitl.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 RadiologyHomePage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return BaseView<RadiologyViewModel>(
      onModelReady: (model) => model.getPatientRadOrders(),
      builder: (_, model, widget) => AppScaffold(
        isShowAppBar: true,
        appBarTitle: 'Radiology',
        baseViewModel: model,
        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: const Text('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: const Text('Hospital'),
                        leading: Radio(
                          value: FilterType.Hospital,
                          groupValue: model.filterType,
                          activeColor: Colors.red[800],
                          onChanged: (FilterType value) {
                            model.setFilterType(value);
                          },
                        ),
                      ),
                    ),
                  )
                ],
              ),
              ...List.generate(
                model.finalRadiologyList.length,
                    (index) => AppExpandableNotifier(
                    title: model
                        .finalRadiologyList[index].filterName,
                    bodyWidget: Column(
                      crossAxisAlignment: CrossAxisAlignment.start,
                      mainAxisAlignment: MainAxisAlignment.spaceBetween,
                      children: model
                          .finalRadiologyList[index].finalRadiologyList
                          .map((radiology) {
                        return InkWell(
                          onTap: () => Navigator.push(
                            context,
                            FadePage(
                              page: RadiologyDetailsPage(finalRadiology: radiology,),
                            ),
                          ),
                          child: DoctorCard(
                            name: radiology.doctorName,
                            profileUrl: radiology.doctorImageURL,
                            subName: '${radiology.projectName} \nBill No ${radiology.invoiceNo}',
                            date: DateUtil.getMonthDayYearDateFormatted(
                                radiology.orderDate),
                          ),
                        );
                      }).toList(),
                    )),
              )
            ],
          ),
        ),
      ),
    );
  }
}
