import { cloneDeep } from "./cloneDeep"

/**
 * 清除对象属性的默认值
 * @param model 
 */
export function clearData(data: Recordable) {
    const model = cloneDeep(data);
    const keys = Object.keys(model);
    const emptyObj = keys.reduce((acc, key) => {
        if (Array.isArray(model[key])) {
            acc[key] = [];
        } else if (typeof model[key] === 'object') {
            acc[key] = null;
        } else if (typeof model[key] === 'number') {
            acc[key] = 0;
        } else if (typeof model[key] === 'boolean') {
            acc[key] = false;
        } else {
            acc[key] = "";
        }
        return acc;
    }, {});
    return emptyObj;
}