import SwiftUI

/// Device-local Projects-tab preferences: the sort order and the names the
/// user has declared via "+" before any note was filed into them. Declared
/// names are deliberately NOT synced — a project becomes part of the synced
/// data the moment a note carries it; until then it is scaffolding that only
/// this device knows about.
enum ProjectsPrefs {
    static let declaredKey = "declaredProjects"
    static let sortKey = "projectsSort"

    /// Newline-joined storage — names are single-line (the creation alert's
    /// text field can't produce newlines) so this stays trivially inspectable.
    static func decodeDeclared(_ raw: String) -> [String] {
        raw.split(separator: "\n").map(String.init)
    }

    static func encodeDeclared(_ names: [String]) -> String {
        names.joined(separator: "\n")
    }
}

/// Sort orders for the project list.
enum ProjectsSort: String, CaseIterable, Identifiable {
    case activity
    case name
    case count

    var id: String { rawValue }

    var label: String {
        switch self {
        case .activity: "Recent Activity"
        case .name: "Name"
        case .count: "Note Count"
        }
    }
}
