import 'package:diplomaticquarterapp/config/config.dart';
import 'package:diplomaticquarterapp/core/model/radiology/final_radiology.dart';
import 'package:diplomaticquarterapp/core/viewModels/medical/radiology_view_model.dart';
import 'package:diplomaticquarterapp/core/viewModels/project_view_model.dart';
import 'package:diplomaticquarterapp/models/header_model.dart';
import 'package:diplomaticquarterapp/pages/base/base_view.dart';
import 'package:diplomaticquarterapp/uitl/translations_delegate_base.dart';
import 'package:diplomaticquarterapp/uitl/utils_new.dart';
import 'package:diplomaticquarterapp/widgets/buttons/defaultButton.dart';
import 'package:diplomaticquarterapp/widgets/dialogs/confirm_send_email_dialog.dart';
import 'package:diplomaticquarterapp/widgets/new_design/doctor_header.dart';
import 'package:diplomaticquarterapp/widgets/others/app_scaffold_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 RadiologyDetailsPage extends StatelessWidget {
  final FinalRadiology finalRadiology;

  RadiologyDetailsPage({Key key, this.finalRadiology});

  @override
  Widget build(BuildContext context) {
    ProjectViewModel projectViewModel = Provider.of(context);
    return BaseView<RadiologyViewModel>(
      onModelReady: (model) => model.getRadImageURL(projectId: finalRadiology.projectID, lineItem: finalRadiology.invoiceLineItemNo, invoiceNo: finalRadiology.invoiceNo),
      builder: (_, model, widget) => AppScaffold(
        appBarTitle: TranslationBase.of(context).report,
        isShowAppBar: true,
        baseViewModel: model,
        showNewAppBar: true,
        showNewAppBarTitle: true,
        backgroundColor: Color(0xffF8F8F8),
        body: SingleChildScrollView(
          child: Column(
            mainAxisSize: MainAxisSize.max,
            crossAxisAlignment: CrossAxisAlignment.center,
            children: <Widget>[
              DoctorHeader(
                headerModel: new HeaderModel(
                  finalRadiology.doctorName,
                  finalRadiology.doctorID,
                  finalRadiology.doctorImageURL,
                  finalRadiology.speciality,
                  finalRadiology.invoiceNo.toString(),
                  finalRadiology.projectName,
                  finalRadiology.orderDate,
                  null,
                  finalRadiology.nationalityFlagURL,
                  finalRadiology.doctorRate,
                  finalRadiology.actualDoctorRate,
                  finalRadiology.noOfPatientsRate,
                  model.user.emailAddress,
                ),
                onTap: () {
                  showConfirmMessage(finalRadiology: finalRadiology, model: model);
                },
                buttonTitle: TranslationBase.of(context).sendCopyRad,
                isNeedToShowButton: projectViewModel.havePrivilege(8),
              ),
              Container(
                margin: EdgeInsets.all(24),
                decoration: cardRadius(12),
                child: Container(
                  width: double.infinity,
                  child: Padding(
                    padding: const EdgeInsets.all(12.0),
                    child: Column(
                      crossAxisAlignment: CrossAxisAlignment.start,
                      mainAxisAlignment: MainAxisAlignment.start,
                      children: [
                        Text(
                          "General Result",
                          style: TextStyle(
                            fontSize: 16,
                            letterSpacing: -0.64,
                            fontWeight: FontWeight.w600,
                          ),
                        ),
                        mHeight(10),
                        Text(
                          '${finalRadiology.reportData}',
                          style: TextStyle(fontSize: 12, letterSpacing: -0.48),
                        ),
                        mHeight(16),
                        (projectViewModel.havePrivilege(9) || projectViewModel.havePrivilege(8))
                            ? (finalRadiology.dIAPACSURL != "" && projectViewModel.havePrivilege(9))
                                ? Container(
                                    child: DefaultButton(
                                      TranslationBase.of(context).openRad,
                                      () => {launch(model.radImageURL)},
                                      textColor: Colors.white,
                                    ),
                                  )
                                : Container()
                            : Container(),
                      ],
                    ),
                  ),
                ),
              ),
            ],
          ),
        ),
      ),
    );
  }

  void showConfirmMessage({FinalRadiology finalRadiology, RadiologyViewModel model}) {
    showDialog(
      context: AppGlobal.context,
      builder: (cxt) => ConfirmSendEmailDialog(
        email: model.user.emailAddress,
        onTapSendEmail: () {
          model.sendRadReportEmail(mes: TranslationBase.of(AppGlobal.context).sendSuc, finalRadiology: finalRadiology);
        },
      ),
    );
  }
}
