import 'package:diplomaticquarterapp/config/config.dart';
import 'package:diplomaticquarterapp/core/enum/viewstate.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/theme/colors.dart';
import 'package:diplomaticquarterapp/uitl/translations_delegate_base.dart';
import 'package:diplomaticquarterapp/uitl/utils_new.dart';
import 'package:diplomaticquarterapp/widgets/buttons/button.dart';
import 'package:diplomaticquarterapp/widgets/data_display/text.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.doctorImageURL, finalRadiology.speciality, finalRadiology.invoiceNo.toString(), finalRadiology.projectName,
                    finalRadiology.orderDate, finalRadiology.nationalityFlagURL, finalRadiology.doctorRate, finalRadiology.actualDoctorRate, model.user.emailAddress),
                onTap: () {
                  showConfirmMessage(finalRadiology: finalRadiology, model: model);
                },
                buttonTitle: TranslationBase.of(context).sendCopyRad,
                isNeedToShowButton: projectViewModel.havePrivilege(8),
              ),
              Card(
                margin: EdgeInsets.all(24),
                shape: cardRadius(12),
                elevation: 0,
                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),
                        ),
                        // Texts(
                        //   '${finalRadiology.reportData}',
                        //   textAlign: TextAlign.start,
                        //   fontSize: 12,
                        //
                        // ),
                        mHeight(16),
                        (projectViewModel.havePrivilege(9) || projectViewModel.havePrivilege(8))
                            ? (finalRadiology.dIAPACSURL != "" && projectViewModel.havePrivilege(9))
                                ? Container(
                                    width: MediaQuery.of(context).size.width * 0.8,
                                    child: Button(
                                      onTap: () {
                                        launch(model.radImageURL);
                                      },
                                      label: TranslationBase.of(context).openRad,
                                      backgroundColor: CustomColors.accentColor,
                                    ),
                                  )
                                : Container()
                            : Container(),
                      ],
                    ),
                  ),
                ),
              ),
            ],
          ),
        ),
        // bottomSheet: (projectViewModel.havePrivilege(9) || projectViewModel.havePrivilege(8))
        //     ? Container(
        //         width: double.infinity,
        //         height: finalRadiology.dIAPACSURL != "" ? MediaQuery.of(context).size.height * 0.25 : MediaQuery.of(context).size.height * 0.14,
        //         color: Colors.grey[100],
        //         child: Column(
        //           mainAxisSize: MainAxisSize.min,
        //           children: <Widget>[
        //             Divider(),
        //             if (projectViewModel.havePrivilege(8))
        //               Container(
        //                 width: MediaQuery.of(context).size.width * 0.8,
        //                 child: Button(
        //                   onTap: () {
        //                     showConfirmMessage(finalRadiology: finalRadiology, model: model);
        //                   },
        //                   label: TranslationBase.of(context).sendCopyRad,
        //                   loading: model.state == ViewState.BusyLocal,
        //                   backgroundColor: Theme.of(context).primaryColor,
        //                 ),
        //               )
        //           ],
        //         ),
        //       )
        //     : Container(),
      ),
    );
  }

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