import Foundation
import SwiftUI

public extension View {
    /// Sets content in a ZStack on a fixed height and horizontal padding.
    /// Accepts optional leading, center, and trailing views that will be automatically aligned.
    ///
    /// Example:
    /// ```swift
    /// Text("Content")
    ///     .sheetNavigationBar(
    ///         center: ToolbarTitle("Title"),
    ///         trailing: ToolbarButton(.close) { }
    ///     )
    /// ```
    func sheetNavigationBar<Leading: View, Center: View, Trailing: View>(
        @ViewBuilder leading: () -> Leading? = { nil },
        @ViewBuilder center: () -> Center? = { nil },
        @ViewBuilder trailing: () -> Trailing? = { nil },
        type: SheetTypeHeight = .default
    ) -> some View {
        VStack(spacing: 0) {
            ZStack {
                if let center = center() { // Center takes priority
                    center
                        .frame(maxWidth: .infinity, alignment: .center)
                }
                if let leading = leading() {
                    leading
                        .frame(maxWidth: .infinity, alignment: .leading)
                }
                if let trailing = trailing() {
                    trailing
                        .frame(maxWidth: .infinity, alignment: .trailing)
                }
            }
            .frame(height: type.height)
            .padding(.horizontal, 24)
            self
        }
    }
}

public enum SheetTypeHeight {
    case songActions
    case `default`

    var height: CGFloat {
        switch self {
        case .songActions:
            return 58
        case .default:
            return 85
        }
    }
}
