import 'package:flutter/material.dart';

class DetailBottomRow extends StatefulWidget {
  final void Function()? onCancel;
  final void Function()? onAction;
  final void Function()? onMiddleAction;
  final String actionText;
  final String middleActionText;
  final IconData actionIcon;
  final IconData middleActionIcon;

  const DetailBottomRow(
      {Key? key,
      required this.onCancel,
      required this.onAction,
      this.onMiddleAction,
      this.actionText = 'SAVE',
      this.actionIcon = Icons.save,
      this.middleActionText = 'SAVE & CLOSE',
      this.middleActionIcon = Icons.done})
      : super(key: key);

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

class _DetailBottomRowState<T> extends State<DetailBottomRow> {
  @override
  Widget build(BuildContext context) {
    return BottomAppBar(
      child: Padding(
        padding: const EdgeInsets.all(10.0),
        child: Row(
          mainAxisAlignment: MainAxisAlignment.spaceBetween,
          children: [
            ElevatedButton.icon(
              onPressed: widget.onCancel,
              icon: const Icon(
                Icons.close,
                size: 18.0,
              ),
              label: const Text('CANCEL'),
            ),
            widget.onMiddleAction != null
                ? ElevatedButton.icon(
                    onPressed: widget.onMiddleAction,
                    icon: Icon(
                      widget.middleActionIcon,
                      size: 18.0,
                    ),
                    label: Text(widget.middleActionText),
                  )
                : const Spacer(),
            ElevatedButton.icon(
              onPressed: widget.onAction,
              icon: Icon(
                widget.actionIcon,
                size: 18.0,
              ),
              label: Text(widget.actionText),
            ),
          ],
        ),
      ),
    );
  }
}
