content: // Flutter imports:
  import 'package:flutter/material.dart';
  
  // Package imports:
  import 'package:flutter_riverpod/flutter_riverpod.dart';
  
  // Project imports:
  import '../premiums.dart';
  import 'providers/premium_providers.dart';
  import 'routes/routes.dart';
  
  class PremiumInteractionBlock extends ConsumerWidget {
    const PremiumInteractionBlock({
      required this.child,
      super.key,
      this.padding,
    });
  
    const PremiumInteractionBlock.horizontalPadding({
      required this.child,
      super.key,
    }) : padding = const EdgeInsets.symmetric(horizontal: 8);
  
    final EdgeInsetsGeometry? padding;
    final Widget child;
  
    @override
    Widget build(BuildContext context, WidgetRef ref) {
      final hasPremium = ref.watch(hasPremiumProvider);
  
      return !hasPremium
          ? Stack(
              children: [
                Column(
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: [
                    Container(
                      padding: const EdgeInsets.symmetric(
                        horizontal: 12,
                        vertical: 4,
                      ),
                      child: Text(
                        kPremiumBrandName,
                        style: TextStyle(
                          color: Theme.of(context).colorScheme.onSurface,
                          fontWeight: FontWeight.w900,
                          letterSpacing: -1,
                        ),
                      ),
                    ),
                    Container(
                      margin: padding,
                      decoration: BoxDecoration(
                        border: const GradientBoxBorder(
                          gradient: LinearGradient(
                            colors: [
                              Colors.blue,
                              Colors.red,
                            ],
                          ),
                          width: 1.5,
                        ),
                        borderRadius: BorderRadius.circular(8),
                      ),
                      child: IgnorePointer(
                        child: Padding(
                          padding: const EdgeInsets.only(left: 8),
                          child: child,
                        ),
                      ),
                    ),
                  ],
                ),
                Positioned.fill(
                  child: GestureDetector(
                    behavior: HitTestBehavior.opaque,
                    onTap: () {
                      goToPremiumPage(ref);
                    },
                  ),
                ),
              ],
            )
          : child;
    }
  }
  
  class GradientBoxBorder extends BoxBorder {
    const GradientBoxBorder({required this.gradient, this.width = 1.0});
  
    final Gradient gradient;
  
    final double width;
  
    @override
    BorderSide get bottom => BorderSide.none;
  
    @override
    BorderSide get top => BorderSide.none;
  
    @override
    EdgeInsetsGeometry get dimensions => EdgeInsets.all(width);
  
    @override
    bool get isUniform => true;
  
    @override
    void paint(
      Canvas canvas,
      Rect rect, {
      TextDirection? textDirection,
      BoxShape shape = BoxShape.rectangle,
      BorderRadius? borderRadius,
    }) {
      switch (shape) {
        case BoxShape.circle:
          assert(
            borderRadius == null,
            'A borderRadius can only be given for rectangular boxes.',
          );
          _paintCircle(canvas, rect);
        case BoxShape.rectangle:
          if (borderRadius != null) {
            _paintRRect(canvas, rect, borderRadius);
            return;
          }
          _paintRect(canvas, rect);
      }
    }
  
    void _paintRect(Canvas canvas, Rect rect) {
      canvas.drawRect(rect.deflate(width / 2), _getPaint(rect));
    }
  
    void _paintRRect(Canvas canvas, Rect rect, BorderRadius borderRadius) {
      final rrect = borderRadius.toRRect(rect).deflate(width / 2);
      canvas.drawRRect(rrect, _getPaint(rect));
    }
  
    void _paintCircle(Canvas canvas, Rect rect) {
      final paint = _getPaint(rect);
      final radius = (rect.shortestSide - width) / 2.0;
      canvas.drawCircle(rect.center, radius, paint);
    }
  
    @override
    ShapeBorder scale(double t) {
      return this;
    }
  
    Paint _getPaint(Rect rect) {
      return Paint()
        ..strokeWidth = width
        ..shader = gradient.createShader(rect)
        ..style = PaintingStyle.stroke;
    }
  }
  