import 'package:flutter/material.dart';
import 'package:sigap/src/utils/constants/sizes.dart';

enum SocialButtonShapeType { defaultShape, rounded, circular }

class SocialButton extends StatelessWidget {
  final String? text;
  final Icon? icon;
  final String? iconImage;
  final double? iconImageWidth;
  final double? iconImageHeight;
  final VoidCallback onPressed;
  final Color? backgroundColor;
  final Color? foregroundColor;
  final Color? borderColor;
  final bool isVisible;
  final SocialButtonShapeType shapeType;

  const SocialButton({
    super.key,
    this.text,
    this.icon,
    this.iconImage,
    this.iconImageWidth,
    this.iconImageHeight,
    required this.onPressed,
    this.backgroundColor,
    this.foregroundColor,
    this.borderColor,
    this.isVisible = true,
    this.shapeType = SocialButtonShapeType.defaultShape,
  });

  @override
  Widget build(BuildContext context) {
    if (!isVisible) return const SizedBox.shrink();

    OutlinedBorder shape;
    EdgeInsetsGeometry padding;

    switch (shapeType) {
      case SocialButtonShapeType.rounded:
        shape = RoundedRectangleBorder(borderRadius: BorderRadius.circular(30));
        padding = const EdgeInsets.symmetric(
          vertical: TSizes.md,
          horizontal: TSizes.md,
        );
        break;
      case SocialButtonShapeType.circular:
        shape = const CircleBorder();
        padding = const EdgeInsets.all(0);
        break;
      default:
        shape = RoundedRectangleBorder(
          borderRadius: BorderRadius.circular(TSizes.buttonRadius),
        );
        padding = const EdgeInsets.symmetric(
          vertical: TSizes.md,
          horizontal: TSizes.md,
        );
    }

    Widget iconWidget =
        iconImage == null
            ? icon ?? const SizedBox.shrink()
            : Image.asset(
              iconImage!,
              width: iconImageWidth,
              height: iconImageHeight,
            );

    Widget child;
    if (text == null || text!.isEmpty) {
      child = iconWidget;
    } else {
      child = Row(
        mainAxisAlignment: MainAxisAlignment.center,
        mainAxisSize: MainAxisSize.min,
        children: [
          SizedBox(height: 24, width: 24, child: iconWidget),
          const SizedBox(width: TSizes.md),
          Text(
            text!,
            style: Theme.of(context).textTheme.bodyLarge?.copyWith(
              color: foregroundColor ?? Colors.black,
              fontWeight: FontWeight.w500,
            ),
          ),
        ],
      );
    }

    return SizedBox(
      width: shapeType == SocialButtonShapeType.circular ? 48 : double.infinity,
      height: shapeType == SocialButtonShapeType.circular ? 48 : null,
      child: OutlinedButton(
        onPressed: onPressed,
        style: OutlinedButton.styleFrom(
          backgroundColor: backgroundColor ?? Colors.white,
          foregroundColor: foregroundColor ?? Colors.black,
          side: BorderSide(color: borderColor ?? Colors.grey.shade300),
          shape: shape,
          padding: padding,
        ),
        child: child,
      ),
    );
  }
}
