import 'package:flutter/material.dart';
import 'package:flutter_native_splash/flutter_native_splash.dart';
import 'package:get/get.dart';
import 'package:shared_preferences/shared_preferences.dart';

import '../../app.dart';

class LangSplashController extends GetxController {
  RxBool isTurkmen = true.obs;

  @override
  void onInit() {
    FlutterNativeSplash.remove();

    super.onInit();
  }

  void onLangBtnTapped(isTurkmenSelected) {
    isTurkmen.value = isTurkmenSelected;
    final langCode = isTurkmen.value ? 'tm' : 'ru';

    LocalizationService().changeLocale(langCode);
    setLocale(langCode);
  }

  Future<void> onNextBtnTapped() async {
    debugPrint('onNextBtnTapped');
    SharedPreferences prefs = await SharedPreferences.getInstance();

    prefs.setBool(Constants.IS_SPLASH_SEEN, true);
    prefs.setBool(Constants.IS_SPLASH_REMOVED, true);

    Get.offAndToNamed(AppRoutes.DASHBOARD);
  }
}
