import 'dart:convert';

import 'package:get/get.dart';
import 'package:siro_rider/constant/box_name.dart';
import 'package:siro_rider/constant/links.dart';
import 'package:siro_rider/controller/functions/crud.dart';
import 'package:siro_rider/main.dart';

import '../../views/widgets/mydialoug.dart';

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

  Future<void> getArchivePayment() async {
    try {
      isLoading = true;
      update();

      var res = await CRUD().getWallet(
        link: AppLink.getPassengerWalletArchive,
        payload: {'passenger_id': box.read(BoxName.passengerID)},
      );

      if (res != 'failure') {
        archive = jsonDecode(res)['message'];
      } else {
        MyDialog().getDialog('No wallet record found'.tr, '', () {
          Get.back();
          Get.back();
        });
      }
    } catch (e) {
      // MyDialog().getDialog('An error occurred'.tr, '', () {
      //   Get.back();
      // });
    } finally {
      isLoading = false;
      update();
    }
  }

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