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/pages/base/base_view.dart';
import 'package:diplomaticquarterapp/widgets/buttons/button.dart';
import 'package:diplomaticquarterapp/widgets/others/app_scaffold_widget.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.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) {
    return BaseView<RadiologyViewModel>(
      onModelReady: (model) => model.getRadImageURL(
          projectId: finalRadiology.projectID,
          lineItem: finalRadiology.invoiceLineItemNo,
          invoiceNo: finalRadiology.invoiceNo),
      builder: (_, model, widget) => AppScaffold(
          appBarTitle: 'Radiology Report',
          isShowAppBar: true,
          baseViewModel: model,
          body: SingleChildScrollView(
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.center,
              children: <Widget>[
                Text('${finalRadiology.reportData}',textAlign: TextAlign.center,),
              ],
            ),
          ),
          bottomSheet: Container(
            width: double.infinity,
            height: MediaQuery.of(context).size.height * 0.2,
            color: Colors.grey[100],
            child: Column(
              children: <Widget>[
                Divider(),
                Container(
                  width: MediaQuery.of(context).size.width * 0.8,
                  child: Button(
                    onTap: () {
                      launch(model.radImageURL);
                    },
                    label: 'Open Radio Image',
                    backgroundColor: Colors.grey[800],
                  ),
                ),
                Container(
                  width: MediaQuery.of(context).size.width * 0.8,
                  child: Button(
                    onTap: () => model.sendRadReportEmail(
                        finalRadiology: finalRadiology),
                    label: 'Send Copy',
                    loading: model.state == ViewState.BusyLocal,
                    backgroundColor: Colors.red[800],
                  ),
                )
              ],
            ),
          )),
    );
  }
}
