import 'package:flutter/cupertino.dart';
import 'package:get/get.dart';

import '../../../Data/Repository/Summary/ordersrepository.dart';
import '../../../Model/Response/Summary/Getsummarysresponse.dart';

class MonthOrderController extends GetxController{

  String? currentTime;
  String? notificationDate;


  RxBool shimmer = true.obs;
  bool filter2 = false;
  bool searchMode = false;
  bool showOrder = false;

  List<DeliveriesDetails> orderAllList = [];
  List<DeliveriesDetails> searchCompare = [];

  var orderId;
  var orderHeaderId;
  var userId;


  OrderSummaryRepository orderSummaryRepository = OrderSummaryRepository();

  TextEditingController searchController = TextEditingController();


  getOrders() async{
    GetDeliveries? result = await orderSummaryRepository.getOrdersMonth();
    monthOrderResult(result!);
    print('printresultjson${result.toJson()}');
  }

  monthOrderResult(GetDeliveries orderData) async{
    print('todayorderresultss');
    orderAllList.clear();
    if (orderData.details!= null) {
      print('dataDetailsif${orderData.details}');
      searchCompare.clear();
      searchCompare.addAll(orderData.details!);
      orderAllList.addAll(orderData.details!);
      print('orderalllistlengthincontroller${orderAllList.length}');

    }
    for (var currentOrdersValue in orderAllList) {
      if ((currentOrdersValue.orderstatus != 'created')) {
        showOrder = true;
        print('showNoOrderssif$showOrder');
        break;
      } else {
        showOrder = false;
        print('showNoOrder$showOrder');
      }
    }
    shimmer.value = false;
    update();

  }


  search(String searchData) {
    print("datasearchData$searchData");
    print("lenght${orderAllList.length}");
    orderAllList.clear();
    searchCompare.addAll(orderAllList);
    if (filter2 == true) {
      List<DeliveriesDetails> search = searchCompare
          .where((value) =>
      value.pickupcontactno!
          .toLowerCase()
          .contains(searchController.text.toLowerCase()) ==
          true)
          .toList();
      update();
      searchMode = true;
      orderAllList = search;
    } else {
      List<DeliveriesDetails>search = searchCompare
          .where((value) =>
      value.pickupcontactno!
          .toLowerCase()
          .contains(searchController.text.toLowerCase()) ==
          true)
          .toList();

      update();
      searchMode = true;
      orderAllList = search;
    }

  }

  @override
  void onInit() {
    // TODO: implement onInit
    super.onInit();
  }
}