import 'package:doctor_app_flutter/config/size_config.dart';
import 'package:doctor_app_flutter/core/viewModel/PatientMuseViewModel.dart';
import 'package:doctor_app_flutter/core/viewModel/project_view_model.dart';
import 'package:doctor_app_flutter/icons_app/doctor_app_icons.dart';
import 'package:doctor_app_flutter/models/patient/patiant_info_model.dart';
import 'package:doctor_app_flutter/screens/base/base_view.dart';
import 'package:doctor_app_flutter/util/date-utils.dart';
import 'package:doctor_app_flutter/util/translations_delegate_base.dart';
import 'package:doctor_app_flutter/widgets/patients/profile/patient-profile-header-new-design-app-bar.dart';
import 'package:doctor_app_flutter/widgets/shared/app_scaffold_widget.dart';
import 'package:doctor_app_flutter/widgets/shared/app_texts_widget.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:url_launcher/url_launcher.dart';

class ECGPage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    final routeArgs = ModalRoute.of(context).settings.arguments as Map;
    PatiantInformtion patient = routeArgs['patient'];
    String patientType = routeArgs['patient-type'];
    String arrivalType = routeArgs['arrival-type'];
    ProjectViewModel projectViewModel = Provider.of(context);
    return BaseView<PatientMuseViewModel>(
      onModelReady: (model) => model.getECGPatient(
          patientType: patient.patientType,
          patientOutSA: 0,
          patientID: patient.patientId),
      builder: (_, model, w) => AppScaffold(
        baseViewModel: model,
        isShowAppBar: true,
        backgroundColor: Color(0xffF8F8F8),
        appBar: PatientProfileHeaderNewDesignAppBar(patient,arrivalType??'0',patientType),
        body: SingleChildScrollView(
          child: Padding(
            padding: const EdgeInsets.all(8.0),
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                // PatientProfileHeaderNewDesign(patient,arrivalType??'0',patientType),
                SizedBox(height: 12,),
                AppText('Service',style: "caption2",color: Colors.black,),
                AppText('ECG',bold: true,fontSize: 22,),
                SizedBox(height: 12,),
                ...List.generate(model.patientMuseResultsModelList.length, (index) => InkWell(
                  onTap: () async {
                    await launch(
                        model.patientMuseResultsModelList[index].imageURL);
                  },
                  child: Container(
                    width: double.infinity,
                    height: 120,
                    margin: EdgeInsets.only(top: 5,bottom: 5),
                    padding: EdgeInsets.all(10),
                    decoration: BoxDecoration(
                        border: Border.all(color: Colors.white,width: 2),
                      color: Colors.white,
                      borderRadius: BorderRadius.circular(8)
                    ),
                    child: Column(
                      children: [
                        Row(
                         // mainAxisAlignment: MainAxisAlignment.spaceAround,
                          children: [
                            Expanded(
                              child: Column(
                                crossAxisAlignment: CrossAxisAlignment.start,
                                children: [
                                  AppText('ECG Report',fontWeight: FontWeight.w700,fontSize: 17,),
                                  SizedBox(height:3),
                                  RichText(
                                    text: TextSpan(
                                      style: TextStyle(
                                          fontSize: 1.6 *
                                              SizeConfig.textMultiplier,
                                          color: Colors.black),
                                      children: <TextSpan>[
                                        new TextSpan(
                                            text:
                                            TranslationBase.of(context).orderNo,
                                            style: TextStyle(
                                                fontSize: 12,
                                                fontFamily:
                                                'Poppins')),
                                        new TextSpan(
                                            text: '${/*model.patientMuseResultsModelList[index].orderNo?? */'3455'}',
                                            style: TextStyle(
                                                fontWeight: FontWeight.w600,
                                                fontFamily:
                                                'Poppins',
                                                fontSize: 14)),
                                      ],
                                    ),
                                  )
                                ],
                              ),
                            ),
                            Expanded(
                              child: Column(
                                crossAxisAlignment: CrossAxisAlignment.end,
                                children: [
                                  AppText('${DateUtils.getDayMonthYearDateFormatted(model.patientMuseResultsModelList[index].createdOnDateTime,isArabic: projectViewModel.isArabic)}',color: Colors.black,fontWeight: FontWeight.w600,fontSize: 14,),
                                  AppText('${DateUtils.getHour(model.patientMuseResultsModelList[index].createdOnDateTime)}',fontWeight: FontWeight.w600,color: Colors.grey[700],fontSize: 14,),
                                ],
                              ),
                            ),
                          ],
                        ),
                        SizedBox(height: 15,),
                        Align(
                          alignment: Alignment.topRight,
                          child: Icon(DoctorApp.external_link),
                        )
                      ],
                    ),
                  ),
                )),

              ],
            ),
          ),
        ),
      ),
    );
  }
}
