package org.example.Entity.Control.Container;

import com.fasterxml.jackson.annotation.JsonProperty;
import org.example.Entity.Control.Fields.Field;
import org.example.Utils.DataTableUtil;
import org.example.Utils.IPublicUtil;

import java.util.Map;

public class FieldSet extends Field {

    public FieldSet(Map<String, Object> row) {
        super(row);
        this.defaultXtype = "fieldset";
    }

    public FieldSet(Map<String, Object> row, IPublicUtil util) {
        super(row, util);
        this.defaultXtype = "fieldset";
    }

    /**
     * 标题，从FieldCaption或GroupName字段获取
     */

    public String getTitle() {
        Object value = DataTableUtil.get(_row, new String[]{"FieldCaption", "GroupName"}, "");
        return value != null ? value.toString() : "";
    }

    /**
     * 是否折叠，基于isexpand字段判断
     */
    public boolean isCollapsed() {
        Object value = _row.getOrDefault("isexpand", "1");
        if (value == null) return false;
        if (value instanceof Boolean) return !(Boolean) value;
        String strValue = (String) value;
        return !("1".equals(strValue) || "true".equalsIgnoreCase(strValue));
    }

}