import 'package:get/get.dart';
import '../../../../app.dart';

class LanguageController extends GetxController {
  List<LanguageModel> languages = [...LocalizationService.langs];

  RxInt groupValue = 1.obs;

  @override
  void onInit() {
    getCurrentLocale();
    super.onInit();
  }

  void onChangeLanguage(LanguageModel newValue) {
    groupValue.value = newValue.id;
    LocalizationService().changeLocale(newValue.code);
    setLocale(newValue.code);

    resetLocaleSavedData();
  }

  Future<void> getCurrentLocale() async {
    final locale = await getLocale();
    groupValue.value = locale == 'tm' ? 1 : 2;
  }

  Future<void> resetLocaleSavedData() async {
    await Get.delete<SettingsController>();

    SliderApi.sliders.clear();
    CategoryApi.categories.clear();
    CategoryApi.clearCategories();
  }
}
