import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flux/core/enums_and_consts/enums.dart';
import 'package:flux/core/theme/theme.dart';
import 'package:flux/core/theme/bloc/theme_bloc.dart';

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

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: const Text('Impostazioni Tema')),
      body: BlocBuilder<ThemeBloc, ThemeState>(
        builder: (context, state) => RadioGroup<AppThemeMode>(
          groupValue: state.currentTheme,
          onChanged: (newTheme) {
            if (newTheme != null) {
              context.read<ThemeBloc>().add(ChangeThemeEvent(newTheme));
            }
          },
          child: Column(
            children: AppThemeMode.values.map((theme) {
              return RadioListTile<AppThemeMode>(
                title: Text(theme.label),
                secondary: Icon(theme.icon, color: context.accent),
                value: theme,
              );
            }).toList(),
          ),
        ),
      ),
    );
  }
}
