import 'package:flutter/material.dart';
import 'package:get/get.dart';

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

GetBuilder<MapPassengerController> timerForCancelTripFromPassenger() {
  return GetBuilder<MapPassengerController>(
    builder: (controller) {
      final isNearEnd =
          controller.remainingTime <= 5; // Define a threshold for "near end"

      return controller.remainingTime > 0 && controller.remainingTime != 25
          ? Positioned(
              bottom: Get.height * .35,
              left: Get.width * .05,
              child: Container(
                decoration: AppStyle.boxDecoration,
                child: Padding(
                  padding: const EdgeInsets.all(8.0),
                  child: Row(
                    children: <Widget>[
                      Stack(
                        alignment: Alignment.center,
                        children: [
                          CircularProgressIndicator(
                            value: controller.progress,
                            // Set the color based on the "isNearEnd" condition
                            color: isNearEnd ? Colors.red : Colors.blue,
                          ),
                          Text(
                            '${controller.remainingTime}',
                            style: AppStyle.number,
                          ),
                        ],
                      ),
                      const SizedBox(
                        width: 30,
                      ),
                      Text(
                        'You can cancel Ride now'.tr,
                        style: AppStyle.title,
                      )
                    ],
                  ),
                ),
              ),
            )
          : const SizedBox();
    },
  );
}
