import 'package:flutter/material.dart';

class RedWaveBackground extends StatelessWidget {
  final Color brandRed;
  final double heightFactor;

  const RedWaveBackground({
    super.key,
    required this.brandRed,
    this.heightFactor = 0.2,
  });

  @override
  Widget build(BuildContext context) {
    return CustomPaint(
      painter: RedWavePainter(brandRed, heightFactor),
      size: Size.infinite,
    );
  }
}

class RedWavePainter extends CustomPainter {
  final Color brandRed;
  final double heightFactor;

  RedWavePainter(this.brandRed, this.heightFactor);

  @override
  void paint(Canvas canvas, Size size) {
    final paint1 = Paint()
      ..shader = LinearGradient(
        colors: [brandRed, const Color.fromARGB(255, 97, 22, 22)],
        begin: Alignment.topLeft,
        end: Alignment.bottomRight,
      ).createShader(Rect.fromLTWH(0, 0, size.width, size.height));

    final path1 = Path()
      ..moveTo(0, size.height * heightFactor)
      ..quadraticBezierTo(
        size.width * 0.25, size.height * 0.05,
        size.width * 0.5, size.height * 0.15,
      )
      ..quadraticBezierTo(
        size.width * 0.75, size.height * 0.25,
        size.width, size.height * 0.1,
      )
      ..lineTo(size.width, 0)
      ..lineTo(0, 0)
      ..close();

    canvas.drawPath(path1, paint1);

    final paint2 = Paint()..color = brandRed.withOpacity(0.15);
    final path2 = Path()
      ..moveTo(0, size.height * (heightFactor + 0.05))
      ..quadraticBezierTo(
        size.width * 0.4, size.height * 0.1,
        size.width, size.height * 0.2,
      )
      ..lineTo(size.width, 0)
      ..lineTo(0, 0)
      ..close();

    canvas.drawPath(path2, paint2);
  }

  @override
  bool shouldRepaint(CustomPainter oldDelegate) => false;
}
