import 'dart:convert';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart' show rootBundle;
import 'package:english_words/english_words.dart';


const String filePath = '../assets/data.json';

class TindBookState extends ChangeNotifier {
    String input = "";
    var data;
    List<int> favorites = <int>[];

    void loadData() async {
        this.input = await rootBundle.loadString(filePath);
        this.data = jsonDecode(input)['books'];
        notifyListeners();
    }

    Map<String, dynamic> getFav(int index) {
        return this.data[this.favorites[index]];
    }

    void addDataToFav(Map<String, dynamic> obj){
        favorites.add(this.data.indexOf(obj));
        notifyListeners();
    }

    void addIndexToFav(int index) {
        if (! favorites.contains(index)){
            favorites.add(index);
            notifyListeners();
        }
    }
}
