import 'package:flutter/material.dart';
import 'package:softplayer_web/shared/ui/colors/light_mode.dart';

class AuthDecoration extends StatelessWidget {
  const AuthDecoration({super.key});

  @override
  Widget build(BuildContext context) {
    return Container(
      color: LightModeColors.backgroundElevated,
      child: FractionallySizedBox(
        alignment: Alignment.centerLeft,
        child: const CustomPaint(
          painter: _GradientPainter(),
          child: SizedBox.expand(),
        ),
      ),
    );
  }
}

class _GradientPainter extends CustomPainter {
  const _GradientPainter();

  @override
  void paint(Canvas canvas, Size size) {
    // 🎨 Main smooth background gradient
    final rect = Offset.zero & size;

    final backgroundGradient = const LinearGradient(
      begin: Alignment.topLeft,
      end: Alignment.bottomRight,
      colors: [
        Color(0xFF0F172A), // deep navy
        Color(0xFF111827), // dark slate
      ],
    );

    final paint = Paint()..shader = backgroundGradient.createShader(rect);

    canvas.drawRect(rect, paint);

    // 🌈 soft glowing blobs (adds "cool gradient feel")
    _drawGlow(
      canvas,
      size,
      offset: const Offset(0.2, 0.3),
      radius: size.width * 0.8,
      colors: [Colors.cyan.withOpacity(0.25), Colors.transparent],
    );

    _drawGlow(
      canvas,
      size,
      offset: const Offset(0.8, 0.6),
      radius: size.width * 0.9,
      colors: [Colors.purple.withOpacity(0.20), Colors.transparent],
    );

    _drawGlow(
      canvas,
      size,
      offset: const Offset(0.5, 0.9),
      radius: size.width * 0.7,
      colors: [Colors.blue.withOpacity(0.20), Colors.transparent],
    );
  }

  void _drawGlow(
    Canvas canvas,
    Size size, {
    required Offset offset,
    required double radius,
    required List<Color> colors,
  }) {
    final center = Offset(size.width * offset.dx, size.height * offset.dy);

    final gradient = RadialGradient(colors: colors, radius: 1.0);

    final paint = Paint()
      ..shader = gradient.createShader(
        Rect.fromCircle(center: center, radius: radius),
      )
      ..maskFilter = const MaskFilter.blur(BlurStyle.normal, 60);

    canvas.drawCircle(center, radius, paint);
  }

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