import SwiftUI
import Vision

struct DocumentView: View {
   @State private var textFound: String = "Recognizing..."

   var body: some View {
      VStack {
         ScrollView {
            Text(textFound)
               .padding()
         }
         Spacer()
      }
      .task {
         let imageURL = Bundle.main.url(forResource: "letter", withExtension: "png")
         if let imageURL = imageURL {
            do {
               let request = RecognizeDocumentsRequest()
               let result = try await request.perform(on: imageURL)

               if let document = result.first?.document {
                  textFound = document.text.transcript
               }
            } catch {
               print("Error performing the request: \(error)")
            }
         }
      }
   }
}