2026-09-19 17:07:44 +02:00
|
|
|
import Foundation
|
|
|
|
|
import Combine
|
|
|
|
|
import MyPassCore
|
|
|
|
|
|
|
|
|
|
@MainActor
|
|
|
|
|
final class GroupFilterViewModel: ObservableObject {
|
|
|
|
|
@Published var selectedGroupIds: Set<UUID> = []
|
2026-09-19 17:25:06 +02:00
|
|
|
/// The group id passed to the most recent `toggle(_:)` call that resulted in a non-empty
|
|
|
|
|
/// selection, used as a "best effort" default group for new entries. Cleared to `nil`
|
|
|
|
|
/// whenever a toggle empties the selection, or by `clear()`.
|
|
|
|
|
@Published private(set) var lastToggledGroupId: UUID?
|
2026-09-19 17:07:44 +02:00
|
|
|
|
|
|
|
|
private let session: VaultSession
|
|
|
|
|
|
|
|
|
|
init(session: VaultSession) {
|
|
|
|
|
self.session = session
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func isSelected(_ group: MyPassCore.Group) -> Bool {
|
|
|
|
|
selectedGroupIds.contains(group.id)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func toggle(_ group: MyPassCore.Group) {
|
|
|
|
|
guard let root = session.database?.root else { return }
|
|
|
|
|
selectedGroupIds = GroupSelection.toggling(group.id, in: root, current: selectedGroupIds)
|
2026-09-19 17:25:06 +02:00
|
|
|
lastToggledGroupId = selectedGroupIds.isEmpty ? nil : group.id
|
2026-09-19 17:07:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func clear() {
|
|
|
|
|
selectedGroupIds = []
|
2026-09-19 17:25:06 +02:00
|
|
|
lastToggledGroupId = nil
|
2026-09-19 17:07:44 +02:00
|
|
|
}
|
|
|
|
|
}
|