import 'dart:ui' show ImageFilter;

import 'package:flutter/material.dart';

class FrostedPanel extends StatelessWidget {
  final Widget child;
  final double radius;
  final double blurSigma;
  final bool enableBlur;
  final EdgeInsetsGeometry padding;
  final EdgeInsetsGeometry? margin;
  final Color color;
  final Gradient? gradient;
  final BoxBorder? border;
  final List<BoxShadow> boxShadow;

  const FrostedPanel({
    super.key,
    required this.child,
    this.radius = 24,
    this.blurSigma = 18,
    this.enableBlur = true,
    this.padding = EdgeInsets.zero,
    this.margin,
    this.color = Colors.black26,
    this.gradient,
    this.border,
    this.boxShadow = const <BoxShadow>[],
  });

  @override
  Widget build(BuildContext context) {
    final borderRadius = BorderRadius.circular(radius);

    final content = DecoratedBox(
      decoration: BoxDecoration(
        color: gradient == null ? color : null,
        gradient: gradient,
        borderRadius: borderRadius,
        border: border,
      ),
      child: Padding(padding: padding, child: child),
    );

    return Padding(
      padding: margin ?? EdgeInsets.zero,
      child: DecoratedBox(
        decoration: BoxDecoration(
          borderRadius: borderRadius,
          boxShadow: boxShadow,
        ),
        child: ClipRRect(
          borderRadius: borderRadius,
          child: enableBlur
              ? BackdropFilter(
                  filter: ImageFilter.blur(
                    sigmaX: blurSigma,
                    sigmaY: blurSigma,
                  ),
                  child: content,
                )
              : content,
        ),
      ),
    );
  }
}
