import SwiftUI
import NaturalLanguage

struct ContentView: View {
   @State private var textInput: String = ""
   @State private var message: String = ""

   var body: some View {
      VStack {
         TextEditor(text: $textInput)
            .frame(height: 200)
            .padding()
            .scrollContentBackground(.hidden)
            .background(Color.gray.opacity(0.2))
            .clipShape(RoundedRectangle(cornerRadius: 12))
         Text(message)
            .padding()         
         Spacer()
      }
      .padding()
      .onChange(of: textInput) { old, new in
         let detect = NLLanguageRecognizer()
         detect.processString(new)
         if let code = detect.dominantLanguage {
            if code == .english {
               message = "English"
            } else {
               message = "Not English"
            }
         }
      }
   }
}