import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:SEFER/views/widgets/elevated_btn.dart';

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

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

  @override
  Widget build(BuildContext context) {
    return GetBuilder<MapPassengerController>(builder: (controller) {
      if (controller.remainingTime == 0 &&
          (controller.isDriverInPassengerWay == true ||
              controller.timeToPassengerFromDriverAfterApplied > 0)) {
        // ) {
        return Positioned(
          left: 10,
          right: 10,
          bottom: 5,
          child: Container(
            decoration: AppStyle.boxDecoration,
            height: controller.remainingTime == 0 &&
                    (controller.isDriverInPassengerWay == true ||
                        controller.timeToPassengerFromDriverAfterApplied > 0)
                ? 200
                : 0,
            // width: 100,
            child: Padding(
              padding: const EdgeInsets.all(8.0),
              child: Column(
                children: [
                  Text(
                    'You Can cancel Ride After Captain did not come in the time'
                        .tr,
                    style: AppStyle.title,
                    textAlign: TextAlign.center,
                  ),
                  Stack(
                    children: [
                      LinearProgressIndicator(
                        backgroundColor: AppColor.accentColor,
                        color: controller
                                    .remainingTimeToPassengerFromDriverAfterApplied <
                                60
                            ? AppColor.redColor
                            : AppColor.greenColor,
                        minHeight: 25,
                        borderRadius: BorderRadius.circular(15),
                        value: controller
                            .progressTimerToPassengerFromDriverAfterApplied
                            .toDouble(),
                      ),
                      Center(
                        child: Text(
                          controller.stringRemainingTimeToPassenger,
                          style: AppStyle.title,
                        ),
                      )
                    ],
                  ),
                  IconButton(
                    onPressed: () {},
                    icon: const Icon(
                      Icons.phone,
                      color: AppColor.blueColor,
                    ),
                  ),
                  controller.remainingTimeToPassengerFromDriverAfterApplied < 60
                      ? MyElevatedButton(
                          title: 'You can cancel trip'.tr,
                          onPressed: () async {
                            await controller
                                .calculateDistanceBetweenPassengerAndDriverBeforeCancelRide();
                          })
                      : const SizedBox()
                ],
              ),
            ),
          ),
        );
      } else if (controller.remainingTime == 0 &&
          controller.isDriverArrivePassenger == true) {
        return Positioned(
          left: 10,
          right: 10,
          bottom: 5,
          child: Container(
            decoration: AppStyle.boxDecoration,
            height: controller.remainingTime == 0 &&
                    controller.isDriverArrivePassenger == true
                ? 150
                : 0,
            // width: 100,
            child: Padding(
              padding: const EdgeInsets.all(8.0),
              child: Column(
                children: [
                  Text(
                    'The driver waitting you in picked location .'.tr,
                    style: AppStyle.title,
                    textAlign: TextAlign.center,
                  ),
                  Stack(
                    children: [
                      LinearProgressIndicator(
                        backgroundColor: AppColor.accentColor,
                        color:
                            controller.remainingTimeDriverWaitPassenger5Minute <
                                    60
                                ? AppColor.redColor
                                : AppColor.greenColor,
                        minHeight: 50,
                        borderRadius: BorderRadius.circular(15),
                        value: controller
                            .progressTimerDriverWaitPassenger5Minute
                            .toDouble(),
                      ),
                      Center(
                        child: Text(
                          controller
                              .stringRemainingTimeDriverWaitPassenger5Minute,
                          style: AppStyle.title,
                        ),
                      )
                    ],
                  ),
                  Text(
                    'Please go to Car now '.tr,
                    style: AppStyle.title,
                    textAlign: TextAlign.center,
                  ),
                ],
              ),
            ),
          ),
        );
      } else {
        return const RideBeginPassenger();
      }
    });
  }
}
