import Foundation

final class NavigationSettings: ObservableObject {

    /// The items to show in the navigation bar
    @Published
    var navigationItems: [Item]

    @Published
    var german: LocalizedNavigationSettings

    @Published
    var english: LocalizedNavigationSettings

    init(navigationItems: [Item],
         german: LocalizedNavigationSettings,
         english: LocalizedNavigationSettings) {
        self.navigationItems = navigationItems
        self.german = german
        self.english = english
    }

    init(file: NavigationSettingsFile, map: (String) -> Item?) {
        self.navigationItems = file.navigationItems.compactMap(map)
        self.german = LocalizedNavigationSettings(file: file.german)
        self.english = LocalizedNavigationSettings(file: file.english)
    }

    var file: NavigationSettingsFile {
        .init(
            navigationItems: navigationItems.map { $0.itemType.id },
            german: german.file,
            english: english.file)
    }
}

extension NavigationSettings: LocalizedItem {
    
}

extension NavigationSettings {

    static var `default`: NavigationSettings {
        .init(navigationItems: [],
              german: .default,
              english: .default)
    }
}
