import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'package:get/get.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:traderscircuit/Utils/Common/CommonAppbar.dart';
import 'package:traderscircuit/Utils/Common/commonBotton.dart';
import 'package:traderscircuit/Utils/Common/comonGlassmorphicContainer.dart';
import 'package:traderscircuit/Utils/Common/sized_box.dart';
import 'package:traderscircuit/Utils/base_manager.dart';
import 'package:traderscircuit/Utils/text.dart';
import 'package:traderscircuit/Utils/utils.dart';
import 'package:traderscircuit/resources/routes/route_name.dart';
import 'package:traderscircuit/view/onBoarding/splashScreen1.dart';
import 'package:traderscircuit/view_model/Login/delete_account_api.dart';
import 'package:traderscircuit/Utils/Dialogs.dart';

class Settings extends StatefulWidget {
  const Settings({super.key});

  @override
  State<Settings> createState() => _SettingsState();
}

class _SettingsState extends State<Settings> {
  bool isSwitched = false;
  bool isSwitched1 = false;
  bool isSwitched2 = false;
  bool isSwitched3 = false;

  void _toggleSwitch(bool value) {
    setState(() {
      isSwitched = value;
    });
  }

  void _toggleSwitch1(bool value1) {
    setState(() {
      isSwitched1 = value1;
    });
  }

  void _toggleSwitch2(bool value2) {
    setState(() {
      isSwitched2 = value2;
    });
  }

