import 'package:diplomaticquarterapp/core/viewModels/er/am_request_view_model.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:flutter/cupertino.dart';
import 'package:flutter/material.dart';

class OrderLogPage extends StatelessWidget {
  final AmRequestViewModel amRequestViewModel;

  OrderLogPage({Key key, @required this.amRequestViewModel});

  @override
  Widget build(BuildContext context) {
    return Container(
      margin: EdgeInsets.all(10),
      padding: EdgeInsets.all(8),
      child: ListView.builder(
        itemCount: amRequestViewModel.patientAmbulanceRequestOrdersList.length,
        itemBuilder: (context, index) => Container(
          margin: EdgeInsets.all(8),
          decoration: BoxDecoration(
            color: Colors.white,
            borderRadius: BorderRadius.circular(2),
          ),
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              OrderLogItem(
                title: TranslationBase.of(context).reqId,
                value: amRequestViewModel.patientAmbulanceRequestOrdersList[index].id.toString(),
              ),
              OrderLogItem(
                title: TranslationBase.of(context).orderStatus,
                value: amRequestViewModel.patientAmbulanceRequestOrdersList[index].statusText,
              ),
              OrderLogItem(
                title: TranslationBase.of(context).pickupDate,
                value: getDate(amRequestViewModel.patientAmbulanceRequestOrdersList[index].created),
              ),
              OrderLogItem(
                title: TranslationBase.of(context).pickupLocation,
                value: amRequestViewModel.patientAmbulanceRequestOrdersList[index].pickupLocation,
              ),
              OrderLogItem(
                title: TranslationBase.of(context).dropoffLocation,
                value: amRequestViewModel.patientAmbulanceRequestOrdersList[index].dropOffLocation,
              ),
              if (amRequestViewModel.patientAmbulanceRequestOrdersList[index].statusId == 1)
                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: () {
                      amRequestViewModel.updatePressOrder(presOrderID: amRequestViewModel.pendingAmbulanceRequestOrder.id);
                    },
                  ),
                )
            ],
          ),
        ),
      ),
    );
  }

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