import 'package:fis_ui/base_define/page.dart';
import 'package:fis_ui/index.dart';
import 'package:fis_ui/values/spacings.dart';
import 'package:flutter/material.dart';

///操作设备按钮
class DeviceOperateButton extends FStatefulWidget {
  DeviceOperateButton({
    Key? key,
    required this.onPressed,
    required this.icon,
    required this.businessParent,
    this.text,
    this.borderWidth,
    this.width,
  }) : super(key: key);

  ///父级节点
  final FPage businessParent;
  final VoidCallback? onPressed;
  final String? text;
  final FIcon icon;
  final double? borderWidth;
  final double? width;

  @override
  FState<DeviceOperateButton> createState() => _NoBorderIconState();
}

class _NoBorderIconState extends FState<DeviceOperateButton> {
  FWidget textButton(String textString, Function onPressed) {
    return FContainer(
      width: 100,
      margin: EdgeInsets.only(right: FSpacings.MINI_BUTTON),
      child: FOutlinedButton(
        name: textString,
        businessParent: widget.businessParent,
        onPressed: () => onPressed.call(),
        child: FCenter(
          child: FText(
            textString,
            style: TextStyle(color: Colors.black),
          ),
        ),
        style: ButtonStyle(
          padding: MaterialStateProperty.all(
            EdgeInsets.symmetric(
              vertical: 8,
            ),
          ),
        ),
      ),
    );
  }

  @override
  FWidget build(BuildContext context) {
    return FGestureDetector(
      businessParent: widget.businessParent,
      name: "${widget.text}",
      onTap: () async {
        widget.onPressed!.call();
      },
      child: FContainer(
        height: 34,
        child: FMouseRegion(
          cursor: SystemMouseCursors.click,
          child: FCenter(
            child: textButton(
              widget.text ?? "",
              () {
                widget.onPressed!.call();
              },
            ),
          ),
        ),
      ),
    );
  }
}
