import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:tanami_app/core/styles/app_color.dart';
import 'package:tanami_app/core/styles/app_text.dart';
import 'package:tanami_app/shared/components/text_widget.dart';

import '../bloc/choose_language_bloc.dart';
import '../bloc/choose_language_event.dart';
import '../bloc/choose_language_state.dart';

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

  @override
  Widget build(BuildContext context) {
    final radioBloc = context.read<ChooseLanguageBloc>();
    return BlocBuilder<ChooseLanguageBloc, ChooseLanguageState>(
      builder: (context, state) {
        int selectedIndex = 0;
        if (state is ChooseLanguageSelectionChanged) {
          selectedIndex = state.selectedIndex;
        }

        return Column(
          children: List<Widget>.generate(languageList.length, (int index) {
            return Row(
              children: [
                Radio<int>(
                  activeColor: AppColor.radioActiveColor,
                  value: index,
                  groupValue: selectedIndex,
                  onChanged: (int? value) {
                    if (value != null) {
                      radioBloc.add(ChooseLanguageSelected(value));
                    }
                  },
                ),
                TextWidget().text14W500(languageList[index],
                    clr: AppColor.charcoalColor),
              ],
            );
          }),
        );
      },
    );
  }
}

List<String> languageList = [
  AppText.englishText,
  AppText.arabicText,
];
