import { FormArray, FormControl, FormGroup } from '@angular/forms';
import { provideStaticPackageSource } from '@anglr/dynamic';
import { FORM_COMPONENTS_PROVIDER, FORM_MODULE_TYPES_PROVIDER, FORM_RELATIONS_COMPONENTS_PROVIDER, FORM_RELATIONS_MODULE_TYPES_PROVIDER, FORM_RELATIONS_NODES_PROVIDER } from './providers';
import { FormComponentControlType } from './enums';
/**
 * Providers for layout form subpackage
 */
export function provideFormLayout() {
    return [
        FORM_COMPONENTS_PROVIDER,
    ];
}
/**
 * Providers for layout form subpackage
 */
export function provideFormRelations() {
    return [
        FORM_RELATIONS_COMPONENTS_PROVIDER,
    ];
}
/**
 * Default providers for form subpackage layout
 */
export function provideFormLayoutEditor() {
    return [
        FORM_COMPONENTS_PROVIDER,
        FORM_MODULE_TYPES_PROVIDER,
        provideStaticPackageSource('form-components'),
    ];
}
/**
 * Default providers for form subpackage relations
 */
export function provideFormRelationsEditor() {
    return [
        FORM_RELATIONS_MODULE_TYPES_PROVIDER,
        FORM_RELATIONS_NODES_PROVIDER,
        provideStaticPackageSource('form-components'),
    ];
}
/**
 * Providers for layout relations editor form subpackage
 */
export function provideFormLayoutRelationsEditor() {
    return [
        ...provideFormRelationsEditor(),
        ...provideFormLayout(),
    ];
}
/**
 * Providers for layout relations form subpackage
 */
export function provideFormLayoutRelations() {
    return [
        ...provideFormLayout(),
        ...provideFormRelations(),
    ];
}
export function getFormControl(controlName, parentControl, defaultControlType = FormComponentControlType.FormControl, defaultValue) {
    if (!parentControl ||
        !controlName) {
        return getControlForType(defaultControlType, defaultValue);
    }
    const control = parentControl.get(controlName);
    return control !== null && control !== void 0 ? control : getControlForType(defaultControlType, defaultValue);
}
export function getControlForType(type, defaultValue) {
    //TODO fix default value for form array
    switch (type) {
        case FormComponentControlType.FormArray:
            return new FormArray([]);
        case FormComponentControlType.FormGroup:
            return new FormGroup(defaultValue !== null && defaultValue !== void 0 ? defaultValue : {});
        default:
            return new FormControl(defaultValue);
    }
}
//# sourceMappingURL=utils.js.map