import 'package:diplomaticquarterapp/core/model/er/PatientAllPresOrders.dart';
import 'package:diplomaticquarterapp/core/viewModels/er/am_request_view_model.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/data_display/text.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.patientAllPresOrdersList.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.patientAllPresOrdersList[index].iD
                    .toString(),
              ),
              OrderLogItem(
                title: TranslationBase.of(context).orderStatus,
                value: amRequestViewModel
                    .patientAllPresOrdersList[index].description,
              ),
              OrderLogItem(
                title: TranslationBase.of(context).pickupDate,
                value: DateUtil.getDayMonthYearDateFormatted(
                    DateUtil.convertStringToDate(amRequestViewModel
                        .patientAllPresOrdersList[index].createdOn)),
              ),
              OrderLogItem(
                title: TranslationBase.of(context).pickupLocation,
                value: amRequestViewModel
                    .patientAllPresOrdersList[index].pickupLocationName,
              ),
              OrderLogItem(
                title: TranslationBase.of(context).dropoffLocation,
                value: amRequestViewModel
                    .patientAllPresOrdersList[index].dropoffLocationName,
              ),
              if(amRequestViewModel.patientAllPresOrdersList[index].status==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.pickUpRequestPresOrder.presOrderID );

                    },
                  ),
                )
            ],
          ),
        ),
      ),
    );
  }
}
