import SwiftUI

public extension View {
    /// Applies a presentation corner radius conditionally, depending on iOS version and a runtime flag.
    /// - Parameters:
    ///   - radius: The corner radius to apply on older systems.
    ///   - conditional: When true and running on iOS 26 or newer, skips applying the modifier.
    @ViewBuilder
    func presentationCornerRadius(_ radius: CGFloat, conditional: Bool) -> some View {
        if #available(iOS 26.0, *), conditional {
            // On iOS 26+, if `conditional` is true, do nothing (likely handled by new system defaults)
            self
        } else {
            // Otherwise, manually apply the presentation corner radius
            self.presentationCornerRadius(radius)
        }
    }

    /// Applies a presentation background conditionally, depending on iOS version and a runtime flag.
    /// - Parameters:
    ///   - style: The background style to apply on older systems.
    ///   - conditional: When true and running on iOS 26 or newer, skips applying the modifier.
    @ViewBuilder
    func presentationBackground<S: ShapeStyle>(_ style: S, conditional: Bool) -> some View {
        if #available(iOS 26.0, *), conditional {
            // On iOS 26+, if `conditional` is true, do nothing (new API or behavior may exist)
            self
        } else {
            // Otherwise, apply the background manually
            self.presentationBackground(style)
        }
    }

    /// Sets a navigation bar background color, with backward compatibility for older iOS versions.
    /// - Parameter color: The color to use for the navigation bar background.
    @ViewBuilder
    func navigationBarBackground(_ color: Color) -> some View {
        if #available(iOS 26.0, *) {
            // On iOS 26+, assume system manages the navigation bar background natively
            self
        } else {
            // For older iOS versions, use the toolbarBackground modifier to style the navigation bar
            self.toolbarBackground(color, for: .navigationBar)
        }
    }
}
