import SwiftUI
import AVFoundation

struct ContentView: View {
   @State private var appData = ApplicationData.shared
   @State private var text: String = ""

   var body: some View {
      VStack {
         TextEditor(text: $text)
            .padding()
            .scrollContentBackground(.hidden)
            .background(Color.gray.opacity(0.2))
            .clipShape(RoundedRectangle(cornerRadius: 12))
            .frame(height: 300)
         Button(action: {
            if appData.synthesizer.isSpeaking {
               if appData.synthesizer.isPaused {
                  // Continue speaking
                  appData.synthesizer.continueSpeaking()
               } else {
                  // Pause speaking
                  appData.synthesizer.pauseSpeaking(at: .word)
               }
            } else {
               // Start speaking
               appData.say(text: text)
            }}, label: {
               Text(appData.buttonLabel)
            }
         )
         .buttonStyle(.borderedProminent)
         .padding()
         Spacer()
      }
      .padding()
   }
}