import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:Intaleq/constant/colors.dart';
import 'package:Intaleq/constant/style.dart';
import 'package:Intaleq/controller/payment/passenger_wallet_history_controller.dart';
import 'package:Intaleq/views/widgets/my_scafold.dart';
import 'package:Intaleq/views/widgets/mycircular.dart';

class PaymentHistoryPassengerPage extends StatelessWidget {
  const PaymentHistoryPassengerPage({super.key});

  @override
  Widget build(BuildContext context) {
    Get.put(PassengerWalletHistoryController());
    return MyScafolld(
        title: 'Payment History'.tr,
        body: [
          GetBuilder<PassengerWalletHistoryController>(
            builder: (controller) => controller.isLoading
                ? const MyCircularProgressIndicator() // iOS-style loading indicator
                : controller.archive.isEmpty
                    ? Center(
                        child: Text(
                          'No wallet record found'.tr,
                          style: AppStyle.title,
                        ),
                      )
                    : CupertinoListSection.insetGrouped(
                        children: List.generate(
                          controller.archive.length,
                          (index) {
                            var list = controller.archive[index];
                            return CupertinoListTile(
                              backgroundColor: double.parse(list['balance']) < 0
                                  ? AppColor.redColor.withOpacity(.2)
                                  : AppColor.greenColor.withOpacity(.2),
                              title: Text(
                                list['balance'],
                                style: AppStyle.title.copyWith(
                                  color: CupertinoColors.black,
                                ),
                              ),
                              additionalInfo: Text(
                                list['created_at'],
                                style: AppStyle.title.copyWith(
                                  fontSize: 12,
                                  color: CupertinoColors.systemGrey,
                                ),
                              ),
                              padding: const EdgeInsets.symmetric(
                                  vertical: 8, horizontal: 16),
                            );
                          },
                        ),
                      ),
          )
        ],
        isleading: true);
  }
}
