import 'package:fcs/localization/transalation.dart';
import 'package:fcs/helpers/shared_pref.dart';
import 'package:flutter/painting.dart';

import 'base_model.dart';

class LanguageModel extends BaseModel {
  String language;
  bool get isEng => this.language == "English";
  List<bool> get currentState => isEng ? [true, false] : [false, true];

  static final List<String> languageCodesList =
      Translation().supportedLanguagesCodes;
  static final List<String> languagesList = Translation().supportedLanguages;

  final Map<dynamic, dynamic> languagesMap = {
    languagesList[0]: languageCodesList[0],
    languagesList[1]: languageCodesList[1],
  };
  LanguageModel() {
    load();
  }
  @override
  logout() async {}

  Future<String> load() async {
    var data = await SharedPref.getLang();
    String result = languagesList[1]; // defalut to english
    if (data != null) {
      result = data;
    }
    this.language = result;
    Translation().onLocaleChanged(Locale(languagesMap[this.language]));
    notifyListeners();
    return result;
  }

  void saveLanguage(String language) async {
    Translation().onLocaleChanged(Locale(languagesMap[language]));

    SharedPref.saveLang(language);
    this.language = language;
    notifyListeners();
  }
}
