import 'package:flutter/material.dart';

import 'package:get/get.dart';
import 'package:SEFER/views/home/my_wallet/payment_history_passenger_page.dart';
import '../../../constant/box_name.dart';
import '../../../constant/colors.dart';
import '../../../constant/info.dart';
import '../../../constant/style.dart';
import '../../../controller/home/payment/credit_card_controller.dart';
import '../../../controller/payment/payment_controller.dart';
import '../../../main.dart';
import '../../widgets/elevated_btn.dart';
import '../../widgets/my_scafold.dart';
import 'passenger_wallet_dialoge.dart';

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

  @override
  Widget build(BuildContext context) {
    Get.put(PaymentController());
    Get.put(CreditCardController());
    return MyScafolld(
      title: 'My Wallet'.tr,
      isleading: true,
      body: [
        GetBuilder<PaymentController>(
          builder: (controller) => Column(
            mainAxisAlignment: MainAxisAlignment.start,
            crossAxisAlignment: CrossAxisAlignment.center,
            children: [
              const CardSeferWallet(),
              const SizedBox(
                height: 20,
              ),
              Padding(
                padding: const EdgeInsets.symmetric(horizontal: 30),
                child: Row(
                  children: [
                    MyElevatedButton(
                      kolor: AppColor.blueColor,
                      title: 'Payment History'.tr,
                      onPressed: () {
                        Get.to(() => const PaymentHistoryPassengerPage(),
                            transition: Transition.size);
                      },
                    ),
                  ],
                ),
              )
            ],
          ),
        ),
        GetBuilder<PaymentController>(
            builder: (controller) => controller.isPromoSheetDialogue
                ? Container(
                    color: AppColor.accentColor.withOpacity(.91),
                  )
                : const SizedBox()),
        GetBuilder<PaymentController>(
            builder: (controller) => Positioned(
                  bottom: Get.height * .2,
                  left: Get.width * .2,
                  right: Get.width * .2,
                  child: MyElevatedButton(
                    title: 'Show Promos to Charge'.tr,
                    onPressed: () {
                      controller.changePromoSheetDialogue();
                    },
                  ),
                )),
        const PassengerWalletDialoge(),
      ],
    );
  }
}

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

  @override
  Widget build(BuildContext context) {
    return GetBuilder<PaymentController>(builder: (paymentController) {
      return Row(
        mainAxisAlignment: MainAxisAlignment.center,
        children: [
          Container(
            width: Get.width * .85,
            height: Get.height * .3,
            decoration: BoxDecoration(
              color: AppColor.deepPurpleAccent,
              borderRadius: const BorderRadius.all(Radius.circular(12)),
              gradient: const LinearGradient(
                  colors: [AppColor.blueColor, AppColor.primaryColor]),
            ),
            child: Column(
              mainAxisAlignment: MainAxisAlignment.spaceEvenly,
              children: [
                Row(
                  children: [
                    Text(
                      '${AppInformation.appName} Wallet',
                      style: AppStyle.headTitle
                          .copyWith(color: AppColor.primaryColor),
                    )
                  ],
                ),
                Row(
                  mainAxisAlignment: MainAxisAlignment.center,
                  children: [
                    Text(
                      '${box.read(BoxName.passengerWalletTotal)} \$' ??
                          '0.0 \$',
                      style: AppStyle.headTitle2,
                    )
                  ],
                ),
                Row(
                  mainAxisAlignment: MainAxisAlignment.end,
                  children: [
                    Text(
                      box.read(BoxName.name),
                      style: AppStyle.title,
                    )
                  ],
                )
              ],
            ),
          ),
        ],
      );
    });
  }
}
