import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:gap/gap.dart';
import 'package:tanami_app/core/styles/app_color.dart';
import 'package:tanami_app/core/styles/app_text.dart';
import 'package:tanami_app/core/utils/secure/secure_storage_service.dart';
import 'package:tanami_app/features/biometric/bloc/biometric_bloc.dart';

import '../../Globalconst.dart';
import '../../core/routes/route_name.dart';
import '../../core/routes/routes.dart';
import '../../core/utils/language/localizations_delegate.dart';
import '../../features/biometric/bloc/biometric_state.dart';
import 'text_widget.dart';

deviceLockedDialog(
  context,
) {
  var localizations = AppLocalizations.of(context);
  final SharedPreferenceLocalData secureStorageService =
      SharedPreferenceLocalData();
  return showDialog(
    barrierDismissible: false,
    context: context,
    builder: (context) => WillPopScope(
      onWillPop: () async {
        return false;
      },
      child: BlocBuilder<BiometricBloc, BiometricState>(
        builder: (context, state) {
          return Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: [
              AlertDialog(
                insetPadding: const EdgeInsets.symmetric(horizontal: 16),
                backgroundColor: AppColor.plainWhite,
                shape: const RoundedRectangleBorder(
                  borderRadius: BorderRadius.all(Radius.circular(20)),
                  side: BorderSide(
                    color: AppColor.plainWhite,
                  ),
                ),
                content: Column(
                  mainAxisAlignment: MainAxisAlignment.start,
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: [
                    const Align(
                      alignment: Alignment.center,
                      child: CircleAvatar(
                        radius: 25,
                        backgroundColor: AppColor.inactiveBtnColor,
                        child: Center(
                          child: Icon(
                            Icons.lock,
                            size: 25,
                            color: AppColor.primaryColor,
                          ),
                        ),
                      ),
                    ),
                    Gap(22.h),
                    Align(
                      alignment: Alignment.center,
                      child: Container(
                        margin: const EdgeInsets.symmetric(horizontal: 30),
                        child: TextWidget().text17W700(
                          localizations.translate(AppText.tanamiAppIsLocked),
                          clr: AppColor.textLabelColor,
                        ),
                      ),
                    ),
                    const Gap(5),
                    Align(
                      alignment: Alignment.centerLeft,
                      child: Container(
                        //  margin: const EdgeInsets.symmetric(horizontal: 30),
                        child: TextWidget().text14W400(
                          localizations.translate(AppText.securityMssgText),
                          clr: AppColor.textLabelColor,
                        ),
                      ),
                    ),
                    Gap(21.h),
                    Row(
                      mainAxisAlignment: MainAxisAlignment.spaceAround,
                      children: [
                        GestureDetector(
                          onTap: () {
                            SystemNavigator.pop();
                          },
                          child: Container(
                            height: 48.h,
                            width: 140.w,
                            decoration: BoxDecoration(
                              border: Border.all(
                                color: AppColor.primaryColor,
                              ),
                              borderRadius: BorderRadius.circular(10.h),
                              color: AppColor.plainWhite,
                            ),
                            child: Center(
                              child: TextWidget().text18W700(
                                localizations.translate(AppText.cancelText),
                                clr: AppColor.primaryColor2,
                              ),
                            ),
                          ),
                        ),
                        Gap(15.w),
                        GestureDetector(
                          onTap: () async {
                            // goRouter.pop();
                            // context
                            //     .read<BiometricBloc>()
                            //     .add(AuthenticateBiometricEvent());
                            Globalconst.firstName =
                                await secureStorageService.read("first_name") ??
                                    "";

                            goRouter
                                .goNamed(RouteName.pinScreen, pathParameters: {
                              "fromScreen": "LoginedInUser",
                            });
                          },
                          child: Container(
                            height: 48.h,
                            width: 140.w,
                            decoration: BoxDecoration(
                                borderRadius: BorderRadius.circular(10.h),
                                color: AppColor.primaryColor),
                            child: Center(
                              child: TextWidget().text18W700(
                                localizations.translate(AppText.unlockText),
                                clr: AppColor.plainWhite,
                              ),
                            ),
                          ),
                        ),
                      ],
                    ),
                  ],
                ),
              ),
            ],
          );
        },
      ),
    ),
  );
}
