import 'package:diplomaticquarterapp/core/enum/Ambulate.dart';
import 'package:diplomaticquarterapp/core/model/er/PatientER.dart';
import 'package:diplomaticquarterapp/core/viewModels/er/am_request_view_model.dart';
import 'package:diplomaticquarterapp/pages/Blood/new_text_Field.dart';
import 'package:diplomaticquarterapp/widgets/buttons/secondary_button.dart';
import 'package:diplomaticquarterapp/widgets/data_display/text.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';


class BillAmount extends StatefulWidget {
  final Function changeCurrentTab;
  final PatientER patientER;
  final AmRequestViewModel amRequestViewModel;

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

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

class _BillAmountState extends State<BillAmount> {
  Ambulate _ambulate = Ambulate.None;
  String note ="";


  @override
  void initState() {

    if(widget.patientER.ambulate!=null)
      {
        setState(() {
          _ambulate = widget.patientER.ambulate;
          note = widget.patientER.requesterNote;
        });
      }
    super.initState();
  }


  @override
  Widget build(BuildContext context) {
    return SingleChildScrollView(
      physics: BouncingScrollPhysics(),
      child: Container(
        margin: EdgeInsets.only(left: 12, right: 12),
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            Texts('Bill Amount '),
            SizedBox(
              height: 10,
            ),
            Table(
              border: TableBorder.symmetric(
                  inside: BorderSide(width: 1.0, color: Colors.grey[300]),
                  outside: BorderSide(width: 1.0, color: Colors.grey[300])),
              children: [
                TableRow(
                  children: [
                    Container(
                      height: MediaQuery.of(context).size.height * 0.09,
                      decoration: BoxDecoration(
                        color: Colors.white,
                        borderRadius: BorderRadius.only(
                          topLeft: Radius.circular(10.0),
                        ),
                      ),
                      child: Padding(
                        padding: const EdgeInsets.all(8.0),
                        child: Texts(
                          'Amount before tax: ',
                          textAlign: TextAlign.start,
                          color: Colors.black,
                          fontSize: 15,
                        ),
                      ),
                    ),
                    Container(
                      height: MediaQuery.of(context).size.height * 0.09,
                      decoration: BoxDecoration(
                        color: Colors.white,
                        borderRadius: BorderRadius.only(
                          topRight: Radius.circular(10.0),
                        ),
                      ),
                      child: Padding(
                        padding: const EdgeInsets.all(8.0),
                        child: Texts(
                          'SR ${widget.patientER.patientERTransportationMethod.price}',
                          color: Colors.black,
                          textAlign: TextAlign.start,
                          fontSize: 15,
                        ),
                      ),
                    ),
                  ],
                ),
                TableRow(
                  children: [
                    Container(
                      color: Colors.white,
                      height: MediaQuery.of(context).size.height * 0.09,
                      child: Padding(
                        padding: const EdgeInsets.all(8.0),
                        child: Texts(
                          'Tax amount :',
                          color: Colors.black,
                          fontSize: 15,
                          textAlign: TextAlign.start,
                        ),
                      ),
                    ),
                    Container(
                      height: MediaQuery.of(context).size.height * 0.09,
                      color: Colors.white,
                      child: Padding(
                        padding: const EdgeInsets.all(8.0),
                        child: Texts(
                          'SR ${widget.patientER.patientERTransportationMethod.vAT}',
                          color: Colors.black,
                          fontSize: 15,
                          textAlign: TextAlign.start,
                        ),
                      ),
                    ),
                  ],
                ),
                TableRow(
                  children: [
                    Container(
                      height: MediaQuery.of(context).size.height * 0.09,
                      decoration: BoxDecoration(
                        color: Colors.white,
                        borderRadius: BorderRadius.only(
                          bottomLeft: Radius.circular(10.0),
                        ),
                      ),
                      child: Padding(
                        padding: const EdgeInsets.all(8.0),
                        child: Texts(
                          'Total amount payable',
                          color: Colors.black,
                          fontSize: 15,
                          textAlign: TextAlign.start,
                          bold: true,
                        ),
                      ),
                    ),
                    Container(
                      height: MediaQuery.of(context).size.height * 0.09,
                      decoration: BoxDecoration(
                        color: Colors.white,
                        borderRadius: BorderRadius.only(
                          bottomRight: Radius.circular(10.0),
                        ),
                      ),
                      child: Padding(
                        padding: const EdgeInsets.all(8.0),
                        child: Texts(
                          'SR ${widget.patientER.patientERTransportationMethod.totalPrice}',
                          color: Colors.black,
                          fontSize: 15,
                          textAlign: TextAlign.start,
                        ),
                      ),
                    ),
                  ],
                ),
              ],
            ),
            SizedBox(
              height: 10,
            ),
            Texts('Select Ambulate',bold: true,),
            SizedBox(height: 5,),
            Row(
              children: [
                Expanded(
                  child: InkWell(
                    onTap: () {
                      setState(() {
                        _ambulate = Ambulate.Wheelchair;
                      });
                    },
                    child: Container(
                      decoration: BoxDecoration(
                        shape: BoxShape.rectangle,
                        borderRadius: BorderRadius.circular(8),
                        border:
                        Border.all(color: Colors.grey, width: 0.5),
                        color: Colors.white,
                      ),
                      child: ListTile(
                        title: Text('Wheelchair'),
                        leading: Radio(
                          value: Ambulate.Wheelchair,
                          groupValue: _ambulate,
                          activeColor: Colors.red[800],
                          onChanged: (value) {
                            setState(() {
                              _ambulate = value;
                            });
                          },
                        ),
                      ),
                    ),
                  ),
                ),
                Expanded(
                  child: InkWell(
                    onTap: () {
                      setState(() {
                        _ambulate = Ambulate.Walker;
                      });
                    },
                    child: Container(
                      decoration: BoxDecoration(
                        shape: BoxShape.rectangle,
                        borderRadius: BorderRadius.circular(8),
                        border:
                        Border.all(color: Colors.grey, width: 0.5),
                        color: Colors.white,
                      ),
                      child: ListTile(
                        title: Text('Walker'),
                        leading: Radio(
                          value: Ambulate.Walker,
                          groupValue: _ambulate,
                          activeColor: Colors.red[800],
                          onChanged: (value) {
                            setState(() {
                              _ambulate = value;
                            });
                          },
                        ),
                      ),
                    ),
                  ),
                ),
              ],
            ),
            SizedBox(height: 5,),
            Row(
              children: [
                Expanded(
                  child: InkWell(
                    onTap: () {
                      setState(() {
                        _ambulate = Ambulate.Stretcher;
                      });
                    },
                    child: Container(
                      decoration: BoxDecoration(
                        shape: BoxShape.rectangle,
                        borderRadius: BorderRadius.circular(8),
                        border:
                        Border.all(color: Colors.grey, width: 0.5),
                        color: Colors.white,
                      ),
                      child: ListTile(
                        title: Text('Stretcher'),
                        leading: Radio(
                          value: Ambulate.Stretcher,
                          groupValue: _ambulate,
                          activeColor: Colors.red[800],
                          onChanged: (value) {
                            setState(() {
                              _ambulate = value;
                            });
                          },
                        ),
                      ),
                    ),
                  ),
                ),
                Expanded(
                  child: InkWell(
                    onTap: () {
                      setState(() {
                        _ambulate = Ambulate.None;
                      });
                    },
                    child: Container(
                      decoration: BoxDecoration(
                        shape: BoxShape.rectangle,
                        borderRadius: BorderRadius.circular(8),
                        border:
                        Border.all(color: Colors.grey, width: 0.5),
                        color: Colors.white,
                      ),
                      child: ListTile(
                        title: Text('None'),
                        leading: Radio(
                          value: Ambulate.None,
                          groupValue: _ambulate,
                          activeColor: Colors.red[800],
                          onChanged: (value) {
                            setState(() {
                              _ambulate = value;
                            });
                          },
                        ),
                      ),
                    ),
                  ),
                ),
              ],
            ),
            SizedBox(height: 12,),
            NewTextFields(
              hintText: 'Note',
              initialValue: note,
              onChanged: (value){
                setState(() {
                  note = value;
                });
              },
            ),

            SizedBox(
              height: 15,
            ),
            Container(
              padding: EdgeInsets.all(15),
              width: double.maxFinite,
              height: 76,
              child: SecondaryButton(
                color: Colors.grey[800],
                textColor: Colors.white,
                onTap: () {
                  setState(() {
                    widget.patientER.ambulate = _ambulate;
                    widget.patientER.requesterNote = note;
                    widget.patientER.selectedAmbulate = _ambulate.selectAmbulateNumber();
                    widget.changeCurrentTab(3);
                  });
                },
                label: 'Next',
              ),
            )
          ],
        ),
      ),
    );
  }
}
