import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:google_maps_flutter/google_maps_flutter.dart';
import 'package:flutter_font_icons/flutter_font_icons.dart';
import 'package:ride/views/home/Captin/home_captain/drawer_captain.dart';

import '../../../../constant/colors.dart';
import '../../../../constant/info.dart';
import '../../../../constant/style.dart';
import '../../../../constant/table_names.dart';
import '../../../../controller/functions/location_controller.dart';
import '../../../../controller/home/captin/home_captain_controller.dart';
import '../../../../controller/home/captin/order_request_controller.dart';
import '../../../../controller/home/captin/widget/connect.dart';
import '../../../../controller/home/captin/widget/left_menu_map_captain.dart';
import '../../../../controller/local/local_controller.dart';
import '../../../../main.dart';
import '../../../widgets/circle_container.dart';

class HomeCaptain extends StatelessWidget {
  HomeCaptain({super.key});
  final LocationController locationController = LocationController();
  // final HomeCaptainController homeCaptainController = HomeCaptainController();
// final LocationController locationController=LocationController();
  @override
  Widget build(BuildContext context) {
    Get.put(OrderRequestController());
    Get.put(HomeCaptainController());
    // Get.put(HomeCaptainController());
    print('local is    ${Get.find<LocaleController>().language!.countryCode}');
    return Scaffold(
      appBar: AppBar(
        backgroundColor: AppColor.greenColor,
        elevation: 0,
        title: Text('Captain Home'.tr),
        actions: [
          GetBuilder<LocationController>(
            builder: (locationController) => locationController.isLoading
                ? const SizedBox(
                    height: 1,
                    width: 1,
                    child: CircularProgressIndicator.adaptive())
                : const SizedBox(),
          ),
          IconButton(
              // onPressed: () => box.remove(BoxName.periods),
              onPressed: () => sql.deleteAllData(TableName.driverOrdersRefuse),
              icon: const Icon(Icons.remove)),
          GetBuilder<OrderRequestController>(
            builder: (orderRequestController) => IconButton(
                onPressed: () =>
                    orderRequestController.getRefusedOrderByCaptain(),
                icon: const Icon(Icons.get_app)),
          ),
          GetBuilder<OrderRequestController>(
              builder: (orderRequestController) => MyCircleContainer(
                      child: Text(
                    orderRequestController.countRefuse.toString(),
                    style: AppStyle.title,
                  )))
        ],
      ),
      drawer: DrawerCaptain(),
      body: Stack(
        children: [
          GetBuilder<HomeCaptainController>(
            builder: (controller) => GoogleMap(
              onMapCreated: controller.onMapCreated,
              // cameraTargetBounds: CameraTargetBounds(controller.boundsdata),
              minMaxZoomPreference: const MinMaxZoomPreference(6, 18),

              initialCameraPosition: CameraPosition(
                target: locationController.myLocation,
                zoom: 15,
              ),

              mapType: controller.mapType ? MapType.satellite : MapType.normal,
              myLocationButtonEnabled: true,
              // liteModeEnabled: true, tiltGesturesEnabled: false,

              // indoorViewEnabled: true,
              trafficEnabled: controller.mapTrafficON,
              buildingsEnabled: true,
              mapToolbarEnabled: true,

              myLocationEnabled: true,
              // liteModeEnabled: true,
            ),
          ),
          Positioned(
              bottom: 10,
              right: Get.width * .1,
              left: Get.width * .1,
              child: const ConnectWidget()),
          Positioned(
            top: 5,
            right: Get.width * .17,
            left: Get.width * .17,
            child: GetBuilder<HomeCaptainController>(
              builder: (homeCaptainController) => Container(
                  decoration: AppStyle.boxDecoration,
                  width: Get.width * .8,
                  height: 80,
                  child: Center(
                      child: Column(
                    crossAxisAlignment: CrossAxisAlignment.center,
                    children: [
                      Row(
                        mainAxisAlignment: MainAxisAlignment.center,
                        children: [
                          const Icon(
                            Entypo.wallet,
                            color: AppColor.greenColor,
                          ),
                          Text(
                            ' You Earn today is '.tr +
                                homeCaptainController.totalMoneyToday,
                            style: AppStyle.title,
                          ),
                        ],
                      ),
                      Row(
                        mainAxisAlignment: MainAxisAlignment.center,
                        children: [
                          const Icon(
                            Entypo.loop,
                            color: AppColor.yellowColor,
                          ),
                          Text(
                            ' You Have in ${AppInformation.appName} '.tr +
                                homeCaptainController.totalMoneyInSEFER,
                            style: AppStyle.title,
                          ),
                        ],
                      ),
                    ],
                  ))),
            ),
          ),
          Positioned(
            bottom: 65,
            right: Get.width * .1,
            left: Get.width * .1,
            child: GetBuilder<HomeCaptainController>(
              builder: (homeCaptainController) => Container(
                decoration: AppStyle.boxDecoration,
                child: Column(
                  children: [
                    Text(
                      '${'Active Duration:'.tr} ${homeCaptainController.stringActiveDuration} ',
                      style: AppStyle.title,
                    ),
                    Text(
                      '${'Total Connection Duration:'.tr} ${homeCaptainController.totalDurationToday} ',
                      style: AppStyle.title,
                    ),
                  ],
                ),
              ),
            ),
          ),
          Positioned(
            bottom: Get.height * .17,
            right: Get.width * .01,
            child: AnimatedContainer(
              duration: const Duration(microseconds: 200),
              width: Get.width * .12,
              decoration: BoxDecoration(
                  color: AppColor.secondaryColor,
                  border: Border.all(),
                  borderRadius: BorderRadius.circular(15)),
              child: IconButton(
                onPressed: () {
                  // Get.to(
                  // () => CameraWidgetCardId(),
                  // );
                },
                icon: const Icon(Fontisto.history),
              ),
            ),
          ),
          leftMainMenuCaptainIcons(),
        ],
      ),
    );
  }
}

// class CameraContainer extends StatelessWidget {
//   TextMLGoogleRecognizerController controller =
//       Get.put(TextMLGoogleRecognizerController());

//   CameraContainer({super.key});
//   @override
//   Widget build(BuildContext context) {
//     return Stack(
//       children: [
//         // The camera preview
//         SizedBox(
//           height: Get.height * 0.3,
//           width: Get.width * 0.9,
//           child: CameraPreview(controller.imagePicker as CameraController),
//         ),

//         // The lines on the side of the name and national number
//         const Positioned(
//           bottom: 0,
//           left: 0,
//           right: 0,
//           child: Column(
//             children: [
//               Text('Name'),
//               Text('National Number'),
//             ],
//           ),
//         ),
//       ],
//     );
//   }
// }
