import 'package:fis_theme/theme.dart';
import 'package:fis_ui/index.dart';
import 'package:flutter/material.dart';
import 'package:flyinsono/views/desktop/remote_maintenance/widgets/apiinfo.dart';
import 'package:flyinsono/views/desktop/remote_maintenance/widgets/custom_button.dart';

class CustomValueButton extends FStatefulWidget {
  const CustomValueButton({
    super.key,
    required this.title,
    required this.data,
    required this.onChange,
    this.consultationCode,
    this.width = 120,
    this.decoration,
    this.textColor,
  });
  final String title;
  final ApiInfo data;
  final String? consultationCode;
  final double width;
  final BoxDecoration? decoration;
  final Color? textColor;
  final ValueCallback onChange;

  @override
  FState<FStatefulWidget> createState() {
    return FCustomValueButtonState();
  }
}

class FCustomValueButtonState extends FState<CustomValueButton> {
  @override
  FWidget build(BuildContext context) {
    return FContainer(
      decoration: widget.decoration ??
          BoxDecoration(
              border: Border.all(
                color: FTheme.ins.colorScheme.line,
                width: 0.5,
              ),
              color: Colors.white,
              borderRadius: BorderRadius.all(Radius.circular(8))),
      child: FColumn(
        children: [
          FContainer(
            width: widget.width,
            height: 25,
            child: FText(
              widget.title,
              textAlign: TextAlign.center,
              style: TextStyle(color: widget.textColor),
            ),
          ),
          CustomButton<ApiInfo>(
            data: widget.data,
            textColor: Colors.white,
            decoration: widget.decoration,
            onPressed: (value) async {
              widget.onChange.call(value);
            },
            isDecreaseAndIncrease:
                widget.data.valuesMapString == 'Increase:1;Decrease:-1',
            canExecute: widget.data.canExecute ?? false,
            text: widget.data.displayValue ?? '',
            width: widget.width,
          ),
        ],
      ),
    );
  }
}
