import 'package:flutter/material.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'package:syncrow_web/pages/common/buttons/default_button.dart';
import 'package:syncrow_web/utils/color_manager.dart';

class CommunityStructureHeaderButton extends StatelessWidget {
  const CommunityStructureHeaderButton({
    super.key,
    required this.label,
    this.icon,
    required this.onPressed,
    this.svgAsset,
    required this.theme,
  });

  final String label;
  final Widget? icon;
  final VoidCallback onPressed;
  final String? svgAsset;
  final ThemeData theme;

  @override
  Widget build(BuildContext context) {
    const double buttonHeight = 40;
    return ConstrainedBox(
      constraints: const BoxConstraints(
        maxWidth: 130,
        minHeight: buttonHeight,
      ),
      child: DefaultButton(
        onPressed: onPressed,
        borderWidth: 2,
        backgroundColor: ColorsManager.textFieldGreyColor,
        foregroundColor: ColorsManager.blackColor,
        borderRadius: 12.0,
        padding: 2.0,
        height: buttonHeight,
        elevation: 0,
        borderColor: ColorsManager.lightGrayColor,
        child: Row(
          mainAxisSize: MainAxisSize.min,
          children: [
            if (icon != null) icon!,
            if (svgAsset != null)
              SvgPicture.asset(
                svgAsset!,
                width: 20,
                height: 20,
              ),
            const SizedBox(width: 10),
            Flexible(
              child: Text(
                label,
                style: theme.textTheme.bodySmall
                    ?.copyWith(color: ColorsManager.blackColor, fontSize: 14),
                overflow: TextOverflow.ellipsis,
                maxLines: 1,
              ),
            ),
          ],
        ),
      ),
    );
  }
}
