import 'package:flutter/material.dart';
import 'package:kasy_kit/core/theme/theme.dart';

class PremiumBackground extends StatelessWidget {
  final Widget child;
  final String? bgImagePath;

  const PremiumBackground({
    super.key,
    required this.child,
    this.bgImagePath,
  });

  @override
  Widget build(BuildContext context) {
    return Stack(
      fit: StackFit.expand,
      children: <Widget>[
        const Positioned.fill(child: ColoredBox(color: Colors.black)),
        if (bgImagePath != null)
          Positioned(
            top: 0,
            left: 0,
            right: 0,
            bottom: 0,
            child: Opacity(
              opacity: .60,
              child: Image.asset(
                bgImagePath!,
                fit: BoxFit.cover,
              ),
            ),
          ),
        Positioned.fill(
          child: Container(
              decoration: BoxDecoration(
            gradient: LinearGradient(
              colors: [
                Colors.transparent,
                context.colors.premiumOverlayMid.withValues(alpha: .4),
                context.colors.premiumOverlayDark,
              ],
              stops: const [0, 0.4, 1],
              begin: Alignment.topCenter,
              end: Alignment.bottomCenter,
            ),
          )),
        ),
        Positioned.fill(
          child: LayoutBuilder(
            builder: (context, constraints) {
              return SizedBox(
                width: constraints.maxWidth,
                height: constraints.maxHeight,
                child: child,
              );
            },
          ),
        )
      ],
    );
  }
}
