//
//  NavigationCompatibility.swift
//  suixinkan
//
//  Created by Codex on 2026/6/26.
//

import SwiftUI

extension View {
    /// iOS 16 compatible replacement for iOS 17's navigationDestination(item:).
    func appNavigationDestination<Item, Destination: View>(
        item: Binding<Item?>,
        @ViewBuilder destination: @escaping (Item) -> Destination
    ) -> some View {
        navigationDestination(
            isPresented: Binding(
                get: { item.wrappedValue != nil },
                set: { isPresented in
                    if !isPresented {
                        item.wrappedValue = nil
                    }
                }
            )
        ) {
            if let value = item.wrappedValue {
                destination(value)
            }
        }
    }
}
