import 'package:fis_ui/index.dart';
import 'package:fis_ui/interface/interactive_container.dart';
import 'package:flutter/material.dart';
import 'package:fis_theme/theme.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

class LabeledCheckbox extends StatelessWidget implements FInteractiveContainer {
  LabeledCheckbox({
    Key? key,
    required this.label,
    required this.padding,
    required this.value,
    required this.onChanged,
    this.mainAxisAlignment = MainAxisAlignment.start,
    this.pageName = 'LabeledCheckbox',
  }) : super(key: key);

  @override
  final String pageName;

  /// 选择框文案
  final FWidget label;

  final MainAxisAlignment mainAxisAlignment;

  /// 间距
  final EdgeInsets padding;

  /// 选择值
  final bool value;

  /// 选择回调
  final Function onChanged;

  @override
  FWidget build(BuildContext context) {
    final labeledCheckboxbody = FPadding(
      padding: padding,
      child: FFlex(
        direction: Axis.horizontal,
        mainAxisAlignment: mainAxisAlignment,
        children: [
          FSizedBox(
            width: 28.sp,
            child: FMaterialCheckbox(
              value: value,
              checkColor: Colors.white,
              shape: RoundedRectangleBorder(
                side: BorderSide.none,
                borderRadius: BorderRadius.circular(4.sp),
              ),
              activeColor: FTheme.ins.colorScheme.primary,
              onChanged: (bool? newValue) {
                onChanged(newValue);
              },
            ),
          ),
          FFlexible(
            flex: 0,
            child: label,
          ),
        ],
      ),
    );
    return FGestureDetector(
      businessParent: this,
      name: "ChangedValue:$value",
      child: labeledCheckboxbody,
      onTap: () => onChanged(!value),
    );
  }
}
