import 'package:doctor_app_flutter/core/model/patient/patiant_info_model.dart';
import 'package:doctor_app_flutter/core/model/radiology/final_radiology.dart';
import 'package:doctor_app_flutter/core/service/AnalyticsService.dart';
import 'package:doctor_app_flutter/core/viewModel/project_view_model.dart';
import 'package:doctor_app_flutter/core/viewModel/radiology_view_model.dart';
import 'package:doctor_app_flutter/screens/base/base_view.dart';
import 'package:doctor_app_flutter/utils/translations_delegate_base_utils.dart';
import 'package:doctor_app_flutter/utils/utils.dart';
import 'package:doctor_app_flutter/widgets/patients/profile/app_bar/patient-profile-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:doctor_app_flutter/widgets/shared/buttons/app_buttons_widget.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:url_launcher/url_launcher_string.dart';

import '../../../../locator.dart';

class RadiologyDetailsPage extends StatelessWidget {
  final FinalRadiology finalRadiology;
  final PatiantInformtion patient;
  final String? patientType;
  final String? arrivalType;
  final bool isInpatient;
  final bool isVidaPlus;

  RadiologyDetailsPage({Key? key, required this.finalRadiology, required this.patient, this.patientType, this.arrivalType, this.isInpatient = false, this.isVidaPlus = false});

  @override
  Widget build(BuildContext context) {
    ProjectViewModel projectViewModel = Provider.of(context);
    return BaseView<RadiologyViewModel>(
      onModelReady: (model) => model.getRadImageURL(
        patient: patient,
        projectId: finalRadiology.projectID,
        lineItem: finalRadiology.invoiceLineItemNo,
        invoiceType: finalRadiology.invoiceType!,
        invoiceNo: Utils.isVidaPlusProject(projectViewModel, finalRadiology.projectID) ? finalRadiology.invoiceNo_VP : finalRadiology.invoiceNo,
        isVidaPlus: Utils.isVidaPlusProject(
          projectViewModel,
          finalRadiology.projectID,
        ),
      ),
      builder: (_, model, widget) =>
        //   AppScaffold(
        // isShowAppBar: true,
        // baseViewModel: model,
        // body:
        //

        Material(
          color: Colors.white,
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              PatientProfileAppBar(
                patient,
                appointmentDate: finalRadiology.orderDate!,
                doctorName: finalRadiology.doctorName,
                clinic: finalRadiology.clinicDescription,
                branch: finalRadiology.projectName,
                profileUrl: finalRadiology.doctorImageURL,
                invoiceNO: Utils.isVidaPlusProject(projectViewModel, finalRadiology.projectID) ? finalRadiology.invoiceNo_VP.toString() : finalRadiology.invoiceNo.toString(),
                isAppointmentHeader: true,
              ),
              Expanded(
                child: SingleChildScrollView(
                  child: Column(
                    mainAxisSize: MainAxisSize.max,
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: <Widget>[
                      Column(
                        crossAxisAlignment: CrossAxisAlignment.start,
                        children: [
                          SizedBox(
                            height: 5,
                          ),
                          Padding(
                            padding: const EdgeInsets.all(8.0),
                            child: AppText(
                              TranslationBase.of(context).generalResult,
                              color: Color(0xff2E303A),
                            ),
                          ),
                          Padding(
                            padding: const EdgeInsets.all(8.0),
                            child: AppText(
                              '${finalRadiology.reportData.trim()}',
                              textAlign: TextAlign.start,
                              isCopyable: true,
                              fontSize: 17,
                              color: Color(0xff575757),
                            ),
                          ),
                          SizedBox(
                            height: 100,
                          ),
                        ],
                      ),
                    ],
                  ),
                ),
              ),
              model.radImageURL.isNotEmpty
                  ? Container(
                height: 80,
                width: double.maxFinite,
                child: Container(
                  margin: EdgeInsets.only(left: 35, right: 35, top: 12, bottom: 12),
                  child: AppButton(
                    color: Color(0xffD02127),
                    onPressed: () async {
                      await locator<AnalyticsService>().logEvent(
                        eventCategory: "RadiologyDetailsPage",
                        eventAction: "Open Radiology Image",
                      );
                      launchUrlString(model.radImageURL);
                    },
                    title: TranslationBase.of(context).openRad,
                  ),
                ),
              )
                  : SizedBox(),
            ],
          ),
        ),
        // bottomSheet:model.radImageURL.isNotEmpty
        //     ? Container(
        //   height: 80,
        //   width: double.maxFinite,
        //   child: Container(
        //     margin: EdgeInsets.only(left: 35, right: 35, top: 12, bottom: 12),
        //     child: AppButton(
        //       color: Color(0xffD02127),
        //       onPressed: () async {
        //         await locator<AnalyticsService>().logEvent(
        //           eventCategory: "RadiologyDetailsPage",
        //           eventAction: "Open Radiology Image",
        //         );
        //         launchUrlString(model.radImageURL);
        //       },
        //       title: TranslationBase.of(context).openRad,
        //     ),
        //   ),
        // )
        //     : SizedBox(),
      // ),
    );
  }
}
