import 'package:flutter/material.dart';
import 'package:rasadyar_core/presentation/common/app_color.dart';
import 'package:rasadyar_core/presentation/common/assets.gen.dart';
import 'package:rasadyar_core/presentation/utils/color_utils.dart';

class RFabOutlined extends StatefulWidget {
  final Widget icon;
  VoidCallback? onPressed;
  final Color backgroundColor;
  final Color? borderColor;
  final double? radius;
  OutlinedBorder? shapeBorder;

  @override
  State<RFabOutlined> createState() => _RFabOutlinedState();

  //region General
  RFabOutlined({
    required this.icon,
    required this.onPressed,
    required this.backgroundColor,
    required this.borderColor,
    this.radius = 56.0,
    super.key,
  }) : shapeBorder = CircleBorder(
         side: BorderSide(color: borderColor ?? Colors.transparent),
       );

  RFabOutlined.noBorder({
    required this.icon,
    required this.onPressed,
    required this.backgroundColor,
    super.key,
  }) : borderColor = Colors.transparent,
       radius = 56.0,
       shapeBorder = CircleBorder(
         side: BorderSide(color: Colors.transparent, width: 1),
       );

  RFabOutlined.small({
    required this.icon,
    required this.onPressed,
    required this.backgroundColor,
    required this.borderColor,
    super.key,
  }) : radius = 40.0,
       shapeBorder = CircleBorder(
         side: BorderSide(color: borderColor ?? Colors.transparent, width: 1),
       );

  RFabOutlined.smallNoBorder({
    required this.icon,
    required this.onPressed,
    required this.backgroundColor,
    super.key,
  }) : borderColor = Colors.transparent,
       radius = 40.0,
       shapeBorder = CircleBorder(
         side: BorderSide(color: Colors.transparent, width: 1),
       );

  //endregion

  //region Add
  RFabOutlined.smallAdd({VoidCallback? onPressed, Key? key})
    : this.small(
        key: key,
        onPressed: onPressed,
        backgroundColor: AppColor.greenNormal,
        borderColor: AppColor.greenNormal,
        icon: Assets.vec.addSvg.svg(
          colorFilter: ColorFilter.mode(
            onPressed != null
                ? AppColor.greenNormal
                : AppColor.greenNormal.disabledColor,
            BlendMode.srcIn,
          ),
        ),
      );

  RFabOutlined.smallAddNoBorder({VoidCallback? onPressed, Key? key})
    : this.smallNoBorder(
        key: key,
        onPressed: onPressed,
        backgroundColor: AppColor.greenNormal,

        icon: Assets.vec.addSvg.svg(
          colorFilter: ColorFilter.mode(
            onPressed != null
                ? AppColor.greenNormal
                : AppColor.greenNormal.disabledColor,
            BlendMode.srcIn,
          ),
        ),
      );

  RFabOutlined.add({VoidCallback? onPressed, Key? key})
    : this(
        key: key,
        onPressed: onPressed,
        backgroundColor: AppColor.greenNormal,
        borderColor: AppColor.greenNormal,
        icon: Assets.vec.addSvg.svg(
          colorFilter: ColorFilter.mode(
            onPressed != null
                ? AppColor.greenNormal
                : AppColor.greenNormal.disabledColor,
            BlendMode.srcIn,
          ),
        ),
      );

  RFabOutlined.addNoBorder({VoidCallback? onPressed, Key? key})
    : this.noBorder(
        key: key,
        onPressed: onPressed,
        backgroundColor: AppColor.greenNormal,
        icon: Assets.vec.addSvg.svg(
          colorFilter: ColorFilter.mode(
            onPressed != null
                ? AppColor.greenNormal
                : AppColor.greenNormal.disabledColor,
            BlendMode.srcIn,
          ),
        ),
      );

  //endregion

