import Foundation
import SwiftUI
import Combine

@MainActor
class VODLibraryViewModel: ObservableObject {
    @Published var selectedCategory: String? = nil
    @Published var searchText: String = ""

    func filteredVODItems(from playlist: Playlist?) -> [VODItem] {
        guard let playlist = playlist else { return [] }

        var items = playlist.vodItems

        if let selectedCategory = selectedCategory {
            items = items.filter { $0.categoryID == selectedCategory }
        }

        if !searchText.isEmpty {
            items = items.filter { $0.name.localizedCaseInsensitiveContains(searchText) }
        }

        return items
    }

    func clearFilters() {
        selectedCategory = nil
        searchText = ""
    }
}
