import 'package:flutter/material.dart';
import 'package:flutter_font_icons/flutter_font_icons.dart';
import 'package:get/get.dart';
import 'package:ride/constant/box_name.dart';
import 'package:ride/controller/profile/profile_controller.dart';
import 'package:ride/main.dart';
import 'package:ride/views/widgets/elevated_btn.dart';

import '../../../constant/colors.dart';
import '../../../constant/style.dart';
import '../../../controller/home/map_passenger_controller.dart';

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

  @override
  Widget build(BuildContext context) {
    ProfileController profileController = Get.put(ProfileController());
    return GetBuilder<MapPassengerController>(builder: (controller) {
      if (controller.rideTimerBegin) {
        return Positioned(
          left: 10,
          right: 10,
          bottom: 4,
          child: Container(
            decoration: AppStyle.boxDecoration,
            height: 200,
            // width: 100,
            child: Padding(
              padding: const EdgeInsets.all(8.0),
              child: Column(
                mainAxisAlignment: MainAxisAlignment.center,
                children: [
                  Text(
                    'You will arrive to your destination after '.tr,
                    style: AppStyle.title,
                  ),
                  Stack(
                    children: [
                      LinearProgressIndicator(
                        backgroundColor: AppColor.accentColor,
                        color: controller.remainingTimeTimerRideBegin < 60
                            ? AppColor.redColor
                            : AppColor.greenColor,
                        minHeight: 50,
                        borderRadius: BorderRadius.circular(15),
                        value: controller.progressTimerRideBegin.toDouble(),
                      ),
                      Center(
                        child: Text(
                          controller.stringRemainingTimeRideBegin,
                          style: AppStyle.title,
                        ),
                      )
                    ],
                  ),
                  Row(
                    mainAxisAlignment: MainAxisAlignment.spaceAround,
                    children: [
                      IconButton(
                        onPressed: () {
                          if (box.read(BoxName.sosPhonePassenger).toString() ==
                              '') {
                            Get.defaultDialog(
                                title: 'You dont Add Emergency Phone Yet!'.tr,
                                content: Column(
                                  children: [
                                    Form(
                                      key: controller.sosFormKey,
                                      child: TextFormField(
                                        keyboardType: TextInputType
                                            .phone, // Set the keyboard type to phone
                                        validator: (value) {
                                          if (value!.isEmpty ||
                                              value.length < 10) {
                                            return 'Please enter a phone number';
                                          }
                                          // Add additional validation if needed
                                          return null;
                                        },
                                        decoration: const InputDecoration(
                                          border: OutlineInputBorder(),
                                          hintText: 'Type here',
                                        ),
                                      ),
                                    )
                                  ],
                                ),
                                confirm: MyElevatedButton(
                                    title: 'Add Phone'.tr,
                                    onPressed: () async {
                                      await profileController
                                          .updatField('sosPhone');
                                      box.write(
                                          BoxName.sosPhonePassenger,
                                          profileController
                                              .prfoileData['sosPhone']);
                                    }));
                          } else {
                            controller
                                .sendSMS(box.read(BoxName.sosPhonePassenger));
                          }
                        },
                        icon: const Icon(
                          Icons.sos_rounded,
                          color: AppColor.redColor,
                        ),
                      ),
                      IconButton(
                        onPressed: () {
                          if (box.read(BoxName.sosPhonePassenger).toString() ==
                              '') {
                            Get.defaultDialog(
                                title: 'You dont Add Emergency Phone Yet!'.tr,
                                content: Column(
                                  children: [
                                    Form(
                                      key: controller.sosFormKey,
                                      child: TextFormField(
                                        keyboardType: TextInputType
                                            .phone, // Set the keyboard type to phone
                                        validator: (value) {
                                          if (value!.isEmpty ||
                                              value.length < 10) {
                                            return 'Please enter a phone number'
                                                .tr;
                                          }
                                          // Add additional validation if needed
                                          return null;
                                        },
                                        decoration: const InputDecoration(
                                          border: OutlineInputBorder(),
                                          hintText: 'Type here',
                                        ),
                                      ),
                                    )
                                  ],
                                ),
                                confirm: MyElevatedButton(
                                    title: 'Add Phone'.tr,
                                    onPressed: () async {
                                      await profileController
                                          .updatField('sosPhone');
                                      box.write(
                                          BoxName.sosPhonePassenger,
                                          profileController
                                              .prfoileData['sosPhone']);
                                    }));
                          } else {
                            controller.sendWhatsapp(
                                box.read(BoxName.sosPhonePassenger));
                          }
                        },
                        icon: const Icon(
                          FontAwesome.whatsapp,
                          color: AppColor.greenColor,
                        ),
                      ),
                    ],
                  )
                  // controller.remainingTimeTimerRideBegin < 5
                  //     ? MyElevatedButton(
                  //         title:
                  //             'If you in destination Now. Press finish The Ride',
                  //         onPressed: () async {
                  //todo finish the trip and rest all counter ,start new counter of the trip time

                  // await CRUD()
                  //     .post(link: AppLink.updateRides, payload: {
                  //   'id': controller.rideId,
                  //   'rideTimeStart': DateTime.now().toString(),
                  //   'status': 'Applied'
                  // });
                  // controller.driverArrivePassenger();
                  // // Send notification to driver to alert him that trip is begin
                  // FirebaseMessagesController()
                  //     .sendNotificationToAnyWithoutData(
                  //   'BeginTrip',
                  //   box.read(BoxName.name).toString(),
                  //   controller.driverToken.toString(),
                  // );
                  // print(controller.driverToken.toString());
                  // Get.defaultDialog(
                  //   title: 'The Ride is Begin'.tr,
                  //   backgroundColor: AppColor.greenColor,
                  // );
                  //     })
                  // : const SizedBox()
                ],
              ),
            ),
          ),
        );
      } else {
        return const SizedBox();
      }
    });
  }
}