  //region Edit
  RFabOutlined.smallEdit({VoidCallback? onPressed, Key? key})
    : this.small(
        key: key,
        onPressed: onPressed,
        backgroundColor: AppColor.blueNormal,
        borderColor: AppColor.blueNormal,
        icon: Assets.vec.editSvg.svg(
          colorFilter: ColorFilter.mode(
            onPressed != null
                ? AppColor.blueNormal
                : AppColor.blueNormal.disabledColor,
            BlendMode.srcIn,
          ),
        ),
      );

  RFabOutlined.smallEditNoBorder({VoidCallback? onPressed, Key? key})
    : this.smallNoBorder(
        key: key,
        onPressed: onPressed,
        backgroundColor: AppColor.blueNormal,
        icon: Assets.vec.editSvg.svg(
          colorFilter: ColorFilter.mode(
            onPressed != null
                ? AppColor.blueNormal
                : AppColor.blueNormal.disabledColor,
            BlendMode.srcIn,
          ),
        ),
      );

  RFabOutlined.edit({VoidCallback? onPressed, Key? key})
    : this(
        key: key,
        onPressed: onPressed,
        backgroundColor: AppColor.blueNormal,
        borderColor: AppColor.blueNormal,
        icon: Assets.vec.editSvg.svg(
          colorFilter: ColorFilter.mode(
            onPressed != null
                ? AppColor.blueNormal
                : AppColor.blueNormal.disabledColor,
            BlendMode.srcIn,
          ),
        ),
      );

  RFabOutlined.editNoBorder({VoidCallback? onPressed, Key? key})
    : this.noBorder(
        key: key,
        onPressed: onPressed,
        backgroundColor: AppColor.blueNormal,
        icon: Assets.vec.editSvg.svg(
          colorFilter: ColorFilter.mode(
            onPressed != null
                ? AppColor.blueNormal
                : AppColor.blueNormal.disabledColor,
            BlendMode.srcIn,
          ),
        ),
      );

  //endregion

  //region Delete
  RFabOutlined.smallDelete({VoidCallback? onPressed, Key? key})
    : this.small(
        key: key,
        onPressed: onPressed,
        backgroundColor: AppColor.redNormal,
        borderColor: AppColor.redNormal,
        icon: Assets.vec.trashSvg.svg(
          colorFilter: ColorFilter.mode(
            onPressed != null
                ? AppColor.redNormal
                : AppColor.redNormal.disabledColor,
            BlendMode.srcIn,
          ),
        ),
      );

  RFabOutlined.smallDeleteNoBorder({VoidCallback? onPressed, Key? key})
    : this.smallNoBorder(
        key: key,
        onPressed: onPressed,
        backgroundColor: AppColor.redNormal,
        icon: Assets.vec.trashSvg.svg(
          colorFilter: ColorFilter.mode(
            onPressed != null
                ? AppColor.redNormal
                : AppColor.redNormal.disabledColor,
            BlendMode.srcIn,
          ),
        ),
      );

  RFabOutlined.delete({VoidCallback? onPressed, Key? key})
    : this(
        key: key,
        onPressed: onPressed,
        backgroundColor: AppColor.redNormal,
        borderColor: AppColor.redNormal,
        icon: Assets.vec.trashSvg.svg(
          colorFilter: ColorFilter.mode(
            onPressed != null
                ? AppColor.redNormal
                : AppColor.redNormal.disabledColor,
            BlendMode.srcIn,
          ),
        ),
      );

  RFabOutlined.deleteNoBorder({VoidCallback? onPressed, Key? key})
    : this.noBorder(
        key: key,
        onPressed: onPressed,
        backgroundColor: AppColor.redNormal,
        icon: Assets.vec.trashSvg.svg(
          colorFilter: ColorFilter.mode(
            onPressed != null
                ? AppColor.redNormal
                : AppColor.redNormal.disabledColor,
            BlendMode.srcIn,
          ),
        ),
      );

  //endregion

