package com.mortals.xhx.common.formdesign;


import com.mortals.framework.exception.AppException;
import com.mortals.xhx.common.code.ComponentEnum;
import com.mortals.xhx.common.formdesign.component.*;
import com.mortals.xhx.common.pdu.gen.FieldsItem;
import com.mortals.xhx.common.pdu.gen.component.*;

public abstract class DesignComponent  {

    private String type;

    public DesignComponent(String type) {
        this.type = type;
    }

    public abstract ListItem buildDefaultComponent(ComponentCons cons);


    public static DesignComponent createType(String type) {

        if (type.equals(ComponentEnum.INPUT.getValue())) {
            return new DesignInputComponent(type);
        } else if (type.equals(ComponentEnum.TEXTAREA.getValue())) {
            return new DesignTextAreaComponent(type);
        } else if (type.equals(ComponentEnum.SELECT.getValue())) {
            return new DesignSelectComponent(type);
        } else if (type.equals(ComponentEnum.CHECKBOX.getValue())) {
            return new DesignCheckboxComponent(type);
        }  else if (type.equals(ComponentEnum.RADIO.getValue())) {
            return new DesignRadioComponent(type);
        }else if (type.equals(ComponentEnum.BUTTON.getValue())) {
            return new DesignButtonComponent(type);
        } else if (type.equals(ComponentEnum.DATE.getValue())) {
            return new DesignDateComponent(type);
        } else if (type.equals(ComponentEnum.IMAGE.getValue())) {
            return new DesignImageComponent(type);
        } else if (type.equals(ComponentEnum.DYNAMIC_TABLE.getValue())) {
            return new DesignDynamicTableComponent(type);
        }
//        else if (type.equals(ComponentEnum.AREA.getValue())) {
//            return new AreaComponent(type);
//        }
        else {
            throw new AppException(String.format("不支持当前组件类型,Type:%s", type));
        }
    }

    
    public abstract String getType();


    public static void main(String[] args) {

    }
}
