import 'package:auto_route/auto_route.dart';
              import 'package:flutter/material.dart';
              import 'package:flutter_bloc/flutter_bloc.dart';
              import 'package:krow/app.dart';
              import 'package:krow/core/application/routing/routes.gr.dart';
              import 'package:krow/core/presentation/gen/assets.gen.dart';
              import 'package:krow/core/presentation/styles/kw_box_decorations.dart';
              import 'package:krow/core/presentation/styles/kw_text_styles.dart';
              import 'package:krow/core/presentation/styles/theme.dart';
              import 'package:krow/core/presentation/widgets/scroll_layout_helper.dart';
              import 'package:krow/core/presentation/widgets/ui_kit/dialogs/kw_dialog.dart';
              import 'package:krow/core/presentation/widgets/ui_kit/kw_app_bar.dart';
              import 'package:easy_localization/easy_localization.dart';
              import 'package:krow/features/profile/profile_settings/domain/bloc/profile_settings_bloc.dart';
              import 'package:krow/features/profile/profile_settings/domain/bloc/profile_settings_event.dart';
              import 'package:krow/features/profile/profile_settings/domain/bloc/profile_settings_state.dart';

              @RoutePage()
              class ProfileSettingsMenuScreen extends StatelessWidget {
                const ProfileSettingsMenuScreen({super.key});

                @override
                Widget build(BuildContext context) {
                  return BlocListener<ProfileSettingsBloc, ProfileSettingsState>(
                    listener: (context, state) {
                      if (state.isAccRemoved) {
                        appRouter.replace(const SplashRoute());
                      }
                    },
                    child: Scaffold(
                      appBar: KwAppBar(
                        titleText: 'profile_settings'.tr(),
                        showNotification: true,
                      ),
                      body: ScrollLayoutHelper(
                          padding: const EdgeInsets.all(16),
                          upperWidget: Column(
                            crossAxisAlignment: CrossAxisAlignment.start,
                            children: [
                              Text(
                                'personal_info'.tr(),
                                style: AppTextStyles.captionReg
                                    .copyWith(color: AppColors.blackCaptionGreen),
                              ),
                              _buildMenuItem(
                                context: context,
                                title: 'roles'.tr(),
                                rout: RoleRoute(),
                              ),
                              _buildMenuItem(
                                  context: context,
                                  title: 'personal_info'.tr(),
                                  rout: PersonalInfoRoute(isInEditMode: true)),
                              _buildMenuItem(
                                context: context,
                                title: 'address'.tr(),
                                rout: AddressRoute(),
                              ),
                              _buildMenuItem(
                                context: context,
                                title: 'emergency_contact'.tr(),
                                rout: EmergencyContactsRoute(),
                              ),
                              _buildMenuItem(
                                context: context,
                                title: 'mobility'.tr(),
                                rout: MobilityRoute(),
                              ),
                              _buildMenuItem(
                                context: context,
                                title: 'inclusive'.tr(),
                                rout: InclusiveRoute(),
                              ),
                            ],
                          ),
                          lowerWidget: _buildRemoveAccountButton(context)),
                    ),
                  );
                }

                _buildRemoveAccountButton(BuildContext context) {
                  return Container(
                    margin: const EdgeInsets.only(top: 8),
                    height: 56,
                    decoration: KwBoxDecorations.primaryLight8,
                    child: Material(
                      type: MaterialType.transparency,
                      child: InkWell(
                        onTap: () {
                          _showDeleteAccDialog(context);
                        },
                        child: Padding(
                          padding: const EdgeInsets.symmetric(horizontal: 12),
                          child: Row(
                            children: [
                              Text(
                                'remove_my_account'.tr(),
                                style: AppTextStyles.headingH3
                                    .copyWith(color: AppColors.statusError),
                              ),
                            ],
                          ),
                        ),
                      ),
                    ),
                  );
                }

                _buildMenuItem(
                    {required BuildContext context, required String title, required rout}) {
                  return Container(
                    margin: const EdgeInsets.only(top: 8),
                    height: 56,
                    decoration: KwBoxDecorations.primaryLight8,
                    child: Material(
                      type: MaterialType.transparency,
                      child: InkWell(
                        onTap: () {
                          AutoRouter.of(context).push(rout);
                        },
                        child: Padding(
                          padding: const EdgeInsets.symmetric(horizontal: 12),
                          child: Row(
                            crossAxisAlignment: CrossAxisAlignment.center,
                            mainAxisAlignment: MainAxisAlignment.spaceBetween,
                            children: [
                              Expanded(
                                child: Text(
                                  title,
                                  style: AppTextStyles.headingH3,
                                ),
                              ),
                              Assets.images.icons.caretRight.svg(height: 24, width: 24)
                            ],
                          ),
                        ),
                      ),
                    ),
                  );
                }

                void _showDeleteAccDialog(BuildContext context) {
                  KwDialog.show(
                      context: context,
                      icon: Assets.images.icons.alertTriangle,
                      state: KwDialogState.negative,
                      title: 'are_you_sure_delete_account'.tr(),
                      message: 'delete_account_warning'.tr(),
                      primaryButtonLabel: 'delete_account'.tr(),
                      secondaryButtonLabel: 'cancel'.tr(),
                      onPrimaryButtonPressed: (dialogContext) {
                        Navigator.pop(dialogContext);
                        BlocProvider.of<ProfileSettingsBloc>(context)
                            .add(ProfileSettingsRemoveAccEvent());
                      });
                }
              }