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

class CharacterProvider extends ChangeNotifier {
  List<String> _characters = [];

  List<String> get characters => _characters;
  String _currentAccessory = "Tanpa Aksesori";

  String get currentAccessory => _currentAccessory;

  CharacterProvider() {
    _loadCharacters();
  }

  void _loadCharacters() async {
    SharedPreferences prefs = await SharedPreferences.getInstance();
    _characters = prefs.getStringList("characters") ?? [];
    notifyListeners();
  }

  void addCharacter(String characterName) async {
    if (!_characters.contains(characterName)) {
      _characters.add(characterName);
      SharedPreferences prefs = await SharedPreferences.getInstance();
      await prefs.setStringList("characters", _characters);
      notifyListeners();
    }
  }

  void removeCharacter(String characterName) async {
    _characters.remove(characterName);
    SharedPreferences prefs = await SharedPreferences.getInstance();
    await prefs.setStringList("characters", _characters);
    notifyListeners();
  }

  void applyAccessory(String accessory) {
    _currentAccessory = accessory;
    notifyListeners();
  }
}
