import 'package:hmg_patient_app/core/viewModels/medical/ask_doctor_view_model.dart';
import 'package:hmg_patient_app/core/viewModels/project_view_model.dart';
import 'package:hmg_patient_app/pages/base/base_view.dart';
import 'package:hmg_patient_app/uitl/translations_delegate_base.dart';
import 'package:hmg_patient_app/uitl/utils.dart';
import 'package:hmg_patient_app/widgets/data_display/text.dart';
import 'package:hmg_patient_app/widgets/others/app_expandable_notifier.dart';
import 'package:hmg_patient_app/widgets/others/app_scaffold_widget.dart';
import 'package:hmg_patient_app/widgets/transitions/fade_page.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';

import 'ViewDoctorResponsesPage.dart';

class DoctorResponse extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    ProjectViewModel projectViewModel = Provider.of(context);
    return BaseView<AskDoctorViewModel>(
      onModelReady: (model) => model.getDoctorResponse(),
      builder: (_, model, w) => AppScaffold(
        baseViewModel: model,
        body: SingleChildScrollView(
          child: Container(
            margin: EdgeInsets.all(12),
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                SizedBox(
                  height: 16,
                ),
                AppExpandableNotifier(
                  headerWidget: Padding(
                    padding: const EdgeInsets.all(8.0),
                    child: Row(
                      mainAxisAlignment: MainAxisAlignment.spaceBetween,
                      children: [
                        Texts(TranslationBase.of(context).newDes),
                        Container(
                          width: 30,
                          height: 30,
                          decoration: BoxDecoration(
                            shape: BoxShape.circle,
                            color: Colors.red[800],
                          ),
                          child: Center(
                            child: Texts(
                              '${model.doctorResponseList.length}',
                              color: Colors.white,
                            ),
                          ),
                        )
                      ],
                    ),
                  ),
                  bodyWidget: Column(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: model.doctorResponseList.map(
                      (doctor) {
                        return InkWell(
                          onTap: () {
                            ///go to page ViewDoctorResponsesPage
                            if (doctor.transactions != null && doctor.transactions!.isNotEmpty) {
                              Navigator.push(
                                context,
                                FadePage(
                                  page: ViewDoctorResponsesPage(
                                    doctorResponse: doctor,
                                  ),
                                ),
                              );
                            } else {
                              Utils.showErrorToast("There are no doctor responses for this request.");
                            }
                          },
                          child: Container(
                            height: 100,
                            margin: EdgeInsets.only(top: 8, bottom: 8),
                            decoration: BoxDecoration(
                              borderRadius: BorderRadius.circular(8),
                              color: Colors.white,
                              border: Border.all(color: Colors.grey[300]!),
                            ),
                            child: Row(
                              mainAxisAlignment: MainAxisAlignment.spaceAround,
                              children: [
                                Expanded(
                                  child: Padding(
                                    padding: const EdgeInsets.all(8.0),
                                    child: Column(
                                      crossAxisAlignment: CrossAxisAlignment.start,
                                      children: [
                                        Texts('${doctor.doctorName}'),
                                        SizedBox(
                                          height: 5,
                                        ),
                                        Texts('${doctor.requestTypeDescription}'),
                                      ],
                                    ),
                                  ),
                                ),
                                Padding(
                                  padding: const EdgeInsets.fromLTRB(10.0, 0.0, 10.0, 0.0),
                                  child: Icon(projectViewModel.isArabic ? Icons.arrow_back_ios : Icons.arrow_forward_ios),
                                )
                              ],
                            ),
                          ),
                        );
                      },
                    ).toList(),
                  ),
                ),
                AppExpandableNotifier(
                  headerWidget: Padding(
                    padding: const EdgeInsets.all(8.0),
                    child: Row(
                      mainAxisAlignment: MainAxisAlignment.spaceBetween,
                      children: [
                        Texts(TranslationBase.of(context).all),
                        Container(
                          width: 30,
                          height: 30,
                          decoration: BoxDecoration(
                            shape: BoxShape.circle,
                            color: Colors.red[800],
                          ),
                          child: Center(
                            child: Texts(
                              '${model.doctorResponseList.length}',
                              color: Colors.white,
                            ),
                          ),
                        )
                      ],
                    ),
                  ),
                  bodyWidget: Column(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: model.doctorResponseList.map(
                      (doctor) {
                        return InkWell(
                          onTap: () {},
                          child: Container(
                            height: 85,
                            margin: EdgeInsets.only(top: 8, bottom: 8),
                            decoration: BoxDecoration(
                              borderRadius: BorderRadius.circular(8),
                              color: Colors.white,
                              border: Border.all(color: Colors.grey[300]!),
                            ),
                            child: Row(
                              mainAxisAlignment: MainAxisAlignment.spaceAround,
                              children: [
                                Expanded(
                                  child: Padding(
                                    padding: const EdgeInsets.all(8.0),
                                    child: Column(
                                      crossAxisAlignment: CrossAxisAlignment.start,
                                      children: [
                                        Texts('${doctor.doctorName}'),
                                        SizedBox(
                                          height: 5,
                                        ),
                                        Texts('${doctor.requestTypeDescription}'),
                                      ],
                                    ),
                                  ),
                                ),
                                Padding(
                                  padding: const EdgeInsets.all(8.0),
                                  child: Icon(projectViewModel.isArabic ? Icons.arrow_back_ios : Icons.arrow_forward_ios),
                                )
                              ],
                            ),
                          ),
                        );
                      },
                    ).toList(),
                  ),
                ),
              ],
            ),
          ),
        ),
      ),
    );
  }
}
