import 'package:checker/base/base_state.dart';
import 'package:checker/consts.dart';
import 'package:checker/db.dart';
import 'package:checker/strings.dart';
import 'package:flutter/material.dart';

abstract class SettingsBaseState<T extends StatefulWidget> extends BaseState<T> {

  SettingsBaseState(SqliteHelper helper, String app) {
    this.helper = helper;
    this.app = app;
  }

  int selectedItem;

  @override Widget build(BuildContext context) {
    return new Scaffold(appBar: getAppBar(),
        body: getScreenContent());
  }

  @override
  Widget getScreenContent() {
    getSelectedValue();
    List<Widget> widgets = new List();

    for (String option in getOptions()) {
      widgets.add(getItem(option));
    }

    return new ListView(children: widgets);
  }

  List<String> getOptions();

  void saveOption();

  void getSelectedValue();

  @override
  List<Widget> getMenuButtons() {
    return null;
  }

  Widget getItem(String option) {
    return new Container(
        height: 56.0,
        child: (new FlatButton(onPressed: () {
          saveOption();
          setState(() {
            selectedItem = getOptions().indexOf(option);
          });
        },
            child: new Row(children: <Widget>[
              new Expanded(child: new Text(option)),
              getCheckMark(getOptions().indexOf(option))]))));
  }

  Widget getCheckMark(int index) {
    return index == selectedItem ? new Image.asset(check_png,
        width: 28.0,
        height: 28.0) : new Image.asset(check_png, color: new Color(0xffffff));
  }

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