import 'package:doctor_app_flutter/core/viewModel/PatientMuseViewModel.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/widgets/shared/Text.dart';
import 'package:doctor_app_flutter/widgets/shared/app_scaffold_widget.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.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'];

    return BaseView<PatientMuseViewModel>(
      onModelReady: (model) => model.getECGPatient(
          patientType: patient.patientType,
          patientOutSA: 0,
          patientID: patient.patientId),
      builder: (_, model, w) => AppScaffold(
        baseViewModel: model,
        isShowAppBar: true,
        appBarTitle: 'ECG',
        body: ListView.builder(
            itemCount: model.patientMuseResultsModelList.length,
            itemBuilder: (context, index) => InkWell(
                  onTap: () async {
                    await launch(
                        model.patientMuseResultsModelList[index].imageURL);
                  },
                  child: Container(
                    width: double.infinity,
                    margin: EdgeInsets.all(5),
                    padding: EdgeInsets.all(10),
                    decoration: BoxDecoration(
                      border: Border.all(color: Colors.grey,width: 2)
                    ),
                    child: Center(
                      child: Texts(
                          "${model.patientMuseResultsModelList[index].createdOnDateTime}"),
                    ),
                  ),
                )),
      ),
    );
  }
}
