import 'package:SEFER/controller/payment/paymob.dart';
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:SEFER/views/home/Captin/home_captain/drawer_captain.dart';
import 'package:SEFER/views/widgets/mycircular.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 'widget/connect.dart';
import 'widget/left_menu_map_captain.dart';
import '../../../../controller/home/payment/captain_wallet_controller.dart';
import '../../../../main.dart';
import '../../../widgets/circle_container.dart';

class HomeCaptain extends StatelessWidget {
  HomeCaptain({super.key});
  final LocationController locationController = Get.put(LocationController());
  final HomeCaptainController homeCaptainController =
      Get.put(HomeCaptainController());
  @override
  Widget build(BuildContext context) {
    Get.put(OrderRequestController());
    Get.put(HomeCaptainController());
    return Scaffold(
      appBar: AppBar(
        backgroundColor: AppColor.greenColor,
        elevation: 0,
        title: Text('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)),
          ),
          IconButton(
            onPressed: () {
              PaymobManager().getPaymentKey(100, 'EGP');
            },
            icon: const Icon(
              Icons.call,
              size: 29,
            ),
          ),
        ],
      ),
      drawer: DrawerCaptain(),
      body: Stack(
        children: [
          GetBuilder<HomeCaptainController>(
            builder: (controller) => controller.isLoading
                ? const MyCircularProgressIndicator()
                : 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 * .05,
            left: Get.width * .05,
            child: GetBuilder<HomeCaptainController>(
              builder: (homeCaptainController) => Container(
                  decoration: AppStyle.boxDecoration,
                  width: Get.width * .8,
                  height: 104,
                  child: Center(
                      child: Column(
                    crossAxisAlignment: CrossAxisAlignment.center,
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    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.wallet,
                            color: AppColor.yellowColor,
                          ),
                          Text(
                            '${' You Have in'.tr} ${AppInformation.appName} is ${homeCaptainController.totalMoneyInSEFER}  ',
                            style: AppStyle.title,
                          ),
                        ],
                      ),
                      Row(
                        mainAxisAlignment: MainAxisAlignment.spaceAround,
                        children: [
                          Text(
                            'Total points is '.tr +
                                Get.find<CaptainWalletController>().totalPoints,
                            style: AppStyle.title,
                          ),
                          Container(
                            decoration: BoxDecoration(
                              borderRadius: BorderRadius.circular(6),
                              color: int.parse(Get.find<HomeCaptainController>()
                                          .countRideToday) <
                                      5
                                  ? AppColor.accentColor
                                  : int.parse(Get.find<HomeCaptainController>()
                                                  .countRideToday) >
                                              5 &&
                                          int.parse(Get.find<
                                                      HomeCaptainController>()
                                                  .countRideToday) <
                                              10
                                      ? AppColor.yellowColor
                                      : AppColor.greenColor,
                            ),
                            child: Padding(
                              padding: const EdgeInsets.symmetric(
                                  horizontal: 8, vertical: 2),
                              child: Text(
                                'Ride Today : '.tr +
                                    Get.find<HomeCaptainController>()
                                        .countRideToday,
                                style: AppStyle.title
                                    .copyWith(color: AppColor.secondaryColor),
                              ),
                            ),
                          ),
                        ],
                      ),
                    ],
                  ))),
            ),
          ),
          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: () async {
          //         CRUD().sendEmail(AppLink.sendEmailToPassengerForTripDetails, {
          //           'startLocation': Get.find<MapDriverController>()
          //               .passengerLocation
          //               .toString(),
          //           'endLocation': Get.find<MapDriverController>()
          //               .passengerDestination
          //               .toString(),
          //           'name': Get.find<MapDriverController>().name.toString(),
          //           'timeOfTrip':
          //               Get.find<MapDriverController>().timeOfOrder.toString(),
          //           'fee': Get.find<MapDriverController>()
          //               .totalPassenger
          //               .toString(),
          //           'duration':
          //               Get.find<MapDriverController>().duration.toString(),
          //           'phone': Get.find<MapDriverController>().phone.toString(),
          //           'email': Get.find<MapDriverController>().email.toString(),
          //         });
          //       },
          //       icon: const Icon(
          //         MaterialCommunityIcons.map_marker_radius,
          //         size: 45,
          //         color: AppColor.blueColor,
          //       ),
          //     ),
          //   ),
          // ),
          leftMainMenuCaptainIcons(),
          // callPage(),

          // Positioned(
          //   top: Get.height * .2,
          //   // left: 20,
          //   // right: 20,
          //   bottom: Get.height * .4,
          //   child: IconButton(
          //     onPressed: () {
          //       homeCaptainController.getCountRideToday();
          //     },
          //     icon: const Icon(Icons.call),
          //   ),
          // ),
        ],
      ),
    );
  }
}

// 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'),
//             ],
//           ),
//         ),
//       ],
//     );
//   }
// }
