import 'package:checker/base/base_screen.dart';
import 'package:checker/base/settings_base_state.dart';
import 'package:checker/db.dart';
import 'package:flutter/material.dart';
import 'package:checker/strings.dart';
import 'package:checker/common.dart';

class LanguagesScreen extends BaseScreen {

  LanguagesScreen(helper, app) : super(helper, app);

  @override State createState() => new LanguagesState(helper, app);
}

class LanguagesState extends SettingsBaseState<LanguagesScreen> {

  LanguagesState(SqliteHelper helper, String app) : super(helper, app);

  List<String> languages = const ['ru', 'en', 'ua', 'es'];

  bool isAutomaticallyImplyLeading() => true;

  @override
  List<String> getOptions() {

    List<String> list = new List();

    for (String code in languages) {
      list.add(getLocaleTitle(code));
    }

    return list;
  }

  @override
  String getTitle() {
    return StringsLocalization.locale();
  }

  @override
  saveOption() async {
    await helper.saveLocale(languages[selectedItem]);
    await StringsLocalization.load(languages[selectedItem]);
  }

  @override
  void getSelectedValue() {
    setState(() {
      selectedItem = getOptions().indexOf(getLocaleTitle(StringsLocalization.localeCode));
    });
  }
}
