import SwiftUI

struct TitledTextSection: View {
    
    @Environment(\.colorScheme)
    var colorScheme: ColorScheme

    let content: Titled<String>

    let titleSpacing: CGFloat

    let paragraphSpacing: CGFloat
    
    private var textColor: Color {
        colorScheme == .light ? .lightSchemePrimaryColor : .darkSchemePrimaryColor
    }
    
    var body: some View {
        TitledSection(title: content.title, spacing: titleSpacing) {
            ForEach(content.items) { text in
                Text(text)
                    .font(.body)
                    .fontWeight(.light)
                    .padding(.bottom, paragraphSpacing)
                    .foregroundColor(textColor)
            }
        }
    }
}

struct TitledTextSection_Previews: PreviewProvider {
    static var previews: some View {
        TitledTextSection(
            content: .init(
                title: "Title",
                items: ["Some longer or shorter text to explain some feature."]),
            titleSpacing: 10,
            paragraphSpacing: 5)
    }
}
