import 'dart:convert';

import 'package:siro_driver/views/widgets/elevated_btn.dart';
import 'package:get/get.dart';
import 'package:siro_driver/constant/box_name.dart';
import 'package:siro_driver/constant/links.dart';
import 'package:siro_driver/controller/functions/crud.dart';
import 'package:siro_driver/main.dart';

class DriverWalletHistoryController extends GetxController {
  bool isLoading = false;
  List archive = [];
  List weeklyList = [];

  getArchivePayment() async {
    isLoading = true;
    update();
    var res = await CRUD().getWallet(
        link: AppLink.getWalletByDriver,
        payload: {'driverID': box.read(BoxName.driverID)});
    if (res == 'failure') {
      Get.defaultDialog(
          barrierDismissible: false,
          title: 'There is no data yet.'.tr,
          middleText: '',
          confirm: MyElevatedButton(
            title: 'Back'.tr,
            onPressed: () {
              Get.back();
              // Get.back();
            },
          ));
    }
    archive = jsonDecode(res)['message'];

    isLoading = false;
    update();
  }

  getWeekllyArchivePayment() async {
    isLoading = true;
    update();
    var res = await CRUD().getWallet(
        link: AppLink.getDriverWeekPaymentMove,
        payload: {'driverID': box.read(BoxName.driverID)});
    if (res == 'failure') {
      Get.defaultDialog(
          barrierDismissible: false,
          title: 'There is no data yet.'.tr,
          middleText: '',
          confirm: MyElevatedButton(
            title: 'Back'.tr,
            onPressed: () {
              Get.back();
              // Get.back();
            },
          ));
    } else {
      weeklyList = jsonDecode(res)['message'];
    }

    isLoading = false;
    update();
  }

  @override
  void onInit() {
    // getArchivePayment();
    super.onInit();
  }
}
