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

import '../../../application/auth/logout/logout_bloc.dart';
import '../../../common/theme/theme.dart';
import '../button/button.dart';
import '../spaces/space.dart';
import 'dialog.dart';

class LogoutModalDialog extends StatelessWidget {
  const LogoutModalDialog({super.key});

  @override
  Widget build(BuildContext context) {
    return BlocBuilder<LogoutBloc, LogoutState>(
      builder: (context, state) {
        return CustomModalDialog(
          title: 'Konfirmasi',
          contentPadding: const EdgeInsets.all(16),
          bottom: Padding(
            padding: const EdgeInsets.all(16),
            child: Row(
              children: [
                Expanded(
                  child: AppElevatedButton.outlined(
                    onPressed: () => context.maybePop(),
                    label: 'Batal',
                  ),
                ),
                const SpaceWidth(12),
                Expanded(
                  child: AppElevatedButton.filled(
                    onPressed: state.isLoggingOut
                        ? null
                        : () {
                            context.read<LogoutBloc>().add(
                              const LogoutEvent.logout(),
                            );
                            context.maybePop();
                          },
                    label: 'Ya',
                    isLoading: state.isLoggingOut,
                  ),
                ),
              ],
            ),
          ),
          child: Text(
            'Apakah anda yakin ingin keluar?',
            style: AppStyle.lg.copyWith(fontWeight: FontWeight.w600),
          ),
        );
      },
    );
  }
}
