import 'dart:ui';

import 'package:design/design.dart';
import 'package:flutter/material.dart';
import 'package:guru_widgets/tabbar/guru_tab_bar.dart';
import 'package:guru_widgets/theme/guru_theme.dart';

class CustomTabBarDecoration extends Decoration {
  const CustomTabBarDecoration();

  @override
  BoxPainter createBoxPainter([VoidCallback? onChanged]) {
    return CustomTabBarPainter(GuruThemeDesignSpec.get().tabBarDesignSpec);
  }
}

class CustomTabBarPainter extends BoxPainter {
  final Paint painter = Paint()..isAntiAlias = true;
  final GuruTabBarDesignSpec designSpec;

  CustomTabBarPainter(this.designSpec);

  @override
  void paint(Canvas canvas, Offset offset, ImageConfiguration configuration) {
    assert(configuration != null); 
    assert(configuration.size != null);
    final Rect rect = offset & configuration.size!;

    final Gradient gradient = LinearGradient(
        begin: Alignment.centerLeft,
        end: Alignment.centerRight,
        colors: [Color(0xFFEF5B5B), Color.fromARGB(255, 53, 217, 50)]);

    painter.shader = gradient.createShader(rect);
    canvas.drawRRect(RRect.fromRectAndRadius(rect, Radius.circular(designSpec.tabBarHeight * 0.5)), painter);
  }
}