  //region Action
  RFabOutlined.smallAction({VoidCallback? onPressed, Key? key})
    : this.small(
        key: key,
        onPressed: onPressed,
        backgroundColor: AppColor.blueNormal,
        borderColor: AppColor.blueNormal,
        icon: Assets.vec.scanSvg.svg(
          colorFilter: ColorFilter.mode(
            onPressed != null
                ? AppColor.blueNormal
                : AppColor.blueNormal.disabledColor,
            BlendMode.srcIn,
          ),
        ),
      );

  RFabOutlined.smallActionNoBorder({VoidCallback? onPressed, Key? key})
    : this.smallNoBorder(
        key: key,
        onPressed: onPressed,
        backgroundColor: AppColor.blueNormal,
        icon: Assets.vec.scanSvg.svg(
          colorFilter: ColorFilter.mode(
            onPressed != null
                ? AppColor.blueNormal
                : AppColor.blueNormal.disabledColor,
            BlendMode.srcIn,
          ),
        ),
      );

  RFabOutlined.action({VoidCallback? onPressed, Key? key})
    : this(
        key: key,
        onPressed: onPressed,
        backgroundColor: AppColor.blueNormal,
        borderColor: AppColor.blueNormal,
        icon: Assets.vec.scanSvg.svg(
          colorFilter: ColorFilter.mode(
            onPressed != null
                ? AppColor.blueNormal
                : AppColor.blueNormal.disabledColor,
            BlendMode.srcIn,
          ),
        ),
      );

  RFabOutlined.actionNoBorder({VoidCallback? onPressed, Key? key})
    : this.noBorder(
        key: key,
        onPressed: onPressed,
        backgroundColor: AppColor.blueNormal,
        icon: Assets.vec.scanSvg.svg(
          colorFilter: ColorFilter.mode(
            onPressed != null
                ? AppColor.blueNormal
                : AppColor.blueNormal.disabledColor,
            BlendMode.srcIn,
          ),
        ),
      );

  //endregion

  //region Filter
  RFabOutlined.smallFilter({VoidCallback? onPressed, Key? key})
    : this.small(
        key: key,
        onPressed: onPressed,
        backgroundColor: AppColor.blueNormal,
        borderColor: AppColor.blueNormal,
        icon: Assets.vec.filterSvg.svg(
          colorFilter: ColorFilter.mode(
            onPressed != null
                ? AppColor.blueNormal
                : AppColor.blueNormal.disabledColor,
            BlendMode.srcIn,
          ),
        ),
      );

  RFabOutlined.smallFilterNoBorder({VoidCallback? onPressed, Key? key})
    : this.smallNoBorder(
        key: key,
        onPressed: onPressed,
        backgroundColor: AppColor.blueNormal,
        icon: Assets.vec.filterSvg.svg(
          colorFilter: ColorFilter.mode(
            onPressed != null
                ? AppColor.blueNormal
                : AppColor.blueNormal.disabledColor,
            BlendMode.srcIn,
          ),
        ),
      );

  RFabOutlined.filter({VoidCallback? onPressed, Key? key})
    : this(
        key: key,
        onPressed: onPressed,
        backgroundColor: AppColor.blueNormal,
        borderColor: AppColor.blueNormal,
        icon: Assets.vec.filterSvg.svg(
          colorFilter: ColorFilter.mode(
            onPressed != null
                ? AppColor.blueNormal
                : AppColor.blueNormal.disabledColor,
            BlendMode.srcIn,
          ),
        ),
      );

  RFabOutlined.filterNoBorder({VoidCallback? onPressed, Key? key})
    : this.noBorder(
        key: key,
        onPressed: onPressed,
        backgroundColor: AppColor.blueNormal,
        icon: Assets.vec.filterSvg.svg(
          colorFilter: ColorFilter.mode(
            onPressed != null
                ? AppColor.blueNormal
                : AppColor.blueNormal.disabledColor,
            BlendMode.srcIn,
          ),
        ),
      );

  //endregion

