import 'package:diplomaticquarterapp/core/model/er/PatientER.dart';
import 'package:diplomaticquarterapp/core/model/er/PatientER_RC.dart';
import 'package:diplomaticquarterapp/core/viewModels/er/am_request_view_model.dart';
import 'package:diplomaticquarterapp/core/viewModels/project_view_model.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/others/app_scaffold_widget.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';

class Summary extends StatefulWidget {
  final Function changeCurrentTab;
  final PatientER patientER;
  final PatientER_RC patientER_RC;
  final AmRequestViewModel amRequestViewModel;

  Summary({Key key, this.changeCurrentTab, this.patientER, this.patientER_RC, this.amRequestViewModel});

  @override
  _SummaryState createState() => _SummaryState();
}

class _SummaryState extends State<Summary> {
  @override
  Widget build(BuildContext context) {
    ProjectViewModel projectViewModel = Provider.of(context);
    return AppScaffold(
      isShowDecPage: false,
      isShowAppBar: false,
      body: SingleChildScrollView(
        child: Container(
          margin: EdgeInsets.only(left: 12, right: 12, top: 12),
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              Text(TranslationBase.of(context).RRTSummary, style: TextStyle(fontSize: 16.0, letterSpacing: -0.64, fontWeight: FontWeight.w600)),
              SizedBox(
                height: 5,
              ),
              Container(
                width: double.infinity,
                padding: EdgeInsets.all(10),
                // margin: EdgeInsets.only(top: 12),
                decoration: cardRadius(12),
                child: Column(
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: [
                    _getNormalText(TranslationBase.of(context).transportMethod),
                    projectViewModel.isArabic
                        ? _getNormalText(
                            '${widget.patientER_RC.patientERTransportationMethod.textN}',
                            isBold: true,
                          )
                        : _getNormalText(
                            '${widget.patientER_RC.patientERTransportationMethod.text}',
                            isBold: true,
                          ),
                    SizedBox(
                      height: 8,
                    ),
                    _getNormalText(TranslationBase.of(context).directions),
                    _getNormalText(
                      widget.patientER_RC.transportationDetails.direction == 0 ? TranslationBase.of(context).toHospital : TranslationBase.of(context).fromHospital,
                      isBold: true,
                    ),
                    SizedBox(
                      height: 8,
                    ),
                    _getNormalText(
                      TranslationBase.of(context).pickupLocation,
                    ),
                    _getNormalText(
                      '${widget.patientER_RC.transportationDetails.pickupLocationName}',
                      isBold: true,
                    ),
                    SizedBox(
                      height: 8,
                    ),
                    _getNormalText(TranslationBase.of(context).dropoffLocation),
                    _getNormalText(
                      '${widget.patientER_RC.transportationDetails.dropoffLocationName}',
                      isBold: true,
                    ),
                    SizedBox(
                      height: 8,
                    ),
                    _getNormalText(TranslationBase.of(context).selectAmbulate),
                    _getNormalText(
                      '${widget.patientER_RC.transportationDetails.ambulateTitle}',
                      isBold: true,
                    ),
                    SizedBox(
                      height: 8,
                    ),
                    _getNormalText(TranslationBase.of(context).notes),
                    _getNormalText(
                      '${widget.patientER_RC.transportationDetails.notes ?? '---'}',
                      isBold: true,
                    ),
                    SizedBox(
                      height: 8,
                    ),
                  ],
                ),
              ),
              SizedBox(
                height: 20,
              ),
              Text(TranslationBase.of(context).billAmount, style: TextStyle(fontSize: 16.0, letterSpacing: -0.64, fontWeight: FontWeight.w600)),
              SizedBox(
                height: 5,
              ),
              Container(
                height: 55,
                padding: EdgeInsets.all(10),
                decoration: cardRadius(12),
                child: Row(
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  children: [
                    _getNormalText(TranslationBase.of(context).patientShareTotal + ':'),
                    Container(
                      padding: EdgeInsets.only(left: 20.0, right: 20.0),
                      child: _getNormalText(TranslationBase.of(context).sar + ' ${widget.patientER_RC.patientERTransportationMethod.priceTotal}', isBold: true, isTotal: true)
                    ),
                  ],
                ),
              ),
              SizedBox(height: 50),
            ],
          ),
        ),
      ),
      bottomSheet: Container(
        color: Theme.of(context).scaffoldBackgroundColor,
        padding: EdgeInsets.all(12.0),
        child: DefaultButton(TranslationBase.of(context).send, () async {
          await widget.amRequestViewModel.insertERPressOrder(patientER: widget.patientER_RC);
        }),
      ),
    );
  }

  _getNormalText(text, {bool isBold = false, bool isTotal = false}) {
    return Text(
      text,
      style: TextStyle(
        fontSize: isBold
            ? isTotal
                ? 16
                : 12
            : 10,
        letterSpacing: -0.5,
        color: isBold ? Colors.black : Colors.grey[700],
        fontWeight: FontWeight.w600,
      ),
    );
  }
}
