import 'package:diplomaticquarterapp/core/model/prescriptions/prescriptions_order.dart';
import 'package:diplomaticquarterapp/core/viewModels/er/rrt-view-model.dart';
import 'package:diplomaticquarterapp/locator.dart';
import 'package:diplomaticquarterapp/pages/ErService/rapid-response-team/rrt-order-list-item.dart';
import 'package:diplomaticquarterapp/pages/base/base_view.dart';
import 'package:diplomaticquarterapp/uitl/date_uitl.dart';
import 'package:diplomaticquarterapp/uitl/gif_loader_dialog_utils.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';


class RRTLogPage extends StatefulWidget{
  final  List<PrescriptionsOrder> orders;

  const RRTLogPage({this.orders});
  
  @override
  State<StatefulWidget> createState()  => RRTLogPageState();

}
class RRTLogPageState extends State<RRTLogPage>{

  RRTViewModel viewModel;

  @override
  Widget build(BuildContext context) {

    return BaseView<RRTViewModel>(
      onModelReady: (vm) => viewModel = vm,
      builder: (ctx, vm, widgetState){
        return ListView.builder(
            itemCount: widget.orders.length,
            itemBuilder: (ctx, idx) {
              var order =  widget.orders[idx];
              return RRTLogListItem(order, onCancel: deleteOrder);
            }
        );
      }
    );
  }

  deleteOrder(PrescriptionsOrder order) async {
    GifLoaderDialogUtils.showMyDialog(context);
    var success = await viewModel.cancelOrder(order);
    GifLoaderDialogUtils.hideDialog(context);
    if(success)
      setState(() {
        widget.orders.remove(order);
      });
  }

}


