import 'package:sefer_driver/controller/functions/tts.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:sefer_driver/controller/home/payment/captain_wallet_controller.dart';

import '../../../../../constant/style.dart';
import '../../../../widgets/elevated_btn.dart';
import '../../../../../controller/home/captin/home_captain_controller.dart';

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

  @override
  Widget build(BuildContext context) {
    // final OrderRequestController orderRequestController =
    //     Get.put(OrderRequestController());
    CaptainWalletController captainWalletController =
        Get.put(CaptainWalletController());
    int refusedRidesToday = 0;
    captainWalletController.getCaptainWalletFromBuyPoints();
    return Center(
      child: GetBuilder<HomeCaptainController>(
          builder: (homeCaptainController) => double.parse(
                      (captainWalletController.totalPoints)) <
                  -200
              ? CupertinoButton(
                  onPressed: () {
                    Get.defaultDialog(
                        // backgroundColor: CupertinoColors.destructiveRed,
                        barrierDismissible: false,
                        title: double.parse(
                                    (captainWalletController.totalPoints)) <
                                -200
                            ? 'You dont have Points'.tr
                            : 'You Are Stopped For this Day !'.tr,
                        titleStyle: AppStyle.title,
                        content: Column(
                          children: [
                            IconButton(
                              onPressed: () async {
                                double.parse((captainWalletController
                                            .totalPoints)) <
                                        -200
                                    ? await Get.find<TextToSpeechController>()
                                        .speakText(
                                            'You must be recharge your Account'
                                                .tr)
                                    : await Get.find<TextToSpeechController>()
                                        .speakText(
                                            'You Refused 3 Rides this Day that is the reason \nSee you Tomorrow!'
                                                .tr);
                              },
                              icon: const Icon(Icons.headphones),
                            ),
                            Text(
                              double.parse((captainWalletController
                                          .totalPoints)) <
                                      -200
                                  ? 'You must be recharge your Account'.tr
                                  : 'You Refused 3 Rides this Day that is the reason \nSee you Tomorrow!'
                                      .tr,
                              style: AppStyle.title,
                            ),
                          ],
                        ),
                        confirm: double.parse(
                                    (captainWalletController.totalPoints)) <
                                -200
                            ? MyElevatedButton(
                                title: 'Recharge my Account'.tr,
                                onPressed: () {
                                  homeCaptainController.goToWalletFromConnect();
                                })
                            : MyElevatedButton(
                                title: 'Ok , See you Tomorrow'.tr,
                                onPressed: () {
                                  Get.back();
                                  Get.back();
                                }));
                  },
                  color: CupertinoColors.destructiveRed,
                  child: Text(
                    'You are Stopped'.tr,
                    style: AppStyle.title,
                  ),
                )
              : Container(
                  decoration: BoxDecoration(
                    gradient: LinearGradient(
                      begin: Alignment.topLeft,
                      end: Alignment.bottomRight,
                      colors: homeCaptainController.isActive
                          ? [const Color(0xFF00C853), const Color(0xFF00E676)]
                          : [Colors.grey.shade600, Colors.grey.shade400],
                    ),
                    borderRadius: BorderRadius.circular(20),
                    boxShadow: [
                      BoxShadow(
                        color: (homeCaptainController.isActive
                                ? const Color(0xFF00C853)
                                : Colors.grey)
                            .withOpacity(0.4),
                        spreadRadius: 0,
                        blurRadius: 15,
                        offset: const Offset(0, 5),
                      ),
                    ],
                  ),
                  child: CupertinoButton(
                    onPressed: homeCaptainController.onButtonSelected,
                    padding: const EdgeInsets.symmetric(
                        horizontal: 20, vertical: 10),
                    child: Row(
                      mainAxisSize: MainAxisSize.min,
                      children: [
                        Container(
                          padding: const EdgeInsets.all(4),
                          decoration: BoxDecoration(
                            color: Colors.white.withOpacity(0.2),
                            shape: BoxShape.circle,
                          ),
                          child: Icon(
                            homeCaptainController.isActive
                                ? Icons.power_settings_new_rounded
                                : Icons.power_off_rounded,
                            color: Colors.white,
                            size: 20,
                          ),
                        ),
                        const SizedBox(width: 10),
                        Text(
                          homeCaptainController.isActive
                              ? 'Online'.tr
                              : 'Offline'.tr,
                          style: const TextStyle(
                            color: Colors.white,
                            fontSize: 16,
                            fontWeight: FontWeight.bold,
                            letterSpacing: 0.5,
                          ),
                        ),
                      ],
                    ),
                  ),
                )),
    );
  }
}