  //region Download
  RFabOutlined.smallDownload({VoidCallback? onPressed, Key? key})
    : this.small(
        key: key,
        onPressed: onPressed,
        backgroundColor: AppColor.blueNormal,
        borderColor: AppColor.blueNormal,
        icon: Assets.vec.downloadSvg.svg(
          colorFilter: ColorFilter.mode(
            onPressed != null
                ? AppColor.greenNormal
                : AppColor.greenNormal.disabledColor,
            BlendMode.srcIn,
          ),
        ),
      );

  RFabOutlined.smallDownloadNoBorder({VoidCallback? onPressed, Key? key})
    : this.smallNoBorder(
        key: key,
        onPressed: onPressed,
        backgroundColor: AppColor.blueNormal,
        icon: Assets.vec.downloadSvg.svg(
          colorFilter: ColorFilter.mode(
            onPressed != null
                ? AppColor.greenNormal
                : AppColor.greenNormal.disabledColor,
            BlendMode.srcIn,
          ),
        ),
      );

  RFabOutlined.download({VoidCallback? onPressed, Key? key})
    : this(
        key: key,
        onPressed: onPressed,
        backgroundColor: AppColor.blueNormal,
        borderColor: AppColor.blueNormal,
        icon: Assets.vec.downloadSvg.svg(
          colorFilter: ColorFilter.mode(
            onPressed != null
                ? AppColor.greenNormal
                : AppColor.greenNormal.disabledColor,
            BlendMode.srcIn,
          ),
        ),
      );

  RFabOutlined.downloadNoBorder({VoidCallback? onPressed, Key? key})
    : this.noBorder(
        key: key,
        onPressed: onPressed,
        backgroundColor: AppColor.blueNormal,
        icon: Assets.vec.downloadSvg.svg(
          colorFilter: ColorFilter.mode(
            onPressed != null
                ? AppColor.greenNormal
                : AppColor.greenNormal.disabledColor,
            BlendMode.srcIn,
          ),
        ),
      );

  //endregion

  //region Excel
  RFabOutlined.smallExcel({VoidCallback? onPressed, Key? key})
    : this.small(
        key: key,
        onPressed: onPressed,
        backgroundColor: AppColor.greenDark,
        borderColor: AppColor.greenDark,
        icon: Assets.vec.excelDownloadSvg.svg(
          colorFilter: ColorFilter.mode(
            onPressed != null
                ? AppColor.greenNormal
                : AppColor.greenNormal.disabledColor,
            BlendMode.srcIn,
          ),
        ),
      );

  RFabOutlined.smallExcelNoBorder({VoidCallback? onPressed, Key? key})
    : this.noBorder(
        key: key,
        onPressed: onPressed,
        backgroundColor: AppColor.greenDark,
        icon: Assets.vec.excelDownloadSvg.svg(
          colorFilter: ColorFilter.mode(
            onPressed != null
                ? AppColor.greenNormal
                : AppColor.greenNormal.disabledColor,
            BlendMode.srcIn,
          ),
        ),
      );

  RFabOutlined.excel({VoidCallback? onPressed, Key? key})
    : this(
        key: key,
        onPressed: onPressed,
        backgroundColor: AppColor.greenDark,
        borderColor: AppColor.greenDark,
        icon: Assets.vec.excelDownloadSvg.svg(
          colorFilter: ColorFilter.mode(
            onPressed != null
                ? AppColor.greenNormal
                : AppColor.greenNormal.disabledColor,
            BlendMode.srcIn,
          ),
        ),
      );

  RFabOutlined.excelNoBorder({VoidCallback? onPressed, Key? key})
    : this.noBorder(
        key: key,
        onPressed: onPressed,
        backgroundColor: AppColor.greenDark,
        icon: Assets.vec.excelDownloadSvg.svg(
          colorFilter: ColorFilter.mode(
            onPressed != null
                ? AppColor.greenNormal
                : AppColor.greenNormal.disabledColor,
            BlendMode.srcIn,
          ),
        ),
      );

