import 'package:flutter/material.dart';
import 'package:hmg_patient_app_new/core/app_export.dart';

class CustomRoundedProgressBar extends StatelessWidget {
  final int percentage;
  final Color color;
  final Color backgroundColor;
  final double? height;
  final double? paddingBetween;
  final Widget? titleWidget;

  const CustomRoundedProgressBar({
    super.key,
    this.titleWidget,
    required this.percentage,
    this.paddingBetween,
    required this.color,
    required this.backgroundColor,
    this.height,
  });

  @override
  Widget build(BuildContext context) {
    final h = height ?? 8.h;
    return Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        if (titleWidget != null) ...[
          titleWidget!,
          if (paddingBetween != null) ...[
            SizedBox(height: paddingBetween),
          ]
        ],
        LayoutBuilder(
          builder: (context, constraints) {
            double radius = h / 2;
            return Container(
              height: h,
              width: constraints.maxWidth,
              decoration: BoxDecoration(
                color: backgroundColor,
                borderRadius: BorderRadius.circular(radius),
              ),
              child: Align(
                alignment: Alignment.centerLeft,
                child: FractionallySizedBox(
                  widthFactor: (percentage.clamp(0, 100)) / 100,
                  child: Container(
                    height: height,
                    decoration: BoxDecoration(
                      color: color,
                      borderRadius: BorderRadius.horizontal(
                        left: Radius.circular(radius),
                        right: Radius.circular(radius),
                      ),
                    ),
                  ),
                ),
              ),
            );
          },
        ),
      ],
    );
  }
}
