import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:ride/views/widgets/mycircular.dart';

import '../../../controller/functions/ocr_controller.dart';

class TextExtractionView extends StatelessWidget {
  TextExtractionView({super.key});

  @override
  Widget build(BuildContext context) {
    Get.put(TextExtractionController());
    return Scaffold(
      appBar: AppBar(
        title: const Text('Text Extraction'),
      ),
      body: GetBuilder<TextExtractionController>(builder: (controller) {
        return Center(
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: [
              ElevatedButton(
                onPressed: () => controller.pickAndExtractText(),
                child: const Text('Pick Image and Extract Text'),
              ),
              const SizedBox(height: 20),
              controller.isloading
                  ? const MyCircularProgressIndicator()
                  : Text(controller.extractedText),
            ],
          ),
        );
      }),
    );
  }
}

class TextRecognizerWidget extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    Get.put(TextMLGoogleRecognizerController());
    return GetBuilder<TextMLGoogleRecognizerController>(
        builder: (controller) => Scaffold(
              appBar: AppBar(),
              body: Center(
                child: Text(controller.scannedText ?? ''),
              ),
            ));
  }
}

// class TesseractWidget extends StatelessWidget {
//   final TesseractController controller = Get.put(TesseractController());

//   @override
//   Widget build(BuildContext context) {
//     return Scaffold(
//       appBar: AppBar(
//         title: Text('Tesseract Implementation'),
//       ),
//       body: GetBuilder<TesseractController>(
//         builder: (controller) => Container(
//           padding: const EdgeInsets.all(16),
//           child: ListView(
//             children: <Widget>[
//               Column(
//                 mainAxisAlignment: MainAxisAlignment.spaceEvenly,
//                 children: [
//                   ElevatedButton(
//                     child: Text('Select image'),
//                     onPressed: controller.extractTextFromImage,
//                   ),
//                   controller.scanning
//                       ? const MyCircularProgressIndicator()
//                       : const Icon(Icons.done),
//                   SizedBox(height: 16),
//                   Center(child: SelectableText(controller.text)),
//                 ],
//               ),
//             ],
//           ),
//         ),
//       ),
//     );
//   }
// }

// import 'package:flutter/material.dart';
// import 'package:get/get.dart';
// import 'package:image_picker/image_picker.dart';
//
// import '../../../controller/functions/document_scanner.dart';
//
// class TextScanner extends StatelessWidget {
//   // final ImagePickerController _imagePickerController =
//   //     Get.put(ImagePickerController());
//
//   TextScanner({super.key});
//
//   @override
//   Widget build(BuildContext context) {
//     return Scaffold(
//       appBar: AppBar(
//         title: const Text('Image Picker'),
//       ),
//       body: Center(
//         child: Column(
//           mainAxisAlignment: MainAxisAlignment.center,
//           children: [
//             Obx(() {
//               // final bool textScanning =
//               //     _imagePickerController.textScanning.value;
//               // final String scannedText =
//               //     _imagePickerController.scannedText.value;
//
//               if (textScanning) {
//                 return const CircularProgressIndicator();
//               } else if (scannedText.isNotEmpty) {
//                 return Text(scannedText);
//               } else {
//                 return const Text('No text scanned');
//               }
//             }),
//             ElevatedButton(
//               onPressed: () =>
//                   _imagePickerController.getImage(ImageSource.camera),
//               child: const Text('Take Picture'),
//             ),
//           ],
//         ),
//       ),
//     );
//   }
// }
