import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:kmobile/features/auth/controllers/theme_mode_cubit.dart';
import '../../../l10n/app_localizations.dart';

String _getThemeModeText(ThemeMode mode, AppLocalizations l10n) {
  switch (mode) {
    case ThemeMode.system:
      return l10n.themeModeSystem;
    case ThemeMode.light:
      return l10n.themeModeLight;
    case ThemeMode.dark:
      return l10n.themeModeDark;
  }
}

Future<void> showThemeModeDialog(BuildContext context) async {
  final cubit = context.read<ThemeModeCubit>();
  final currentMode = context.read<ThemeModeCubit>().state.mode;
  final l10n = AppLocalizations.of(context);

  await showDialog(
    context: context,
    builder: (context) {
      return AlertDialog(
        title: Text(l10n.selectThemeMode),
        content: Column(
          mainAxisSize: MainAxisSize.min,
          children: ThemeMode.values.map((mode) {
            return RadioListTile<ThemeMode>(
              title: Text(_getThemeModeText(mode, l10n)),
              value: mode,
              groupValue: currentMode,
              onChanged: (value) {
                if (value != null) {
                  cubit.changeThemeMode(value);
                  Navigator.pop(context);
                }
              },
            );
          }).toList(),
        ),
      );
    },
  );
}