  void _toggleSwitch3(bool value3) {
    setState(() {
      isSwitched3 = value3;
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: CommonAppbar(
        titleTxt: "Settings",
      ),
      backgroundColor: Colors.black,
      extendBody: true,
      body: Stack(
        children: [
          CommonBlurLeft(),
          CommonBlurRight(),
          Stack(
            children: [
              Padding(
                padding: EdgeInsets.symmetric(horizontal: 16, vertical: 16),
                child: ListView(
                  physics: BouncingScrollPhysics(),
                  // mainAxisAlignment: MainAxisAlignment.start,
                  // crossAxisAlignment: CrossAxisAlignment.start,

                  children: [
                    //  CommonDropdownBtn(hint: "hint", items: ["hi", "hii"]),

                    SizedBox(
                      height: 40.h,
                    ),
                    Row(
                      children: [
                        text18W500("Setup your security"),
                        Spacer(),
                        Icon(
                          Icons.arrow_forward_ios_rounded,
                          color: Colors.white,
                          size: 24,
                        )
                      ],
                    ),
                    SizedBox(
                      height: 50.h,
                    ),
                    text25W600("Notifications"),
                    SizedBox(
                      height: 30.h,
                    ),
                    Row(
                      children: [
                        text20W400("WhatsApp Notifications"),
                        Spacer(),
                        Switch(
                          value: isSwitched,
                          onChanged: _toggleSwitch,
                          activeTrackColor: Colors.green,
                          activeColor: Colors.white,
                          inactiveTrackColor: Colors.white,
                          inactiveThumbColor: Colors.black,
                        ),
                      ],
                    ),
                    SizedBox(
                      height: 40.h,
                    ),
                    Row(
                      children: [
                        text20W400("In - App Notifications"),
                        Spacer(),
                        Switch(
                          value: isSwitched1,
                          onChanged: _toggleSwitch1,
                          activeTrackColor: Colors.green,
                          activeColor: Colors.white,
                          inactiveTrackColor: Colors.white,
                          inactiveThumbColor: Colors.black,
                        ),
                      ],
                    ),
                    SizedBox(
                      height: 40.h,
                    ),
                    Row(
                      children: [
                        text20W400("Push Notifications"),
                        Spacer(),
                        Switch(
                          value: isSwitched2,
                          onChanged: _toggleSwitch2,
                          activeTrackColor: Colors.green,
                          activeColor: Colors.white,
                          inactiveTrackColor: Colors.white,
                          inactiveThumbColor: Colors.black,
                        ),
                      ],
                    ),
                    SizedBox(
                      height: 40.h,
                    ),
                    Row(
                      children: [
                        text20W400("E-mail Notifications"),
                        Spacer(),
                        Switch(
                          value: isSwitched3,
                          onChanged: _toggleSwitch3,
                          activeTrackColor: Colors.green,
                          activeColor: Colors.white,
                          inactiveTrackColor: Colors.white,
                          inactiveThumbColor: Colors.black,
                        ),
                      ],
                    ),
                    SizedBox(
                      height: 60.h,
                    ),
                    Row(
                      children: [
                        InkWell(
                          child: Image.asset(
                            "assets/images/png/Delete.png",
                            width: 20,
                            height: 22,
                          ),
                          onTap: () {
                            Get.bottomSheet(
                              commonGlassContainer(
                                width: double.infinity,
                                height: 363.h,
                                borderradius: 4,
                                customWidget: Center(
                                  child: Padding(
                                    padding:
                                        EdgeInsets.symmetric(horizontal: 20.w),
                                    child: Column(
                                      children: [
                                        sizedBoxHeight(60.h),
                                        // Image.asset(
                                        //   'assets/images/png/Group 1000003722.png',
                                        //   height: 100.h,
                                        // ),
                                        // sizedBoxHeight(25.h),
                                        text22W600('Confirm Delete'),
                                        sizedBoxHeight(30.h),
                                        text20W400_center(
                                            'Are you sure you want to delete your account?'),
                                        sizedBoxHeight(50.h),
                                        CommonYesNoBtn(
                                          yesonTap: () async {
                                            utils.loader();

                                            var resp = await DeleteAccountAPI()
                                                .deleteAcountApi();
                                            print(resp.status);
                                            print('Api msg : ${resp.message}');

                                            if (resp.status ==
                                                ResponseStatus.SUCCESS) {
                                              Get.back();
                                              print(
                                                  "api response is ${resp.data}");
                                              Utils.showToast(
                                                  "Account deleted successfully");

                                              Map<String, dynamic> res =
                                                  resp.data;
                                              print(res);

                                              Get.offNamed(
                                                RouteName.loginscreen,
                                              );
                                            } else {
                                              Get.back();
                                              Utils.showToast(resp.message);
                                              print(
                                                  'Api msg : ${resp.message}');
                                            }
                                          },
                                          noonTap: () {
                                            Get.back();
                                          },
                                        ),
                                      ],
                                    ),
                                  ),
                                ),
                              ),
                              backgroundColor: Colors.black.withOpacity(0.3),
                            );
                          },
                        ),
                        SizedBox(
                          width: 15.w,
                        ),
                        InkWell(
                          child: text20W400("Delete Account"),
                          onTap: () {
                            Get.bottomSheet(
                              commonGlassContainer(
                                width: double.infinity,
                                height: 363.h,
                                borderradius: 4,
                                customWidget: Center(
                                  child: Padding(
                                    padding:
                                        EdgeInsets.symmetric(horizontal: 20.w),
                                    child: Column(
                                      children: [
                                        sizedBoxHeight(60.h),
                                        // Image.asset(
                                        //   'assets/images/png/Group 1000003722.png',
                                        //   height: 100.h,
                                        // ),
                                        // sizedBoxHeight(25.h),
                                        text22W600('Confirm Delete'),
                                        sizedBoxHeight(30.h),
                                        text20W400_center(
                                            'Are you sure you want to delete your account?'),
                                        sizedBoxHeight(50.h),
                                        CommonYesNoBtn(
                                          yesonTap: () async {
                                            utils.loader();

                                            var resp = await DeleteAccountAPI()
                                                .deleteAcountApi();
                                            print(resp.status);
                                            print('Api msg : ${resp.message}');

                                            if (resp.status ==
                                                ResponseStatus.SUCCESS) {
                                              Get.back();
                                              print(
                                                  "api response is ${resp.data}");
                                              Utils.showToast(
                                                  "Account deleted successfully");

                                              Map<String, dynamic> res =
                                                  resp.data;
                                              print(res);

                                              Get.offNamed(
                                                RouteName.loginscreen,
                                              );
                                            } else {
                                              Get.back();
                                              Utils.showToast(resp.message);
                                              print(
                                                  'Api msg : ${resp.message}');
                                            }
                                          },
                                          noonTap: () {
                                            Get.back();
                                          },
                                        ),
                                      ],
                                    ),
                                  ),
                                ),
                              ),
                              backgroundColor: Colors.black.withOpacity(0.3),
                            );
                          },
                        )
                      ],
                    ),
                  ],
                ),
              ),
            ],
          ),
        ],
      ),
    );
  }
}

Deletedialog(context) {
  return showDialog(
    // barrierDismissible: false,
    context: context,
    builder: (context) => Column(
      mainAxisAlignment: MainAxisAlignment.center,
      children: [
        AlertDialog(
          insetPadding: EdgeInsets.symmetric(horizontal: 16.w),
          backgroundColor:
              Get.isDarkMode ? Colors.black : const Color(0XFF1B243D),
          contentPadding: EdgeInsets.fromLTRB(29.w, 44.h, 29.w, 35.h),
          shape: RoundedRectangleBorder(
            borderRadius: BorderRadius.all(Radius.circular(5.r)),
          ),
          content: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            crossAxisAlignment: CrossAxisAlignment.center,
            children: [
              Container(
                height: 87.h,
                width: 80.w,
                decoration: const BoxDecoration(
                    shape: BoxShape.circle, color: Color(0xFFC18948)),
                child: Align(
                  alignment: Alignment.topLeft,
                  child: Container(
                    height: 79.h,
                    width: 73.w,
                    decoration: BoxDecoration(
                      shape: BoxShape.circle,
                      color: const Color(0xFFE8C69F).withOpacity(0.5),
                    ),
                    child: Center(
                      child: SvgPicture.asset(
                        'assets/images/svg/apps 1.svg',
                        // fit: BoxFit.fill,
                      ),
                    ),
                  ),
                ),
              ),
              sizedBoxHeight(30.h),
              Text(
                "Are you sure you want to logout ?",
                textAlign: TextAlign.center,
                style: TextStyle(
                    fontFamily: "hiragino",
                    fontWeight: FontWeight.w400,
                    fontSize: 20.sp,
                    color: const Color(0xFFFFFFFF)),
              ),
              sizedBoxHeight(40.h),
              Row(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                children: [
                  SizedBox(
                      width: 140.w,
                      child: CommonYesNoBtn(
                        yesonTap: () async {
                          SharedPreferences prefs =
                              await SharedPreferences.getInstance();
                          await prefs.clear();
                          Get.offNamed(RouteName.loginscreen);
                        },
                      )),
                  SizedBox(
                    width: 140.w,
                    child: CommonYesNoBtn(
                      noonTap: () {
                        Get.back();
                      },
                    ),
                  ),
                ],
              )
            ],
          ),
        ),
      ],
    ),
  );
}
