import SwiftUI

public struct ButtonAuraBackground: View {
    public enum AuraStyle {
        case pink
        case blue
        case orangeAura
    }

    let style: AuraStyle
    let withGradientOverlay: Bool
    let auraOffset: CGFloat

    public init(style: AuraStyle, withGradientOverlay: Bool, auraOffset: CGFloat = .zero) {
        self.style = style
        self.withGradientOverlay = withGradientOverlay
        self.auraOffset = auraOffset
    }

    public var body: some View {
        if withGradientOverlay {
            ZStack {
                LinearGradient(
                    gradient: Gradient(
                        colors: [
                            Color.black.opacity(.zero),
                            Color.black.opacity(style == .pink ? 0.5 : 0.8),
                        ]),
                    startPoint: .top,
                    endPoint: .bottom
                )
                .background {
                    auraBackground
                }
            }
        } else {
            auraBackground
        }
    }

    @ViewBuilder
    var auraBackground: some View {
        switch style {
        case .blue:
            Image.Assets.createButtonBackgroundBlue
                .resizable()
                .aspectRatio(contentMode: .fill)
                .offset(x: auraOffset)

        case .pink:
            Image.Assets.omniplayerBackground
                .resizable()
                .aspectRatio(contentMode: .fill)

        case .orangeAura:
            #if targetEnvironment(simulator)
                Color.orange
            #else
                AuraShaderView(
                    id: "welcome-screen",
                    appPreset: .pinkYellowOrange,
                    morphSpeed: 0.05,
                    scale: 0.4,
                    seed: 0
                )
            #endif
        }
    }
}
