import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:siro_admin/constant/style.dart';
import 'package:siro_admin/views/widgets/elevated_btn.dart';
import 'package:siro_admin/views/widgets/mycircular.dart';

import '../../../controller/admin/wallet_admin_controller.dart';
import '../../widgets/my_scafold.dart';

class Wallet extends StatelessWidget {
  Wallet({super.key});
  WalletAdminController walletAdminController =
      Get.put(WalletAdminController());
  @override
  Widget build(BuildContext context) {
    return MyScafolld(
      title: 'Wallet'.tr,
      body: [
        GetBuilder<WalletAdminController>(builder: (walletAdminController) {
          return Center(
            child: walletAdminController.isLoading
                ? const MyCircularProgressIndicator()
                : Column(
                    children: [
                      MyElevatedButton(
                          title: 'Pay to them to banks'.tr,
                          onPressed: () async {
                            await walletAdminController.payToBankDriverAll();
                          }),
                      SizedBox(
                        height: Get.height * .8,
                        child: ListView.builder(
                          itemCount:
                              walletAdminController.driversWalletPoints.length,
                          itemBuilder: (BuildContext context, int index) {
                            var res = walletAdminController
                                .driversWalletPoints[index];

                            if (res != null && res['name_arabic'] != null) {
                              return Padding(
                                padding: const EdgeInsets.all(4.0),
                                child: Container(
                                  decoration: AppStyle.boxDecoration1,
                                  child: Padding(
                                    padding: const EdgeInsets.symmetric(
                                        horizontal: 10),
                                    child: Row(
                                      mainAxisAlignment:
                                          MainAxisAlignment.spaceBetween,
                                      children: [
                                        Text(
                                            'driver name:  ${res['name_arabic'].toString()}'),
                                        Text(
                                            'Amount: ${res['total_amount'].toString()}'),
                                      ],
                                    ),
                                  ),
                                ),
                              );
                            } else {
                              return Container(); // Return an empty container if the data is null
                            }
                          },
                        ),
                      )
                    ],
                  ),
          );
        })
      ],
      isleading: true,
      action: IconButton(
        onPressed: () async {
          walletAdminController.getWalletForEachDriverToPay();
        },
        icon: const Icon(
          Icons.refresh,
          color: Colors.black,
        ),
      ),
    );
  }
}
