//
//  DaysFilterClass.swift
//  Feels
//
//  Created by Trey Tartt on 3/31/22.
//

import SwiftUI

class DaysFilterClass: ObservableObject {
    static let shared = DaysFilterClass()
    
    @Published public var currentFilters = [Int]()
    
    init() {
        let storedDays = UserDefaultsStore.getDaysFilter()
        currentFilters = storedDays
    }
    
    func addFilter(newFilter: Int) {
        currentFilters.append(newFilter)
        currentFilters = UserDefaultsStore.saveDaysFilter(days: currentFilters)
    }
    
    func removeFilter(filter: Int) {
        if let index = currentFilters.firstIndex(of: filter) {
            currentFilters.remove(at: index)
        }
        currentFilters = UserDefaultsStore.saveDaysFilter(days: currentFilters)
    }
}
