import SwiftUI
import ComponentLibrary

struct PresetCard: View {
    let text: String
    let action: () -> Void

    var body: some View {
        Button(action: action) {
            Text(text)
                .figmaMCPTypography(TypographyV1.FigmaMCP.small)
                .foregroundColor(ChatConstants.Colors.Foreground.tertiary)
                .tracking(0.28)
                .lineLimit(2)
                .multilineTextAlignment(.leading)
                .frame(width: 150, height: 74, alignment: .leading)
                .padding(.horizontal, 12)
                .glassBackground(
                    shape: .rect(cornerRadius: 20),
                    type: .regular,
                    fallbackStyle: ChatConstants.Colors.Background.Glass.thin,
                    interactive: true
                )
        }
        .buttonStyle(PlainButtonStyle())
    }
}

struct PresetsScroller: View {
    let onPresetTap: (String) -> Void
    let bottomPadding: CGFloat // Dynamic padding based on sheet height

    private let presets = [
        "Make a song about the beach",
        "Create a love ballad",
        "Write a rap about success",
        "Make an upbeat pop song",
        "Create a sad piano piece",
        "Write a rock anthem",
        "Make a chill lofi track"
    ]

    var body: some View {
        ScrollView(.horizontal, showsIndicators: false) {
            HStack(spacing: 8) {
                ForEach(presets, id: \.self) { preset in
                    PresetCard(text: preset) {
                        onPresetTap(preset)
                    }
                }
            }
            .padding(.horizontal, 16)
            .padding(.vertical, 8)
        }
        .padding(.bottom, bottomPadding)
    }
}

#Preview {
    VStack {
        Spacer()
        PresetsScroller(
            onPresetTap: { preset in
                print("Tapped: \(preset)")
            },
            bottomPadding: 100
        )
    }
    .background(ChatConstants.Colors.Background.primary)
}

