import 'dart:convert';

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

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

class TextRecognizerAPI extends StatelessWidget {
  const TextRecognizerAPI({super.key});

  @override
  Widget build(BuildContext context) {
    Get.put(ScanDocumentsByApi());
    return GetBuilder<ScanDocumentsByApi>(
        builder: (controller) => Scaffold(
            appBar: AppBar(
              title: Text('Api'),
              actions: [
                IconButton(
                  onPressed: () {
                    controller.matchFaceApi();
                  },
                  icon: const Icon(Icons.face),
                ),
              ],
            ),
            body: Center(
                child: controller.isLoading
                    ? const MyCircularProgressIndicator()
                    : SingleChildScrollView(
                        child: Column(
                          crossAxisAlignment: CrossAxisAlignment.start,
                          children: [
                            Row(
                              children: [
                                Image.memory(
                                  controller.imagePortrait,
                                  width: 60,
                                ),
                                Image.memory(
                                  controller.imageSignature,
                                  width: 60,
                                ),
                                Image.memory(
                                  controller.imageDocumentFrontSide,
                                  width: 250,
                                ),
                              ],
                            ),
                            Text(controller.responseMap['authenticity_meta']
                                .toString()),
                            Text(
                                'countryName: ${controller.responseMap['data']['countryName'].toString()}'),
                            Text(
                                'Expiry Date: ${controller.responseMap['data']['ocr']['dateOfExpiry'].toString()}'),
                            // Add more Text widgets to display other record values
                            Text(
                                'Address: ${controller.responseMap['data']['ocr']['address'].toString()}'),
                            Text(
                                'City: ${controller.responseMap['data']['ocr']['addressCity'].toString()}'),
                            Text(
                                'Jurisdiction Code: ${controller.responseMap['data']['ocr']['addressJurisdictionCode'].toString()}'),
                            Text(
                                'Postal Code: ${controller.responseMap['data']['ocr']['addressPostalCode'].toString()}'),
                            Text(
                                'Street: ${controller.responseMap['data']['ocr']['addressStreet'].toString()}'),
                            Text(
                                'Date of Birth: ${controller.responseMap['data']['ocr']['dateOfBirth'].toString()}'),
                            Text(
                                'Date of Issue: ${controller.responseMap['data']['ocr']['dateOfIssue'].toString()}'),
                            Text(
                                'Drivers License Class: ${controller.responseMap['data']['ocr']['dlClass'].toString()}'),
                            Text(
                                'Document Number: ${controller.responseMap['data']['ocr']['documentNumber'].toString()}'),
                            Text(
                                'Eye Color: ${controller.responseMap['data']['ocr']['eyesColor'].toString()}'),
                            Text(
                                'Given Names: ${controller.responseMap['data']['ocr']['givenNames'].toString()}'),
                            Text(
                                'Height: ${controller.responseMap['data']['ocr']['height'].toString()}'),
                            Text(
                                'Issuing State Code: ${controller.responseMap['data']['ocr']['issuingStateCode'].toString()}'),
                            Text(
                                'Name: ${controller.responseMap['data']['ocr']['name'].toString()}'),
                            Text(
                                'Sex: ${controller.responseMap['data']['ocr']['sex'].toString()}'),
                            Text(
                                'Surname: ${controller.responseMap['data']['ocr']['surname'].toString()}'),
                            Text(
                                'Valid State: ${controller.responseMap['data']['ocr']['validState'].toString()}'),
                          ],
                        ),
                      ))));
  }
}
// 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: () {},
//                 child: const Text('Pick Image and Extract Text'),
//               ),
//               const SizedBox(height: 20),
//               controller.isloading
//                   ? const MyCircularProgressIndicator()
//                   : Text(controller.extractedText),
//             ],
//           ),
//         );
//       }),
//     );
//   }
// }

// class TextRecognizerWidget extends StatelessWidget {
//   const TextRecognizerWidget({super.key});
//
//   @override
//   Widget build(BuildContext context) {
//     Get.put(TextMLGoogleRecognizerController());
//     return GetBuilder<TextMLGoogleRecognizerController>(
//         builder: (controller) => Scaffold(
//             appBar: AppBar(),
//             body: Center(
//                 child: Column(
//               crossAxisAlignment: CrossAxisAlignment.start,
//               children: [
//                 Text('${controller.decode['DRIVER_LICENSE'].toString()}'),
//                 Text('DL: ${controller.decode['dl_number'].toString()}'),
//                 Text(
//                     'Expiry Date: ${controller.decode['expiry_date'].toString()}'),
//                 Text('Last Name: ${controller.decode['lastName'].toString()}'),
//                 Text(
//                     'First Name: ${controller.decode['firstName'].toString()}'),
//                 Text('Address: ${controller.decode['address'].toString()}'),
//                 Text('Date of Birth: ${controller.decode['dob'].toString()}'),
//                 Text('RSTR: ${controller.decode['rstr'].toString()}'),
//                 Text('Class: ${controller.decode['class'].toString()}'),
//                 Text('End: ${controller.decode['end'].toString()}'),
//                 Text('DD: ${controller.decode['dd'].toString()}'),
//                 Text('Sex: ${controller.decode['sex'].toString()}'),
//                 Text('Hair: ${controller.decode['hair'].toString()}'),
//                 Text('Eyes: ${controller.decode['eyes'].toString()}'),
//                 // and so on for other fields
//               ],
//             ))));
//   }
// }

// class PassportPage extends StatelessWidget {
//   PassportPage({super.key});
//   PassportRecognizerController passportRecognizerController =
//       Get.put(PassportRecognizerController());
//   @override
//   Widget build(BuildContext context) {
//     return Scaffold(
//         appBar: AppBar(
//           title: const Text('Driver License'),
//         ),
//         body: const Center(child: Text('data')));
//   }
// }
