export const defineMetaProperty = (constructor, key, value) => {
    Object.defineProperty(constructor, key, {
        value,
        writable: false,
        enumerable: false,
        configurable: false,
    });
};
export const getFieldTypeName = (type) => {
    switch (type) {
        case String: return 'string';
        case Number: return 'number';
        case Boolean: return 'boolean';
        default: return 'string';
    }
};
export const mergeFields = (fields1, fields2) => {
    const fieldMap = new Map();
    fields1 === null || fields1 === void 0 ? void 0 : fields1.forEach((field) => {
        fieldMap.set(field.name, field);
    });
    fields2 === null || fields2 === void 0 ? void 0 : fields2.forEach((field) => {
        fieldMap.set(field.name, field);
    });
    return Array.from(fieldMap.values());
};
export const getFieldInitialValue = (type) => {
    switch (type) {
        case 'string': return '';
        case 'number': return 0;
        case 'boolean': return false;
        case 'select': return '';
        case 'multiselect': return [];
        case 'multitext': return [];
        case 'color': return '#ffffff';
        case 'file': return '';
        case 'range': return 0;
        default: return '';
    }
};
export const getInitialStateFromFields = (fields) => fields.reduce((acc, field) => {
    var _a;
    acc[field.name] = (_a = field.initialValue) !== null && _a !== void 0 ? _a : getFieldInitialValue(field.type);
    return acc;
}, {});
export const buildInitialState = (fields, getInitialState) => {
    var _a;
    return (Object.assign(Object.assign({}, ((_a = getInitialState === null || getInitialState === void 0 ? void 0 : getInitialState()) !== null && _a !== void 0 ? _a : {})), getInitialStateFromFields(fields)));
};
export const isEditor = () => Boolean(window.DachaWorkbench);
