import 'package:auto_size_text/auto_size_text.dart';
import 'package:flutter/material.dart';
import 'package:satu/shared/app_colors.dart';
import 'package:satu/shared/shared_styles.dart';

/// A button that shows a busy indicator in place of title
class AmanIconButton extends StatefulWidget {
  final bool busy;
  final String title;
  final Function onPressed;
  final bool? enabled;
  final Color mainColor;
  final IconData icon;
  const AmanIconButton(
      {
        required this.title,
        this.busy = false,
        required this.onPressed,
        this.enabled = true,
        required this.mainColor,
        required this.icon
      });

  @override
  _AmanIconButtonState createState() => _AmanIconButtonState();
}

class _AmanIconButtonState extends State<AmanIconButton> {
  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      child: InkWell(
        borderRadius: BorderRadius.circular(6),
        onTap: () {
          if(!widget.busy) {
            widget.onPressed();
          }
        },
        child: Container(
          //height: 75,
          width: 120,
          alignment: Alignment.center,
          padding: EdgeInsets.symmetric(
              //horizontal: 25,
              vertical: 15),
          decoration: BoxDecoration(
            borderRadius: BorderRadius.circular(6),
            border: Border.all( width: 1.0, color: widget.mainColor )
          ),
          child:  Column(
              children: <Widget>[
                (!widget.busy
                    ? Icon(
            widget.icon,
            color: widget.mainColor,
            size: 36,
          )
                    : CircularProgressIndicator(
            strokeWidth: 3,
            valueColor: AlwaysStoppedAnimation<Color>(widget.mainColor))),
                AutoSizeText(widget.title, overflow: TextOverflow.fade, maxLines: 2, style: TextStyle(color: widget.mainColor, fontSize: 14, fontWeight: FontWeight.w800, ), textAlign: TextAlign.center,)
              ],
            ),
        ),
      ),
    );
  }
}
