import 'dart:math';

import 'package:flutter/cupertino.dart';

/// Created by Haoyi on 2023/10/11

class YearlyTrophiesDecoration extends Decoration {
  final Gradient? gradient;
  final double height;
  final bool enabled;

  const YearlyTrophiesDecoration(
      {required this.gradient, required this.height, this.enabled = true});

  @override
  BoxPainter createBoxPainter([VoidCallback? onChanged]) {
    return YearlyTrophiesPainter(gradient, height, enabled);
  }
}

class YearlyTrophiesPainter extends BoxPainter {
  final Gradient? gradient;
  final double height;
  final bool enabled;
  final Paint bgPaint = Paint()..isAntiAlias = true;

  YearlyTrophiesPainter(this.gradient, this.height, this.enabled);

  @override
  void paint(Canvas canvas, Offset offset, ImageConfiguration configuration) {
    if (!enabled || gradient == null) {
      return;
    }
    Rect rect =
        Rect.fromLTWH(0, offset.dx, configuration.size!.width, min(height, configuration.size!.height));
    bgPaint.shader = gradient?.createShader(rect);
    canvas.drawRect(rect, bgPaint);
  }

}
