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/pages/ErService/widgets/StepsWidget.dart';
import 'package:diplomaticquarterapp/uitl/date_uitl.dart';
import 'package:diplomaticquarterapp/uitl/translations_delegate_base.dart';
import 'package:diplomaticquarterapp/widgets/buttons/secondary_button.dart';
import 'package:diplomaticquarterapp/widgets/others/OrderLogItem.dart';
import 'package:diplomaticquarterapp/widgets/others/app_scaffold_widget.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

import 'BillAmount.dart';
import 'PickupLocation.dart';
import 'SelectTransportationMethod.dart';
import 'Summary.dart';

class AmbulanceRequestIndexPage extends StatefulWidget {
  final AmRequestViewModel amRequestViewModel;

  AmbulanceRequestIndexPage({Key key, this.amRequestViewModel});

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

class _AmbulanceRequestIndexPageState extends State<AmbulanceRequestIndexPage> {
  int currentIndex = 0;
  PageController pageController;
  PatientER _patientER = PatientER();

  PatientER_RC _patientER_RC = PatientER_RC();

  TransportationDetails transportationDetails = new TransportationDetails();

  _changeCurrentTab(int tab) {
    setState(() {
      currentIndex = tab;
    });
    pageController.animateToPage(tab,
        duration: Duration(milliseconds: 800), curve: Curves.easeOutQuart);
  }

  @override
  void initState() {
    super.initState();
    pageController = new PageController();
    _patientER_RC.transportationDetails = transportationDetails;
  }

  @override
  Widget build(BuildContext context) {
    return AppScaffold(
      body: widget.amRequestViewModel.pendingAmbulanceRequestOrder != null
          ? SingleChildScrollView(
            child: Column(
                children: [
                  SizedBox(
                    height: 80,
                  ),
                  Container(
                    margin: EdgeInsets.only(left: 18, right: 18),
                    decoration: BoxDecoration(
                      color: Colors.white,
                      borderRadius: BorderRadius.circular(2),
                    ),
                    child: Column(
                      crossAxisAlignment: CrossAxisAlignment.start,
                      children: [
                        OrderLogItem(
                          title: TranslationBase.of(context).reqId,
                          value: widget.amRequestViewModel.pendingAmbulanceRequestOrder
                              .id
                              .toString(),
                        ),
                        OrderLogItem(
                          title: TranslationBase.of(context).status,
                          value: widget.amRequestViewModel.pendingAmbulanceRequestOrder.statusText,
                        ),
                        OrderLogItem(
                          title: TranslationBase.of(context).pickupDate,
                          value: getDate(widget.amRequestViewModel.pendingAmbulanceRequestOrder.created),
                        ),
                        OrderLogItem(
                          title: TranslationBase.of(context).pickupLocation,
                          value: widget.amRequestViewModel.pendingAmbulanceRequestOrder
                              .pickupLocation,
                        ),
                        OrderLogItem(
                          title: TranslationBase.of(context).dropoffLocation,
                          value: widget.amRequestViewModel.pendingAmbulanceRequestOrder
                              .dropOffLocation,
                        ),
                        OrderLogItem(
                          title: TranslationBase.of(context).transportMethod,
                          value: widget
                              .amRequestViewModel.pendingAmbulanceRequestOrder.serviceText,
                        ),
                        Container(
                          padding: EdgeInsets.all(10),
                          width: double.maxFinite,
                          margin: EdgeInsets.only(bottom: 4, left: 4, right: 4),
                          decoration: BoxDecoration(
                              borderRadius: BorderRadius.only(
                                bottomRight: Radius.circular(12),
                                bottomLeft: Radius.circular(12),
                              ),
                              color: Colors.white),
                          child: SecondaryButton(
                            color: Colors.red[900],
                            textColor: Colors.white,
                            label: TranslationBase.of(context).cancel,
                            onTap: () {
                              widget.amRequestViewModel.updatePressOrder(
                                  presOrderID: widget.amRequestViewModel
                                      .pendingAmbulanceRequestOrder.id);
                            },
                          ),
                        )
                      ],
                    ),
                  ),
                ],
              ),
          )
          : Column(
              children: [
                SizedBox(
                  height: 20,
                ),
                Container(
                  margin: EdgeInsets.only(left: 12, right: 12),
                  child: StepsWidget(
                    index: currentIndex,
                    changeCurrentTab: _changeCurrentTab,
                  ),
                ),
                Expanded(
                  child: PageView(
                    physics: NeverScrollableScrollPhysics(),
                    controller: pageController,
                    children: <Widget>[
                      //Container(),
                      SelectTransportationMethod(
                        changeCurrentTab: _changeCurrentTab,
                        patientER: _patientER,
                        patientER_RC: _patientER_RC,
                        amRequestViewModel: widget.amRequestViewModel,
                      ),
                      PickupLocation(
                        changeCurrentTab: _changeCurrentTab,
                        patientER: _patientER,
                        patientER_RC: _patientER_RC,
                        amRequestViewModel: widget.amRequestViewModel,
                      ),
                      BillAmount(
                        changeCurrentTab: _changeCurrentTab,
                        patientER: _patientER,
                        patientER_RC: _patientER_RC,
                        amRequestViewModel: widget.amRequestViewModel,
                      ),
                      Summary(
                        changeCurrentTab: _changeCurrentTab,
                        patientER: _patientER,
                        patientER_RC: _patientER_RC,
                        amRequestViewModel: widget.amRequestViewModel,
                      ),
                    ],
                  ),
                ),
              ],
            ),
    );
  }

  String getDate(String date) {
    return date.split("T")[0];
  }

}
