class FormObject {
  String? label;
  dynamic defaultValue;
  int? span;
  String? key;
  String? type;
  bool? border;
  dynamic disabledValue;
  List<Option>? options;
  List<FormObject>? children;
  String? append;
  String? placeholder;
  bool? required;
  bool? showLimit;
  String? parentKey;
  String? buttonName;
  List? childrenKey;

  FormObject({
    this.label,
    this.defaultValue,
    this.span,
    this.key,
    this.type,
    this.border,
    this.disabledValue,
    this.options,
    this.children,
    this.append,
    this.placeholder,
    this.required,
    this.showLimit,
    this.parentKey,
    this.buttonName,
    this.childrenKey,
  });

  factory FormObject.fromJson(Map<String, dynamic> json) {
    var optionsList = json['options'] == null ? null : json['options'] as List;
    List<Option>? options =
        optionsList?.map((item) => Option.fromJson(item)).toList();

    return FormObject(
      label: json['label'],
      defaultValue: json['defaultValue'],
      span: json['span'],
      key: json['key'],
      type: json['type'],
      border: json['border'],
      disabledValue: json['disabledValue'],
      options: options,
      children: json['children'] != null
          ? List<FormObject>.from(json['children'])
          : null,
      append: json['append'],
      placeholder: json['placeholder'],
      required: json['required'],
      showLimit: json['show-limit'],
      parentKey: json['parentKey'],
      buttonName: json['buttonName'],
      childrenKey:
          json['childrenKey'] == null ? null : json['childrenKey'] as List,
    );
  }

  Map<String, dynamic> toJson() {
    List<Map<String, dynamic>> optionsList =
        options != null ? options!.map((item) => item.toJson()).toList() : [];

    return {
      'label': label,
      'defaultValue': defaultValue,
      'span': span,
      'key': key,
      'type': type,
      'border': border,
      'disabledValue': disabledValue,
      'options': optionsList,
      'children': children,
      'append': append,
      'placeholder': placeholder,
      'required': required,
      'show-limit': showLimit,
      'parentKey': parentKey,
      'buttonName': buttonName,
      'childrenKey': childrenKey
    };
  }
}

class Option {
  String? label;
  String? value;

  Option({this.label, this.value});

  factory Option.fromJson(Map<String, dynamic> json) {
    return Option(
      label: json['label'],
      value: json['value'],
    );
  }

  Map<String, dynamic> toJson() {
    return {
      'label': label,
      'value': value,
    };
  }
}

class MenuItem {
  // 显示的文本
  String label;
  // 选中的值
  dynamic value;
  // 是否选中
  bool checked;

  MenuItem({this.label = '', this.value, this.checked = false});
}
