import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:news_getx/theme/app_borders.dart';
import 'package:news_getx/theme/app_colors.dart';
import 'package:news_getx/theme/app_radii.dart';

/// 扁平圆角按钮
class FlatButton extends StatelessWidget {
  final VoidCallback onPressed;
  final double width;
  final double height;
  final Color gbColor;
  final String title;
  final Color fontColor;
  final double fontSize;
  final String fontName;
  final FontWeight fontWeight;

  @override
  Widget build(BuildContext context) {
    return SizedBox(
      width: width.w,
      height: height.h,
      child: TextButton(
        onPressed: onPressed,
        style: ButtonStyle(
          textStyle: MaterialStateProperty.all(TextStyle(fontSize: 16.sp)),
          foregroundColor: MaterialStateProperty.resolveWith((states) {
            if (states.contains(MaterialState.focused) &&
                !states.contains(MaterialState.pressed)) {
              return Colors.blue;
            } else if (states.contains(MaterialState.pressed)) {
              return Colors.deepPurple;
            }
            return fontColor;
          }),
          backgroundColor: MaterialStateProperty.resolveWith((states) {
            if (states.contains(MaterialState.pressed)) {
              return Colors.blue[200];
            }
            return gbColor;
          }),
          shape: MaterialStateProperty.all(RoundedRectangleBorder(
            borderRadius: Radii.k6pxRadius,
          )),
        ),
        child: Text(
          title,
          textAlign: TextAlign.center,
          style: TextStyle(
            color: fontColor,
            fontFamily: fontName,
            fontWeight: fontWeight,
            fontSize: fontSize.sp,
            height: 1,
          ),
        ),
      ),
    );
  }

  FlatButton({
    required this.onPressed,
    super.key,
    this.width = 140,
    this.height = 140,
    this.gbColor = AppColors.primaryElement,
    this.title = "button",
    this.fontColor = AppColors.primaryElementText,
    this.fontSize = 18,
    this.fontName = "Montserrat",
    this.fontWeight = FontWeight.w400,
  });
}

/// 扁平圆角按钮
class IconBorderFlatButton extends StatelessWidget {
  final VoidCallback onPressed;
  final String iconFileName;
  final double width;
  final double height;

  @override
  Widget build(BuildContext context) {
    return SizedBox(
      width: width.w,
      height: height.h,
      child: TextButton(
        onPressed: onPressed,
        style: ButtonStyle(
          shape: MaterialStateProperty.all(RoundedRectangleBorder(
            borderRadius: Radii.k6pxRadius,
            side: AppBorders.primaryBorder,
          )),
        ),
        child: Image.asset(
          "assets/images/icons-$iconFileName.png",
        ),
      ),
    );
  }

  IconBorderFlatButton({
    required this.onPressed,
    required this.iconFileName,
    super.key,
    this.width = 88,
    this.height = 44,
  });
}
