import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:get/get.dart';
import 'package:share_plus/share_plus.dart';

import '../../../constant/colors.dart';
import '../../../constant/links.dart';
import '../../../constant/style.dart';
import '../../../controller/home/profile/invit_controller.dart';
import '../../../controller/home/profile/invites_rewards_controller.dart';
import '../../../print.dart';
import '../../widgets/error_snakbar.dart';

class ShareAppPage extends StatelessWidget {
  final InviteController controller = Get.put(InviteController());
  final InvitesRewardsController rewardsController =
      Get.put(InvitesRewardsController());

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: AppColor.secondaryColor,
      appBar: AppBar(
        backgroundColor: AppColor.secondaryColor,
        elevation: 0,
        title: Text(
          'Invite'.tr,
          style: AppStyle.headTitle2.copyWith(fontSize: 20),
        ),
        leading: IconButton(
          icon: Icon(Icons.arrow_back_ios, color: AppColor.cyanBlue),
          onPressed: () => Get.back(),
        ),
      ),
      body: SafeArea(
        child: GetBuilder<InviteController>(
          builder: (controller) {
            return Column(
              children: [
                Expanded(
                  child: SingleChildScrollView(
                    padding: const EdgeInsets.all(16),
                    child: _buildPassengerTab(context),
                  ),
                ),
              ],
            );
          },
        ),
      ),
    );
  }

  Widget _buildPassengerTab(BuildContext context) {
    return Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        _buildPermanentCodeCard(context),
        const SizedBox(height: 10),
        _buildManualCodeEntry(context),
        const SizedBox(height: 20),
        Container(
          padding: const EdgeInsets.all(16),
          decoration: BoxDecoration(
            color: AppColor.grayColor.withOpacity(0.08),
            borderRadius: BorderRadius.circular(12),
          ),
          child: Column(
            children: [
              Text(
                "Share this code with your friends and earn rewards when they use it!"
                    .tr,
                textAlign: TextAlign.center,
                style: TextStyle(
                  color: AppColor.grayColor,
                  fontSize: 13,
                ),
              ),
            ],
          ),
        ),
        const SizedBox(height: 20),
        _buildPhoneInput(),
        const SizedBox(height: 20),
        _buildActionButtonsPassengers(),
        const SizedBox(height: 20),
        _buildInvitationsListPassengers(context),
        const SizedBox(height: 20),
        _buildUnifiedRewardsList(),
        const SizedBox(
            height: 60), // Add padding for the floating action button
      ],
    );
  }

  // Widget _buildPhoneInput() {
  //   return Container(
  //     decoration: BoxDecoration(
  //       color: CupertinoColors.systemGrey6,
  //       borderRadius: BorderRadius.circular(8),
  //     ),
  //     child: Row(
  //       children: [
  //         Expanded(
  //           child: CupertinoTextField.borderless(
  //             controller: controller.invitePhoneController,
  //             placeholder: 'Enter phone'.tr,
  //             padding: const EdgeInsets.all(12),
  //             keyboardType: TextInputType.phone,
  //           ),
  //         ),
  //         CupertinoButton(
  //           child: const Icon(CupertinoIcons.person_badge_plus,
  //               color: AppColor.blueColor),
  //           onPressed: () async {
  //             await controller.pickContacts();
  //             if (controller.contacts.isNotEmpty) {
  //               if (box.read(BoxName.isSavedPhones) == null) {
  //                 controller.savePhoneToServer();
  //                 box.write(BoxName.isSavedPhones, true);
  //               }
  //               _showContactsDialog(Get.context!);
  //             }
  //           },
  //         ),
  //       ],
  //     ),
  //   );
  // }
  Widget _buildPhoneInput() {
    return Container(
      decoration: BoxDecoration(
        color: AppColor.grayColor.withOpacity(0.1),
        borderRadius: BorderRadius.circular(12),
        border: Border.all(color: AppColor.grayColor.withOpacity(0.1)),
      ),
      child: Row(
        children: [
          Expanded(
            child: CupertinoTextField.borderless(
              controller: controller.invitePhoneController,
              placeholder: 'Enter phone'.tr,
              placeholderStyle: TextStyle(
                  color: AppColor.grayColor.withOpacity(0.5), fontSize: 16),
              style: TextStyle(color: AppColor.writeColor, fontSize: 16),
              padding: const EdgeInsets.all(14),
              keyboardType: TextInputType.phone,
            ),
          ),
          CupertinoButton(
            child: Icon(CupertinoIcons.person_badge_plus,
                color: AppColor.cyanBlue),
            onPressed: () async {
              await controller.pickContacts();
              Log.print('contacts: ${controller.contacts}');
              if (controller.contacts.isNotEmpty) {
                _showContactsDialog(Get
                    .context!); // Show contacts dialog after loading contacts
              } else {
                Get.snackbar(
                  'No contacts available'.tr,
                  'Please add contacts to your phone.'.tr,
                );
              }
            },
          ),
        ],
      ),
    );
  }

  Widget _buildActionButtonsPassengers() {
    return Padding(
      padding: const EdgeInsets.symmetric(vertical: 20.0, horizontal: 16.0),
      child: Row(
        children: [
          Expanded(
            child: Container(
              decoration: BoxDecoration(
                borderRadius: BorderRadius.circular(10),
                boxShadow: [
                  BoxShadow(
                    color: Colors.black.withOpacity(0.1),
                    blurRadius: 6,
                    offset: const Offset(0, 3),
                  ),
                ],
              ),
              child: CupertinoButton(
                color: AppColor.primaryColor,
                borderRadius: BorderRadius.circular(10),
                padding: const EdgeInsets.symmetric(vertical: 14),
                onPressed: controller.sendInviteToPassenger,
                child: Text(
                  'Send Invite'.tr,
                  style: TextStyle(
                    fontSize: 16,
                    fontWeight: FontWeight.bold,
                    color: AppColor.secondaryColor,
                  ),
                ),
              ),
            ),
          ),
          const SizedBox(width: 16),
          Expanded(
            child: Container(
              decoration: BoxDecoration(
                borderRadius: BorderRadius.circular(10),
                boxShadow: [
                  BoxShadow(
                    color: Colors.black.withOpacity(0.1),
                    blurRadius: 6,
                    offset: const Offset(0, 3),
                  ),
                ],
              ),
              child: CupertinoButton(
                color: AppColor.cyanBlue,
                borderRadius: BorderRadius.circular(10),
                padding: const EdgeInsets.symmetric(vertical: 14),
                child: Text(
                  'Show Invitations'.tr,
                  style: TextStyle(
                    fontSize: 16,
                    fontWeight: FontWeight.bold,
                    color: AppColor.secondaryColor,
                  ),
                ),
                onPressed: () async {
                  controller.fetchDriverStatsPassengers();
                },
              ),
            ),
          ),
        ],
      ),
    );
  }

  Widget _buildInvitationsListPassengers(BuildContext context) {
    return Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        Text("Invitations Sent".tr,
            style: TextStyle(
                fontSize: 17, 
                fontWeight: FontWeight.bold,
                color: AppColor.writeColor,
            )),
        const SizedBox(height: 10),
        controller.driverInvitationDataToPassengers.isEmpty
            ? Center(
                child: Text(
                  "No invitation found yet!".tr,
                  style: TextStyle(
                    color: AppColor.grayColor,
                    fontSize: 17,
                  ),
                ),
              )
            : ListView.builder(
                shrinkWrap: true,
                physics: const NeverScrollableScrollPhysics(),
                itemCount: controller.driverInvitationDataToPassengers.length,
                itemBuilder: (context, index) {
                  return _buildInvitationItemPassengers(context, index);
                },
              ),
      ],
    );
  }

  Widget _buildInvitationItemPassengers(BuildContext context, int index) {
    // Extracting the data from the sample JSON-like structure
    var invitation = controller.driverInvitationDataToPassengers[index];

    int countOfInvitDriver =
        int.tryParse(invitation['countOfInvitDriver']?.toString() ?? '0') ?? 0;
    double progressValue = (countOfInvitDriver / 10.0).clamp(0.0, 1.0);

    return GestureDetector(
      onTap: () {
        controller.onSelectPassengerInvitation(index);
      },
      child: Container(
        margin: const EdgeInsets.symmetric(vertical: 8.0),
        padding: const EdgeInsets.all(16),
        decoration: BoxDecoration(
          color: AppColor.grayColor.withOpacity(0.08),
          borderRadius: BorderRadius.circular(12),
          border: Border.all(color: AppColor.grayColor.withOpacity(0.05)),
        ),
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            Text(
              invitation['passengerName']
                  .toString(), // Handle null or missing data
              style: TextStyle(
                fontSize: 17,
                fontWeight: FontWeight.w600,
                color: AppColor.writeColor,
              ),
            ),
            const SizedBox(height: 8),
            ClipRRect(
              borderRadius: BorderRadius.circular(4),
              child: LinearProgressIndicator(
                value: progressValue,
                backgroundColor: AppColor.grayColor.withOpacity(0.1),
                valueColor:
                    AlwaysStoppedAnimation<Color>(AppColor.primaryColor),
                minHeight: 6,
              ),
            ),
            const SizedBox(height: 4),
            Text(
              '$countOfInvitDriver / 2 ${'Trip'.tr}', // Show trips completed
              style: TextStyle(
                fontSize: 13,
                color: AppColor.grayColor,
              ),
            ),
          ],
        ),
      ),
    );
  }

  Widget _buildPassengerStats(BuildContext context) {
    return Container(
      padding: const EdgeInsets.all(16),
      decoration: BoxDecoration(
        color: AppColor.grayColor.withOpacity(0.08),
        borderRadius: BorderRadius.circular(12),
        border: Border.all(color: AppColor.grayColor.withOpacity(0.05)),
      ),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Text(
            "Your Rewards".tr,
            style: TextStyle(
              fontSize: 17,
              fontWeight: FontWeight.w600,
              color: AppColor.writeColor,
            ),
          ),
          const SizedBox(height: 16),
          _buildStatItem(
            context,
            "Total Invites".tr,
            controller.driverInvitationDataToPassengers[0]['countOfInvitDriver']
                .toString(),
          ),
          _buildStatItem(
            context,
            "Active Users".tr,
            controller.driverInvitationDataToPassengers[0]['passengerName']
                .toString(),
          ),
        ],
      ),
    );
  }

  Widget _buildStatItem(BuildContext context, String label, String value) {
    return Padding(
      padding: const EdgeInsets.symmetric(vertical: 8.0),
      child: Row(
        mainAxisAlignment: MainAxisAlignment.spaceBetween,
        children: [
          Text(
            label,
            style: TextStyle(
              color: AppColor.writeColor,
              fontSize: 15,
            ),
          ),
          Text(
            value,
            style: const TextStyle(
              fontWeight: FontWeight.w600,
              color: AppColor.blueColor,
              fontSize: 15,
            ),
          ),
        ],
      ),
    );
  }

  void _showContactsDialog(BuildContext context) {
    Get.defaultDialog(
      backgroundColor: AppColor.secondaryColor,
      title: 'Choose from contact'.tr,
      titleStyle: TextStyle(color: AppColor.writeColor),
      content: SizedBox(
        height: 400,
        width: 400,
        child: Column(
          children: [
            // Header with cancel and title
            // Container(
            //   padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 12),
            //   decoration: const BoxDecoration(
            //     borderRadius: BorderRadius.vertical(top: Radius.circular(20)),
            //     color: CupertinoColors.systemGrey6,
            //   ),
            //   child: Row(
            //     mainAxisAlignment: MainAxisAlignment.spaceBetween,
            //     children: [
            //       CupertinoButton(
            //         padding: EdgeInsets.zero,
            //         child: Text(
            //           'Cancel'.tr,
            //           style: const TextStyle(color: CupertinoColors.systemBlue),
            //         ),
            //         onPressed: () => Navigator.pop(context),
            //       ),
            //       Container(
            //           child: Text('Choose from contact'.tr,
            //               style: AppStyle.title)),
            //       const SizedBox(width: 60), // Balance for Cancel button
            //     ],
            //   ),
            // ),

            // Contact list
            Expanded(
              child: ListView.builder(
                itemCount: controller.contactMaps.length,
                itemBuilder: (context, index) {
                  final contact = controller.contactMaps[index];
                  return CupertinoButton(
                    padding: EdgeInsets.zero,
                    onPressed: () {
                      controller.selectPhone(contact['phones'].toString());
                    },
                    child: Container(
                      padding: const EdgeInsets.symmetric(
                          horizontal: 16, vertical: 12),
                      decoration: BoxDecoration(
                        color: AppColor.secondaryColor,
                        border: Border(
                          bottom: BorderSide(
                            color: AppColor.grayColor.withOpacity(0.1),
                          ),
                        ),
                      ),
                      child: Row(
                        children: [
                          // Display contact name and phone number
                          Expanded(
                            child: Column(
                              crossAxisAlignment: CrossAxisAlignment.start,
                              children: [
                                Text(
                                  contact['name'],
                                  style: TextStyle(
                                    color: AppColor.writeColor,
                                    fontSize: 17,
                                    fontWeight: FontWeight.w500,
                                  ),
                                ),
                                Text(
                                  (contact['phones'][0].toString()),
                                  style: TextStyle(
                                    color: AppColor.grayColor,
                                    fontSize: 15,
                                  ),
                                ),
                              ],
                            ),
                          ),
                          // Chevron icon for selection
                          Icon(
                            CupertinoIcons.chevron_forward,
                            color: AppColor.grayColor.withOpacity(0.5),
                          ),
                        ],
                      ),
                    ),
                  );
                },
              ),
            ),
          ],
        ),
      ),
    );
    // showCupertinoModalPopup(
    //   context: context,
    //   builder: (BuildContext context) => Container(
    //     height: 400,
    //     decoration: BoxDecoration(
    //       color: CupertinoColors.systemBackground,
    //       borderRadius: const BorderRadius.vertical(top: Radius.circular(20)),
    //       boxShadow: [
    //         BoxShadow(
    //           color: CupertinoColors.black.withOpacity(0.2),
    //           offset: const Offset(0, -4),
    //           blurRadius: 10,
    //         ),
    //       ],
    //     ),
    //     child: Column(
    //       children: [
    //         // Header with cancel and title
    //         Container(
    //           padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 12),
    //           decoration: const BoxDecoration(
    //             borderRadius: BorderRadius.vertical(top: Radius.circular(20)),
    //             color: CupertinoColors.systemGrey6,
    //           ),
    //           child: Row(
    //             mainAxisAlignment: MainAxisAlignment.spaceBetween,
    //             children: [
    //               CupertinoButton(
    //                 padding: EdgeInsets.zero,
    //                 child: Text(
    //                   'Cancel'.tr,
    //                   style: const TextStyle(color: CupertinoColors.systemBlue),
    //                 ),
    //                 onPressed: () => Navigator.pop(context),
    //               ),
    //               Container(
    //                   child: Text('Choose from contact'.tr,
    //                       style: AppStyle.title)),
    //               const SizedBox(width: 60), // Balance for Cancel button
    //             ],
    //           ),
    //         ),

    //         // Contact list
    //         Expanded(
    //           child: ListView.builder(
    //             itemCount: controller.contactMaps.length,
    //             itemBuilder: (context, index) {
    //               final contact = controller.contactMaps[index];
    //               return CupertinoButton(
    //                 padding: EdgeInsets.zero,
    //                 onPressed: () {
    //                   controller.selectPhone(contact['phones'].toString());
    //                 },
    //                 child: Container(
    //                   padding: const EdgeInsets.symmetric(
    //                       horizontal: 16, vertical: 12),
    //                   decoration: BoxDecoration(
    //                     color: CupertinoColors.systemBackground,
    //                     border: Border(
    //                       bottom: BorderSide(
    //                         color: CupertinoColors.separator.withOpacity(0.5),
    //                       ),
    //                     ),
    //                   ),
    //                   child: Row(
    //                     children: [
    //                       // Display contact name and phone number
    //                       Expanded(
    //                         child: Column(
    //                           crossAxisAlignment: CrossAxisAlignment.start,
    //                           children: [
    //                             Text(
    //                               contact['name'],
    //                               style: const TextStyle(
    //                                 color: CupertinoColors.label,
    //                                 fontSize: 17,
    //                                 fontWeight: FontWeight.w500,
    //                               ),
    //                             ),
    //                             Text(
    //                               controller.formatPhoneNumber(
    //                                   contact['phones'][0].toString()),
    //                               style: const TextStyle(
    //                                 color: CupertinoColors.secondaryLabel,
    //                                 fontSize: 15,
    //                               ),
    //                             ),
    //                           ],
    //                         ),
    //                       ),
    //                       // Chevron icon for selection
    //                       const Icon(
    //                         CupertinoIcons.chevron_forward,
    //                         color: CupertinoColors.systemGrey2,
    //                       ),
    //                     ],
    //                   ),
    //                 ),
    //               );
    //             },
    //           ),
    //         ),
    //       ],
    //     ),
    //   ),
    // );
  }



  Widget _buildUnifiedRewardsList() {
    return GetBuilder<InvitesRewardsController>(
      builder: (rewardsController) {
        if (rewardsController.isLoading) {
          return const Center(child: CupertinoActivityIndicator());
        }

        var filteredList = rewardsController.referrals;

        if (filteredList.isEmpty) {
          return const SizedBox(); // Hide if no valid rewards
        }

        return Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            Text("Reward Status".tr,
                style:
                    const TextStyle(fontSize: 17, fontWeight: FontWeight.bold)),
            const SizedBox(height: 10),
            ListView.builder(
              shrinkWrap: true,
              physics: const NeverScrollableScrollPhysics(),
              itemCount: filteredList.length,
              itemBuilder: (context, index) {
                var ref = filteredList[index];
                int trips = ref['trip_count'] ?? 0;
                int target = ref['target_trips'] ?? 1;
                bool canClaim = ref['can_claim'] ?? false;
                bool isClaimed = ref['is_reward_claimed'] == 1;

                return Container(
                  margin: const EdgeInsets.only(bottom: 12),
                  padding: const EdgeInsets.all(16),
                  decoration: BoxDecoration(
                    color: CupertinoColors.systemGrey6,
                    borderRadius: BorderRadius.circular(12),
                  ),
                  child: Row(
                    children: [
                      Expanded(
                        child: Column(
                          crossAxisAlignment: CrossAxisAlignment.start,
                          children: [
                            Text(
                                ref['invited_user_type'] == 'driver'
                                    ? "Driver Referral".tr
                                    : "Passenger Referral".tr,
                                style: const TextStyle(
                                    fontWeight: FontWeight.bold)),
                            const SizedBox(height: 4),
                            Text("Trips: $trips / $target".tr,
                                style: const TextStyle(
                                    color: CupertinoColors.secondaryLabel,
                                    fontSize: 13)),
                            if (isClaimed)
                              Text("Reward Claimed".tr,
                                  style: const TextStyle(
                                      color: CupertinoColors.activeGreen,
                                      fontSize: 12,
                                      fontWeight: FontWeight.bold))
                            else if (!canClaim)
                              Text("Waiting for trips".tr,
                                  style: const TextStyle(
                                      color: CupertinoColors.systemOrange,
                                      fontSize: 12))
                            else
                              Text("Reward Earned".tr,
                                  style: const TextStyle(
                                      color: CupertinoColors.activeGreen,
                                      fontSize: 12,
                                      fontWeight: FontWeight.bold))
                          ],
                        ),
                      ),
                    ],
                  ),
                );
              },
            ),
          ],
        );
      },
    );
  }

  Widget _buildPermanentCodeCard(BuildContext context) {
    return GetBuilder<InvitesRewardsController>(
      builder: (rc) {
        String code = rc.referralCode ?? 'Loading...'.tr;
        return Container(
          width: double.infinity,
          padding: const EdgeInsets.all(20),
          margin: const EdgeInsets.symmetric(vertical: 10),
          decoration: BoxDecoration(
            color: AppColor.grayColor.withOpacity(0.08),
            borderRadius: BorderRadius.circular(12),
            border: Border.all(color: AppColor.cyanBlue.withOpacity(0.2)),
          ),
          child: Column(
            children: [
              Text(
                "Your Permanent Referral Code".tr,
                style: TextStyle(
                  fontSize: 14,
                  color: AppColor.grayColor,
                  fontWeight: FontWeight.w500,
                ),
              ),
              const SizedBox(height: 12),
              Row(
                mainAxisAlignment: MainAxisAlignment.center,
                children: [
                  Text(
                    code,
                    style: TextStyle(
                      fontSize: 24,
                      fontWeight: FontWeight.bold,
                      color: AppColor.cyanBlue,
                      letterSpacing: 2,
                    ),
                  ),
                  if (rc.referralCode != null) ...[
                    const SizedBox(width: 16),
                    GestureDetector(
                      onTap: () {
                        Clipboard.setData(ClipboardData(text: rc.referralCode!));
                        mySnackbarSuccess('Code copied!'.tr);
                      },
                      child: Icon(
                        CupertinoIcons.doc_on_doc,
                        color: AppColor.cyanBlue,
                        size: 20,
                      ),
                    ),
                  ],
                ],
              ),
              if (rc.referralCode != null) ...[
                const SizedBox(height: 16),
                CupertinoButton(
                  color: AppColor.cyanBlue.withOpacity(0.1),
                  padding: const EdgeInsets.symmetric(horizontal: 24, vertical: 8),
                  borderRadius: BorderRadius.circular(8),
                  onPressed: () {
                    final appName = 'Siro';
                    final shareText = 'Get a ride with $appName! Use my referral code: ${rc.referralCode} for a discount.\nDownload: ${AppLink.inviteRedirectUrl}?code=${rc.referralCode}&app=rider\n\n💡 Note: If the link is not clickable, save this number or reply to activate links!';
                    Share.share(shareText);
                  },
                  child: Row(
                    mainAxisSize: MainAxisSize.min,
                    children: [
                      Icon(CupertinoIcons.share, color: AppColor.cyanBlue, size: 18),
                      const SizedBox(width: 8),
                      Text(
                        'Share via WhatsApp Groups'.tr,
                        style: TextStyle(
                          color: AppColor.cyanBlue,
                          fontSize: 14,
                          fontWeight: FontWeight.bold,
                        ),
                      ),
                    ],
                  ),
                ),
              ],
            ],
          ),
        );
      },
    );
  }

  Widget _buildManualCodeEntry(BuildContext context) {
    final TextEditingController manualCodeController = TextEditingController();
    return Container(
      padding: const EdgeInsets.all(16),
      margin: const EdgeInsets.symmetric(vertical: 10),
      decoration: BoxDecoration(
        color: AppColor.grayColor.withOpacity(0.08),
        borderRadius: BorderRadius.circular(12),
      ),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Text(
            "Enter Inviter's Code".tr,
            style: TextStyle(
              fontSize: 15,
              fontWeight: FontWeight.bold,
              color: AppColor.writeColor,
            ),
          ),
          const SizedBox(height: 8),
          Text(
            "If someone referred you, enter their code below to link accounts and receive rewards.".tr,
            style: TextStyle(
              fontSize: 12,
              color: AppColor.grayColor,
            ),
          ),
          const SizedBox(height: 12),
          Row(
            children: [
              Expanded(
                child: Container(
                  decoration: BoxDecoration(
                    color: AppColor.secondaryColor,
                    borderRadius: BorderRadius.circular(8),
                    border: Border.all(color: AppColor.grayColor.withOpacity(0.2)),
                  ),
                  child: CupertinoTextField.borderless(
                    controller: manualCodeController,
                    placeholder: 'Enter Code (e.g. AB1234)'.tr,
                    placeholderStyle: TextStyle(color: AppColor.grayColor.withOpacity(0.5)),
                    style: TextStyle(color: AppColor.writeColor),
                    padding: const EdgeInsets.all(10),
                    textCapitalization: TextCapitalization.characters,
                  ),
                ),
              ),
              const SizedBox(width: 12),
              CupertinoButton(
                color: AppColor.cyanBlue,
                padding: const EdgeInsets.symmetric(horizontal: 16),
                borderRadius: BorderRadius.circular(8),
                onPressed: () {
                  if (manualCodeController.text.trim().isNotEmpty) {
                    rewardsController.linkInviteCode(manualCodeController.text.trim());
                    manualCodeController.clear();
                  } else {
                    mySnackeBarError('Please enter a referral code'.tr);
                  }
                },
                child: Text('Link'.tr, style: const TextStyle(color: Colors.white, fontSize: 14)),
              ),
            ],
          ),
        ],
      ),
    );
  }
}
