import SwiftUI

struct BannerView: View {
    var banner: Banner
        
    var body: some View {
        ZStack(alignment: .center) {
            backgroundView
            
            if !banner.hideShade {
                ColorName.bannerShade.color
            }
            
            VStack {
                if let logo = banner.logo {
                    URLImage(url: logo, contentMode: .fit, fallbackColor: .clear)
                        .frame(height: 70)
                }
                
                if let heading = banner.heading {
                    Text(heading)
                        .textStyle(.headline, color: ColorName.textOnTint.color)
                        .multilineTextAlignment(.center)
                }
                
                if let subheading = banner.subheading {
                    Text(subheading)
                        .textStyle(.subheadline, color: ColorName.textOnTint.color)
                        .multilineTextAlignment(.center)
                }
            }
            .padding()
        }
        .clipped()
        .background(ColorName.background.color)
    }
    
    @ViewBuilder var backgroundView: some View {
        if let url = banner.banner {
            URLImage(url: url)
        } else {
            ColorName.tint.color
        }
        
    }
}
