import { FormArray } from '../form-array';
import { FormControl } from '../form-control';
import { FormGroup } from '../form-group';
export function ClassFormControlValidators(controlValidatators) {
    if (controlValidatators === void 0) { controlValidatators = []; }
    return function (constructor) {
        Object.defineProperty(constructor.prototype, "form-control-validators", {
            get: function () { return controlValidatators; }
        });
    };
}
export function PropertyFormControlValidators(controlValidatators) {
    if (controlValidatators === void 0) { controlValidatators = []; }
    return function (target, key) {
        Object.defineProperty(target, key + "-form-control-validators", {
            get: function () { return controlValidatators; }
        });
    };
}
export function PropertyFormControlSkip(target, key) {
    Object.defineProperty(target, key + "-form-control-skip", {
        get: function () { return true; }
    });
}
var FormBuilder = /** @class */ (function () {
    function FormBuilder() {
    }
    FormBuilder.Group = function (object) {
        var _this = this;
        var keys = Object.keys(object);
        var values = Object.values(object);
        return new FormGroup(values.reduce(function (acc, cur, index) {
            if (object[keys[index] + "-form-control-skip"]) {
                return acc;
            }
            if (Array.isArray(cur)) {
                acc[keys[index]] = _this.Array(cur, object[keys[index] + "-form-control-validators"] || []);
            }
            else if (typeof cur === 'object') {
                acc[keys[index]] = _this.Group(cur);
            }
            else {
                acc[keys[index]] = _this.Control(cur, object[keys[index] + "-form-control-validators"] || []);
            }
            return acc;
        }, {}), object['form-control-validators'] || []);
    };
    FormBuilder.Array = function (array, controlValidators) {
        var _this = this;
        if (controlValidators === void 0) { controlValidators = []; }
        return new FormArray(array.map(function (e) {
            if (Array.isArray(e)) {
                return _this.Array(e);
            }
            else if (typeof e === 'object') {
                return _this.Group(e);
            }
            else {
                return _this.Control(e);
            }
        }), controlValidators);
    };
    FormBuilder.Control = function (primitive, controlValidators) {
        if (controlValidators === void 0) { controlValidators = []; }
        return new FormControl(controlValidators, {
            initialValue: primitive
        });
    };
    return FormBuilder;
}());
export default FormBuilder;
//# sourceMappingURL=form-builder.js.map