import 'package:flutter/material.dart';
import 'package:zap_stream_flutter/theme.dart';

class BasicButton extends StatelessWidget {
  final Widget? child;
  final BoxDecoration? decoration;
  final EdgeInsetsGeometry? padding;
  final EdgeInsetsGeometry? margin;
  final void Function()? onTap;
  final bool? disabled;

  const BasicButton(
    this.child, {
    super.key,
    this.decoration,
    this.padding,
    this.margin,
    this.onTap,
    this.disabled,
  });

  static text(
    String text, {
    BoxDecoration? decoration,
    EdgeInsetsGeometry? padding,
    EdgeInsetsGeometry? margin,
    void Function()? onTap,
    double? fontSize,
    bool? disabled,
  }) {
    return BasicButton(
      Text(
        text,
        style: TextStyle(
          color: Color.fromARGB(255, 255, 255, 255),
          fontSize: fontSize,
          fontWeight: FontWeight.bold,
        ),
      ),
      disabled: disabled,
      decoration: decoration,
      padding: padding ?? EdgeInsets.symmetric(vertical: 4, horizontal: 12),
      margin: margin,
      onTap: onTap,
    );
  }

  @override
  Widget build(BuildContext context) {
    final defaultBr = BorderRadius.all(Radius.circular(100));
    final inner = Container(
      padding: padding,
      margin: margin,
      decoration:
          decoration ?? BoxDecoration(color: LAYER_2, borderRadius: defaultBr),
      child: Center(child: child),
    );
    return GestureDetector(
      onTap: () {
        if (!(disabled ?? false) && onTap != null) {
          onTap!();
        }
      },
      child: (disabled ?? false) ? Opacity(opacity: 0.5, child: inner) : inner,
    );
  }
}
