import 'package:flutter/material.dart';
import 'package:hmg_patient_app_new/core/utils/size_utils.dart';
import 'package:hmg_patient_app_new/theme/colors.dart';
import 'package:hmg_patient_app_new/widgets/order_tracking/order_tracking_state.dart';
import 'package:hmg_patient_app_new/widgets/stepper/stepper_widget.dart';

class OrderTrackingWidget extends StatelessWidget {
  final double? height;
  final OrderTrackingState? state;
  final double parentPaddingValue;

  const OrderTrackingWidget({super.key, this.height, required this.state, required this.parentPaddingValue});

  @override
  Widget build(BuildContext context) {
    return SizedBox(
      width: MediaQuery
          .sizeOf(context)
          .width,
      height: height,
      child: getBarAndDot(state, context, MediaQuery
          .sizeOf(context)
          .width),
    );
  }

  Widget? getBarAndDot(OrderTrackingState? state, BuildContext context,
      double width) {
    double widthOfOneState = (width/4) - (parentPaddingValue+8.h);
    if(state == null) {
      return Row(
          children: List.generate(4, (index) {
        if (index == 0) {
          return StepperWidget(widthOfOneState, AppColors.primaryRedColor, true, height);
        } else {
          return StepperWidget(widthOfOneState, AppColors.greyLightColor, false, height);
        }
      }));
    }
    switch (state) {
      case OrderTrackingState.waitingForCall:
        return Row(
          children: List.generate(4, (index){
            if(index == 0) {
              return StepperWidget(widthOfOneState, AppColors.primaryRedColor, true, height);
            } else {
              return StepperWidget(widthOfOneState, AppColors.greyLightColor, false, height);
            }
          })
        );

      case OrderTrackingState.dispactched:
        return Row(
            children: List.generate(4, (index){
              if(index == 1 || index == 0) {
                return StepperWidget(widthOfOneState, AppColors.primaryRedColor, index == 1, height );
              } else {
                return StepperWidget(widthOfOneState, AppColors.greyLightColor, false, height);
              }
            })
        );
      case OrderTrackingState.returning:
        return Row(
            children: List.generate(4, (index){
              if(index == 2 || index == 1 || index == 0) {
                return StepperWidget(widthOfOneState, AppColors.primaryRedColor, index == 2, height);
              } else {
                return StepperWidget(widthOfOneState, AppColors.greyLightColor, false, height);
              }
            })
        );
      case OrderTrackingState.ended:
        return Row(
            children: List.generate(4, (index){
              // if(index == 3) {
                return StepperWidget(widthOfOneState, AppColors.successLightColor, index == 3, height);
              // } else {
              //   return oneProgressBar(widthOfOneState, AppColors.greyLightColor, false);
              // }
            })
        );
      case OrderTrackingState.failed:
        return Row(
            children: List.generate(4, (index){
              // if(index == 3) {
              return StepperWidget(widthOfOneState, AppColors.errorColor, index == 3, height);
              // } else {
              //   return oneProgressBar(widthOfOneState, AppColors.greyLightColor, false);
              // }
            })
        );
      case OrderTrackingState.cancel:
        return Row(
            children: List.generate(4, (index){
              // if(index == 3) {
              return StepperWidget(widthOfOneState, AppColors.errorColor, index == 3, height);
              // } else {
              //   return oneProgressBar(widthOfOneState, AppColors.greyLightColor, false);
              // }
            })
        );
    }
  }



}