import 'dart:io';

import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:ride/controller/auth/captin/ml_google_doc.dart';
import 'package:ride/controller/auth/captin/register_captin_controller.dart';
import 'package:ride/views/widgets/my_scafold.dart';

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

class CarLicensePage extends StatelessWidget {
  CarLicensePage({super.key});
  CarRegistrationRecognizerController carRegistrationRecognizerController =
      Get.put(CarRegistrationRecognizerController());
  RegisterCaptinController registerCaptainController =
      Get.put(RegisterCaptinController());

  @override
  Widget build(BuildContext context) {
    return MyScafolld(
        title: 'Car License Card'.tr,
        body: [
          Positioned(
              top: 3,
              left: Get.width * .2,
              right: Get.width * .2,
              child: MyElevatedButton(
                title: 'Take Picture Of ID Card'.tr,
                onPressed: () async {
                  await carRegistrationRecognizerController.scanText();
                },
              )),
          Positioned(
            top: 50,
            child: SizedBox(
              height: Get.height * .7,
              width: Get.width,
              child: buildImageWithBoundingBoxes(),
            ),
          ),
          Positioned(
              bottom: 20,
              left: Get.width * .2,
              right: Get.width * .2,
              child: MyElevatedButton(
                title: 'Register'.tr,
                onPressed: () async {
                  registerCaptainController.addLisence();
                  registerCaptainController.register();
                },
              )),
        ],
        isleading: true);
  }
}

Widget buildImageWithBoundingBoxes() {
  CarRegistrationRecognizerController carRegistrationRecognizerController =
      Get.put(CarRegistrationRecognizerController());
  if (carRegistrationRecognizerController.image == null) {
    return Text('No image selected');
  } else {
    return Stack(
      children: [
        Positioned(
            // top: 50,
            // right: 5,
            // left: 5,
            // bottom: 50,
            child: Image.file(
          File(carRegistrationRecognizerController.image!.path),
          fit: BoxFit.fill,
        )),
        // for (var line
        //     in carRegistrationRecognizerController.extractedTextWithCoordinates)
        //   Positioned(
        //     left: line['boundingBox']['left'],
        //     top: line['boundingBox']['top'] - Get.width * 2,
        //     width: line['boundingBox']['width'],
        //     height: line['boundingBox']['height'],
        //     child: Container(
        //       decoration: BoxDecoration(
        //         border: Border.all(color: Colors.red, width: 2),
        //       ),
        //     ),
        //   ),
      ],
    );
  }
}
