import 'package:hmg_patient_app/core/model/AlHabibMedicalService/HealthCalculator/DiseasesByClinic.dart';
import 'package:hmg_patient_app/core/viewModels/AlHabibMedicalService/health-calculator/Bariatrics-viewmodel.dart';
import 'package:hmg_patient_app/pages/base/base_view.dart';
import 'package:hmg_patient_app/theme/colors.dart';
import 'package:hmg_patient_app/uitl/translations_delegate_base.dart';
import 'package:hmg_patient_app/widgets/data_display/text.dart';
import 'package:hmg_patient_app/widgets/others/app_scaffold_widget.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_rating_bar/flutter_rating_bar.dart';

class DoctorList extends StatelessWidget {
  DiseasesByClinic diseaseByClinic;

  DoctorList({Key? key, required this.diseaseByClinic}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return BaseView<BariatricsViewModel>(
        allowAny: true,
        onModelReady: (model) => model.getDoctorList(disease: diseaseByClinic),
        builder: (BuildContext context, BariatricsViewModel model, Widget? child) => AppScaffold(
              isShowDecPage: false,
              isShowAppBar: true,
              baseViewModel: model,
              appBarTitle: "Doctors List",
              description: TranslationBase.of(context).infoApprovals,
              infoList: TranslationBase.of(context).infoApprovalPoints,
              body: ListView.builder(
                  itemCount: model.doctorLists.length,
                  itemBuilder: (BuildContext context, int index) {
                    return Padding(
                      padding: EdgeInsets.symmetric(horizontal: 16.0, vertical: 10.0),
                      child: Container(
                        //height: MediaQuery.of(context).size.height * 0.09,
                        decoration: BoxDecoration(color: Colors.white),

                        child: ExpansionTile(
                          title: Padding(
                            padding: EdgeInsets.all(21.0),
                            child: Texts(model.doctorLists[index].filterName),
                          ),
                          children: model.doctorLists[index].doctorsByTimeList
                              .map((doctor) => Card(
                                    margin: EdgeInsets.fromLTRB(10.0, 16.0, 10.0, 8.0),
                                    color: Colors.white,
                                    shape: RoundedRectangleBorder(
                                      borderRadius: BorderRadius.circular(10),
                                    ),
                                    child: Container(
                                      decoration: BoxDecoration(),
                                      padding: EdgeInsets.all(7.0),
                                      width: MediaQuery.of(context).size.width,
                                      child: Row(
                                        mainAxisAlignment: MainAxisAlignment.start,
                                        children: <Widget>[
                                          Expanded(
                                            flex: 1,
                                            child: ClipRRect(
                                              borderRadius: BorderRadius.circular(100.0),
                                              child: Image.network(doctor.doctorImageURL!, fit: BoxFit.fill, height: 60.0, width: 60.0),
                                            ),
                                          ),
                                          Expanded(
                                            flex: 4,
                                            child: Container(
                                              width: MediaQuery.of(context).size.width * 0.55,
                                              margin: EdgeInsets.fromLTRB(20.0, 10.0, 10.0, 0.0),
                                              child: Column(
                                                crossAxisAlignment: CrossAxisAlignment.start,
                                                children: <Widget>[
                                                  if (doctor.doctorTitle != null)
                                                    Text(doctor.doctorTitle! + " " + doctor.name!, style: TextStyle(fontSize: 14.0, color: Colors.grey[700], letterSpacing: 1.0)),
                                                  Container(
                                                    margin: EdgeInsets.only(top: 3.0),
                                                    child: Text(doctor.clinicName != null ? doctor.clinicName! : "", style: TextStyle(fontSize: 12.0, color: Colors.grey[600], letterSpacing: 1.0)),
                                                  ),
                                                  Container(
                                                    margin: EdgeInsets.only(top: 3.0),
                                                    child: Text(doctor.projectName!, style: TextStyle(fontSize: 12.0, color: Colors.grey[600], letterSpacing: 1.0)),
                                                  ),
                                                  Row(
                                                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                                                    mainAxisSize: MainAxisSize.max,
                                                    children: <Widget>[
                                                      //  RatingBar.readOnly(
                                                      //  initialRating: doctor.actualDoctorRate.toDouble(),
                                                      //  size: 20.0,
                                                      //  filledColor: Colors.yellow[700],
                                                      //  emptyColor: Colors.grey[500],
                                                      //    isHalfAllowed: true,
                                                      //    halfFilledIcon: Icons.star_half,
                                                      //    filledIcon: Icons.star,
                                                      //     emptyIcon: Icons.star,
                                                      //   ),

                                                      // Changed By Aamir
                                                      RatingBar(
                                                        initialRating: 3,
                                                        direction: Axis.horizontal,
                                                        allowHalfRating: true,
                                                        itemCount: 5,
                                                        itemSize: 20,
                                                        ignoreGestures: true,
                                                        ratingWidget: RatingWidget(
                                                          full: Icon(
                                                            Icons.star,
                                                            color: CustomColors.accentColor,
                                                          ),
                                                          half: Icon(
                                                            Icons.star_half,
                                                            color: CustomColors.accentColor,
                                                          ),
                                                          empty: Icon(
                                                            Icons.star,
                                                            color: CustomColors.accentColor,
                                                          ),
                                                        ),
                                                        tapOnlyMode: true,
                                                        unratedColor: Colors.grey[500],
                                                        itemPadding: EdgeInsets.symmetric(horizontal: 4.0),
                                                        onRatingUpdate: (rating) {
                                                          print(rating);
                                                        },
                                                      ),
                                                      Container(
                                                        child: Image.network(doctor.nationalityFlagURL!, width: 25.0, height: 25.0),
                                                      ),
                                                    ],
                                                  ),
                                                ],
                                              ),
                                            ),
                                          ),
                                        ],
                                      ),
                                    ),
                                  ))
                              .toList(),
                        ),
                      ),
                    );
                  }),
            ));
  }
}
