import SwiftUI

struct SuggestionsList: View {
    let onSuggestionTap: (String) -> Void
    let onShuffleTap: () -> Void

    @State private var currentSuggestions: [String] = []

    private let allSuggestions = [
        "Make a lofi hip-hop song",
        "Turn my lyrics into a song",
        "Create my personal anthem",
        "Write a roast song about my favorite thing",
        "Turn my feelings into a song",
        "Surprise me with a song in a random genre",
        "Make me a new workout anthem song",
        "Create a birthday song for my best friend",
        "Make a chill study music track",
        "Write a song about my morning routine"
    ]

    var body: some View {
        VStack(alignment: .leading, spacing: 8) {
            // Title
            Text("Suggestions")
                .font(.custom("PP Neue Montreal", size: 18).weight(.medium))
                .foregroundColor(.white)
                .tracking(0.36)
                .frame(maxWidth: .infinity, alignment: .leading)

            // Suggestions list
            VStack(spacing: 0) {
                ForEach(Array(currentSuggestions.enumerated()), id: \.offset) { index, suggestion in
                    Button(action: {
                        onSuggestionTap(suggestion)
                    }) {
                        HStack(spacing: 4) {
                            Text(suggestion)
                                .font(.custom("PP Neue Montreal", size: 14))
                                .foregroundColor(Constants.Colors.Foreground.inactive)
                                .tracking(0.28)
                                .frame(maxWidth: .infinity, alignment: .leading)

                            // Show shuffle icon only on first suggestion
                            if index == 0 {
                                Button(action: {
                                    shuffleSuggestions()
                                    onShuffleTap()
                                }) {
                                    Image("Icon/rotate-reverse")
                                        .resizable()
                                        .frame(width: 20, height: 20)
                                        .foregroundColor(Constants.Colors.Foreground.inactive)
                                }
                                .buttonStyle(PlainButtonStyle())
                            }
                        }
                        .padding(.vertical, 12)
                    }
                    .buttonStyle(PlainButtonStyle())
                }
            }
        }
        .onAppear {
            shuffleSuggestions()
        }
    }

    private func shuffleSuggestions() {
        // Show 7 random suggestions
        currentSuggestions = Array(allSuggestions.shuffled().prefix(7))
    }
}

#Preview {
    SuggestionsList(
        onSuggestionTap: { suggestion in
            print("Tapped: \(suggestion)")
        },
        onShuffleTap: {
            print("Shuffle tapped")
        }
    )
    .padding()
    .background(Constants.Colors.Background.primary)
}
