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

import '../../../constant/style.dart';
import '../../../controller/home/map/ride_lifecycle_controller.dart';

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

      return controller.remainingTime > 0 && controller.remainingTime != 25
          ? Positioned(
              bottom: 5,
              left: 10,
              right: 10,
              child: Container(
                height: 180,
                decoration: AppStyle.boxDecoration,
                child: Padding(
                  padding: const EdgeInsets.all(8.0),
                  child: Column(
                    children: [
                      Row(
                        mainAxisAlignment: MainAxisAlignment.spaceAround,
                        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,
                          )
                        ],
                      ),
                      Text(
                        'After this period\nYou can\'t cancel!'.tr,
                        style: AppStyle.title,
                      )
                    ],
                  ),
                ),
              ),
            )
          : const SizedBox();
    },
  );
}