  //endregion

  //region Back
  RFabOutlined.smallBack({VoidCallback? onPressed, Key? key})
    : this.small(
        key: key,
        onPressed: onPressed,
        backgroundColor: AppColor.blueNormal,
        borderColor: AppColor.blueNormal,
        icon: Assets.vec.arrowLeftSvg.svg(
          colorFilter: ColorFilter.mode(
            onPressed != null
                ? AppColor.blueNormal
                : AppColor.blueNormal.disabledColor,
            BlendMode.srcIn,
          ),
        ),
      );

  RFabOutlined.smallBackNoBorder({VoidCallback? onPressed, Key? key})
    : this.smallNoBorder(
        key: key,
        onPressed: onPressed,
        backgroundColor: AppColor.blueNormal,
        icon: Assets.vec.arrowLeftSvg.svg(
          colorFilter: ColorFilter.mode(
            onPressed != null
                ? AppColor.blueNormal
                : AppColor.blueNormal.disabledColor,
            BlendMode.srcIn,
          ),
        ),
      );

  RFabOutlined.back({VoidCallback? onPressed, Key? key})
    : this(
        key: key,
        onPressed: onPressed,
        backgroundColor: AppColor.blueNormal,
        borderColor: AppColor.blueNormal,
        icon: Assets.vec.arrowLeftSvg.svg(
          colorFilter: ColorFilter.mode(
            onPressed != null
                ? AppColor.blueNormal
                : AppColor.blueNormal.disabledColor,
            BlendMode.srcIn,
          ),
        ),
      );

  RFabOutlined.backNoBorder({VoidCallback? onPressed, Key? key})
    : this.noBorder(
        key: key,
        onPressed: onPressed,
        backgroundColor: AppColor.blueNormal,
        icon: Assets.vec.arrowLeftSvg.svg(
          colorFilter: ColorFilter.mode(
            onPressed != null
                ? AppColor.blueNormal
                : AppColor.blueNormal.disabledColor,
            BlendMode.srcIn,
          ),
        ),
      );

  //endregion
}

class _RFabOutlinedState extends State<RFabOutlined> {
  bool isOnPressed = false;

  @override
  Widget build(BuildContext context) {
    return OutlinedButton(
      onPressed: widget.onPressed,
      style: ButtonStyle(
        side: WidgetStateProperty.resolveWith<BorderSide?>((states) {
          if (states.contains(WidgetState.disabled)) {
            return BorderSide(
              color:
                  widget.borderColor?.disabledColor ??
                  AppColor.blueNormal.disabledColor,
              width: 2,
            );
          }
          return BorderSide(
            color: widget.borderColor ?? AppColor.blueNormal,
            width: 2,
          );
        }),
        backgroundColor: WidgetStateProperty.resolveWith<Color?>((states) {
          if (states.contains(WidgetState.pressed)) {
            return widget.backgroundColor;
          } else if (states.contains(WidgetState.hovered)) {
            return widget.backgroundColor.hoverColor ??
                AppColor.blueNormal.hoverColor;
          } else if (states.contains(WidgetState.disabled)) {
            return widget.backgroundColor.disabledColor ??
                AppColor.blueNormal.disabledColor;
          }
          return Colors.transparent;
        }),
        foregroundColor: WidgetStateProperty.resolveWith<Color?>((states) {
          if (states.contains(WidgetState.pressed)) {
            return Colors.white;
          } else if (states.contains(WidgetState.disabled)) {
            return widget.backgroundColor.disabledColor ??
                AppColor.blueNormal.disabledColor;
          }
          return widget.backgroundColor;
        }),

        shape: WidgetStatePropertyAll(widget.shapeBorder),
        fixedSize: WidgetStatePropertyAll(
          Size(widget.radius ?? 56, widget.radius ?? 56),
        ),
        padding: WidgetStatePropertyAll(EdgeInsets.zero),
      ),
      child: widget.icon,
    );
  }
}
