import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';

import '../../../../core/styles/app_color.dart';
import '../../../../core/styles/app_text.dart';
import '../../../../core/utils/secure/secure_storage_service.dart';
import '../../../../shared/components/appbar_widget.dart';
import '../../../../shared/components/exit_app_dialog.dart';
import '../bloc/pin_bloc.dart';
import 'pin_layout.dart';

class PinScreen extends StatelessWidget {
  final String fromScreen;
  const PinScreen({super.key, required this.fromScreen});

  @override
  Widget build(BuildContext context) {
    final secureStorageService = SecureStorageService();
    return WillPopScope(
      onWillPop: () async {
        if (fromScreen == "LoginedInUser") {
          exitAppDialog(context);
          return false;
        } else {
          return true;
        }
      },
      child: Scaffold(
        backgroundColor: AppColor.plainWhite,
        appBar: fromScreen == "register" || fromScreen == "reset-pin"
            ? AppBarWidget(
                height: 75,
                titleTxt: fromScreen == "reset-pin"
                    ? AppText.changePinCode
                    : AppText.createPinCode,
                showLeading: fromScreen == "reset-pin" ? true : false,
              )
            : null,
        resizeToAvoidBottomInset: true,
        body: MultiBlocProvider(
          providers: [
            BlocProvider(
              // Create an instance of the OnboardingBloc
              create: (context) =>
                  PinBloc(secureStorageService: secureStorageService),
            ),
          ],
          child: PinLayout(
            fromScreen: fromScreen,
          ),
        ),
      ),
    );
  }
}
