import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:traderscircuit/Utils/Common/CommonAppbar.dart';
import 'package:traderscircuit/Utils/Common/commonBotton.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/secureAccess.dart/SecureAccess.dart';
import 'package:traderscircuit/view/secureAccess.dart/faceIdScreen.dart';
import 'package:traderscircuit/view_model/Login/secure_access_api.dart';

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

  @override
  State<Faceid> createState() => _FaceidState();
}

class _FaceidState extends State<Faceid> {
  Color primaryColor = Colors.transparent.withOpacity(0.2);
  Color secondaryColor = Colors.grey.shade800;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: CommonAppbar(
        titleTxt: "Secure your access",
        //    customActionWidget: SizedBox(),
      ),
      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: [
                    text18W400("Quickly set up Face ID for secure access."),
                    SizedBox(
                      height: 180.h,
                    ),
                    Row(
                      mainAxisAlignment: MainAxisAlignment.center,
                      children: [
                        Image.asset("assets/images/png/face-id.png"),
                      ],
                    ),
                    SizedBox(
                      height: 180.h,
                    ),
                    CommonBtn(
                      text: "Setup",
                      onTap: () async {
                        bool result = await LocalAuth.authenticate();
                        //  Get.toNamed(RouteName.adddetails);
                        if (result) {
                          Utils.loader();
                          Map<String, dynamic> updata = {};
                          final resp =
                              await SecureAccessAPI(updata).secureaccessApi();
                          if (resp.status == ResponseStatus.SUCCESS) {
                            Get.back();
                            Get.toNamed(RouteName.adddetails);
                          } else if (resp.status == ResponseStatus.PRIVATE) {
                            Get.back();
                            String? message = resp.data['message'];
                            Utils.showToast("$message");
                          } else if (resp.status == ResponseStatus.ERROR) {
                            Get.back();
                            String? message = resp.data['message'];
                            Utils.showToast("$message");
                          } else {
                            Get.back();
                            String? message = resp.data['message'];
                            Utils.showToast("$message");
                          }
                        } else {
                          Utils.showToast("Setting FaceID Failed!");
                        }

                        // if (result) {
                        //   Get.toNamed(RouteName.adddetails);
                        // } else {
                        //   Utils.showToast("msg");
                        // }
                      },
                    )
                  ],
                ),
              ),
            ],
          ),
        ],
      ),
    );
  }
}
