import { forwardRef, Inject } from '@angular/core';
import { FormControl, Validators } from '@angular/forms';
import { ComponentSettingsDialogComponent } from '../component-settings-dialog.component';
export var DEFAULT_INPUTS_METADATA = [
    'property',
    'data'
];
var PropertyMetadataClass = (function () {
    function PropertyMetadataClass(settingsDialog) {
        this.settingsDialog = settingsDialog;
    }
    PropertyMetadataClass.prototype.initialize = function () {
        if (this.settingsDialog) {
            this.registerFormListeners();
        }
    };
    PropertyMetadataClass.prototype.registerFormListeners = function () {
        if (this.settingsDialog) {
            this.settingsDialog.registerFormControlComponent(this);
        }
    };
    PropertyMetadataClass.prototype.destroy = function () {
        this.unregisterFormListeners();
    };
    PropertyMetadataClass.prototype.unregisterFormListeners = function () {
        if (this.settingsDialog) {
            this.settingsDialog.unregisterFormControlComponent(this);
        }
    };
    PropertyMetadataClass.prototype.getFormGroup = function () {
        return this.settingsDialog.formGroup;
    };
    PropertyMetadataClass.prototype.getPropertyName = function () {
        if (this.property) {
            return this.property;
        }
        return undefined;
    };
    PropertyMetadataClass.prototype.getValue = function () {
        if (this.value) {
            return this.value.value;
        }
        return this.parseValue(this.data.default);
    };
    PropertyMetadataClass.prototype.parseValue = function (arg) {
        return arg;
    };
    PropertyMetadataClass.prototype.getFormControl = function () {
        if (!this.fControl) {
            var validators = this.resolveValidators();
            var cfg = {
                value: (this.data && this.data.default) ? this.data.default : undefined
            };
            this.fControl = new FormControl(cfg, validators);
        }
        return this.fControl;
    };
    PropertyMetadataClass.prototype.resolveValidators = function () {
        var validators = [];
        if (this.data.required) {
            validators.push(Validators.required);
        }
        return validators;
    };
    Object.defineProperty(PropertyMetadataClass.prototype, "isValid", {
        get: function () {
            if (this.fControl) {
                return this.fControl.valid;
            }
            return false;
        },
        enumerable: true,
        configurable: true
    });
    PropertyMetadataClass.prototype.innerOnChange = function (value) {
        this.value = { value: value };
    };
    PropertyMetadataClass.DEFAULT_INPUTS_METADATA = DEFAULT_INPUTS_METADATA;
    PropertyMetadataClass.ctorParameters = function () { return [
        { type: ComponentSettingsDialogComponent, decorators: [{ type: Inject, args: [forwardRef(function () { return ComponentSettingsDialogComponent; }),] }] }
    ]; };
    return PropertyMetadataClass;
}());
export { PropertyMetadataClass };
//# sourceMappingURL=property.metadata.class.js.map