import SwiftUI

struct NoiseView: View {
    let player = NoisePlayer()
    let sounds = [
        Sound(name: "White Noise", fileName: "white-noise.mp3"),
        Sound(name: "Heavy Rain White Noise", fileName: "heavy-rain-white-noise.mp3"),
        Sound(name: "Fan White Noise", fileName: "fan-white-noise-heater.mp3")
        // Add more sounds here, matching your bundled MP3s
    ]
    
    @State private var selectedSound: Sound?
    @State private var isPlaying = false
    
    var body: some View {
        VStack {
            Text("White/Pink Noise")
                .font(.headline)
            
            Picker("Select Noise", selection: $selectedSound) {
                Text("Choose a sound").tag(nil as Sound?) // Placeholder
                ForEach(sounds) { sound in
                    Text(sound.name).tag(sound as Sound?)
                }
            }
            .pickerStyle(.menu)
            
            HStack {
                Button(isPlaying ? "Stop" : "Play") {
                    if isPlaying {
                        player.stopSound()
                    } else if let sound = selectedSound {
                        player.playSound(sound)
                    }
                    isPlaying.toggle()
                }
                .padding()
                .background(isPlaying ? Color.red : Color.green)
                .foregroundColor(.white)
                .cornerRadius(8)
                .disabled(selectedSound == nil) // Disable if no sound selected
            }
            
            // Add premium unlock button here later (e.g., In-App Purchase)
        }
        .padding()
    }
}

#Preview {
    NoiseView()
}
