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

class AccessoryProvider extends ChangeNotifier {
  List<String> _accessories = [];

  List<String> get accessories => _accessories;

  AccessoryProvider() {
    _loadAccessories();
  }

  void _loadAccessories() async {
    SharedPreferences prefs = await SharedPreferences.getInstance();
    _accessories = prefs.getStringList("accessories") ?? [];
    notifyListeners();
  }

  void addAccessory(String accessoryName) async {
    if (!_accessories.contains(accessoryName)) {
      _accessories.add(accessoryName);
      SharedPreferences prefs = await SharedPreferences.getInstance();
      await prefs.setStringList("accessories", _accessories);
      notifyListeners();
    }
  }

  void removeAccessory(String accessoryName) async {
    _accessories.remove(accessoryName);
    SharedPreferences prefs = await SharedPreferences.getInstance();
    await prefs.setStringList("accessories", _accessories);
    notifyListeners();
  }
}
